the-art-of-joomla-archive /quanta/code/trunk/components/com_quanta/router.php

Language PHP Lines 147
MD5 Hash deebf31de33101b8c2e62222b1099dce Estimated Cost $1,755 (why?)
Repository https://bitbucket.org/eddieajau/the-art-of-joomla-archive View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?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;
}
Back to Top