/quanta/code/trunk/components/com_quanta/router.php
PHP | 146 lines | 75 code | 19 blank | 52 comment | 10 complexity | deebf31de33101b8c2e62222b1099dce MD5 | raw file
- <?php
- /**
- * @version $Id: router.php 377 2010-11-03 08:00:54Z eddieajau $
- * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
- * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
- * @link http://www.theartofjoomla.com
- */
- // no direct access
- defined('_JEXEC') or die;
- /**
- * Quanta router helpers.
- *
- * @package NewLifeInIT
- * @subpackage com_quanta
- */
- class QuantaRoute
- {
- /**
- * @var array A cache of the menu items pertaining to com_content
- */
- protected static $lookup = null;
- /**
- * @param int $categoryId An optional category id.
- *
- * @return string The routed link.
- */
- public static function submitCategory($categoryId, $uri)
- {
- // Create the link
- $link = 'index.php?option=com_quanta&task=history.add&category_id='.(int) $categoryId.'&return='.base64_encode($uri->toString());
- return $link;
- }
- /**
- * @param int $categoryId An optional category id.
- *
- * @return string The routed link.
- */
- public static function submitHistory($historyId, $uri)
- {
- // Create the link
- $link = 'index.php?option=com_quanta&task=history.edit&history_id='.(int) $historyId.'&return='.base64_encode($uri->toString());
- return $link;
- }
- /**
- * @param int $id The id of the record.
- * @param int $categoryId An optional category id.
- *
- * @return string The routed link.
- */
- public static function record($recordId, $categoryId = null)
- {
- // Prepare the search needles
- $needles = array(
- // View => Target Id
- 'scatter' => 'record.'.(int) $recordId,
- );
- // Create the link
- $link = 'index.php?option=com_quanta&view=scatter&record_id='. $recordId;
- if ($categoryId) {
- $link .= '&category_id='.$categoryId;
- }
- if ($itemId = self::_findItemId($needles)) {
- $link .= '&Itemid='.$itemId;
- };
- return $link;
- }
- protected static function _findItemId($needles = array())
- {
- // Prepare the reverse lookup array.
- if (self::$lookup === null)
- {
- self::$lookup = array();
- $component = &JComponentHelper::getComponent('com_quanta');
- $menus = &JApplication::getMenu('site', array());
- $items = $menus->getItems('componentid', $component->id);
- foreach ($items as &$item)
- {
- if (isset($item->query) && isset($item->query['view']))
- {
- $view = $item->query['view'];
- if (!isset(self::$lookup[$view])) {
- self::$lookup[$view] = array();
- }
- if (isset($item->query['record_id'])) {
- self::$lookup[$view]['record.'.(int) $item->query['record_id']] = $item->id;
- }
- if (isset($item->query['category_id'])) {
- self::$lookup[$view]['category.'.(int) $item->query['category_id']] = $item->id;
- }
- }
- }
- }
- $match = null;
- foreach ($needles as $view => $id)
- {
- if (isset(self::$lookup[$view]))
- {
- if (isset(self::$lookup[$view][$id])) {
- return self::$lookup[$view][$id];
- }
- }
- }
- return null;
- }
- }
- /**
- * Build the route for the com_content component
- *
- * @param array An array of URL arguments
- *
- * @return array The URL arguments to use to assemble the subsequent URL.
- */
- function QuantaBuildRoute(&$query)
- {
- return array();
- }
- /**
- * Parse the segments of a URL.
- *
- * @param array The segments of the URL to parse.
- *
- * @return array The URL attributes to be used by the application.
- */
- function QuantaParseRoute($segments)
- {
- return $segments;
- }