PageRenderTime 60ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/quanta/code/trunk/components/com_quanta/router.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 146 lines | 75 code | 19 blank | 52 comment | 10 complexity | deebf31de33101b8c2e62222b1099dce MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: router.php 377 2010-11-03 08:00:54Z eddieajau $
  4. * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
  5. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  6. * @link http://www.theartofjoomla.com
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die;
  10. /**
  11. * Quanta router helpers.
  12. *
  13. * @package NewLifeInIT
  14. * @subpackage com_quanta
  15. */
  16. class QuantaRoute
  17. {
  18. /**
  19. * @var array A cache of the menu items pertaining to com_content
  20. */
  21. protected static $lookup = null;
  22. /**
  23. * @param int $categoryId An optional category id.
  24. *
  25. * @return string The routed link.
  26. */
  27. public static function submitCategory($categoryId, $uri)
  28. {
  29. // Create the link
  30. $link = 'index.php?option=com_quanta&task=history.add&category_id='.(int) $categoryId.'&return='.base64_encode($uri->toString());
  31. return $link;
  32. }
  33. /**
  34. * @param int $categoryId An optional category id.
  35. *
  36. * @return string The routed link.
  37. */
  38. public static function submitHistory($historyId, $uri)
  39. {
  40. // Create the link
  41. $link = 'index.php?option=com_quanta&task=history.edit&history_id='.(int) $historyId.'&return='.base64_encode($uri->toString());
  42. return $link;
  43. }
  44. /**
  45. * @param int $id The id of the record.
  46. * @param int $categoryId An optional category id.
  47. *
  48. * @return string The routed link.
  49. */
  50. public static function record($recordId, $categoryId = null)
  51. {
  52. // Prepare the search needles
  53. $needles = array(
  54. // View => Target Id
  55. 'scatter' => 'record.'.(int) $recordId,
  56. );
  57. // Create the link
  58. $link = 'index.php?option=com_quanta&view=scatter&record_id='. $recordId;
  59. if ($categoryId) {
  60. $link .= '&category_id='.$categoryId;
  61. }
  62. if ($itemId = self::_findItemId($needles)) {
  63. $link .= '&Itemid='.$itemId;
  64. };
  65. return $link;
  66. }
  67. protected static function _findItemId($needles = array())
  68. {
  69. // Prepare the reverse lookup array.
  70. if (self::$lookup === null)
  71. {
  72. self::$lookup = array();
  73. $component = &JComponentHelper::getComponent('com_quanta');
  74. $menus = &JApplication::getMenu('site', array());
  75. $items = $menus->getItems('componentid', $component->id);
  76. foreach ($items as &$item)
  77. {
  78. if (isset($item->query) && isset($item->query['view']))
  79. {
  80. $view = $item->query['view'];
  81. if (!isset(self::$lookup[$view])) {
  82. self::$lookup[$view] = array();
  83. }
  84. if (isset($item->query['record_id'])) {
  85. self::$lookup[$view]['record.'.(int) $item->query['record_id']] = $item->id;
  86. }
  87. if (isset($item->query['category_id'])) {
  88. self::$lookup[$view]['category.'.(int) $item->query['category_id']] = $item->id;
  89. }
  90. }
  91. }
  92. }
  93. $match = null;
  94. foreach ($needles as $view => $id)
  95. {
  96. if (isset(self::$lookup[$view]))
  97. {
  98. if (isset(self::$lookup[$view][$id])) {
  99. return self::$lookup[$view][$id];
  100. }
  101. }
  102. }
  103. return null;
  104. }
  105. }
  106. /**
  107. * Build the route for the com_content component
  108. *
  109. * @param array An array of URL arguments
  110. *
  111. * @return array The URL arguments to use to assemble the subsequent URL.
  112. */
  113. function QuantaBuildRoute(&$query)
  114. {
  115. return array();
  116. }
  117. /**
  118. * Parse the segments of a URL.
  119. *
  120. * @param array The segments of the URL to parse.
  121. *
  122. * @return array The URL attributes to be used by the application.
  123. */
  124. function QuantaParseRoute($segments)
  125. {
  126. return $segments;
  127. }