PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/googlemini/code/trunk/components/com_artofgm/helpers/route.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 104 lines | 51 code | 12 blank | 41 comment | 10 complexity | 25327e0433619938222d7e81e98626f0 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: route.php 518 2011-01-07 06:36:43Z eddieajau $
  4. * @package NewLifeInIT
  5. * @subpackage com_artofgm
  6. * @copyright Copyright 2011 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License version 2 or later.
  8. */
  9. // No direct access
  10. defined('_JEXEC') or die;
  11. /**
  12. * @package NewLifeInIT
  13. * @subpackage com_artofgm
  14. * @since 1.0
  15. */
  16. class ArtofGMHelperRoute
  17. {
  18. /**
  19. * @var array
  20. * @since 1.0
  21. */
  22. protected static $lookup;
  23. /**
  24. * Get the component route.
  25. *
  26. * @return string
  27. * @since 1.0
  28. */
  29. public static function getRoute()
  30. {
  31. //Create the link
  32. $link = 'index.php?option=com_artofgm&view=artofgm';
  33. $itemId = self::_findItem();
  34. if ($itemId) {
  35. $link .= '&Itemid='.$itemId;
  36. }
  37. return $link;
  38. }
  39. /**
  40. * Find the itemid given search needles.
  41. *
  42. * @param array $needles An array of the search needles by view.
  43. *
  44. * @return int
  45. * @since 1.0
  46. */
  47. protected static function _findItem($needles = array('artofgm' => true))
  48. {
  49. $app = JFactory::getApplication();
  50. $menus = $app->getMenu('site');
  51. // Prepare the reverse lookup array.
  52. if (self::$lookup === null) {
  53. self::$lookup = array();
  54. // Get a list of the menu items for this component.
  55. $component = JComponentHelper::getComponent('com_artofgm');
  56. $items = $menus->getItems('componentid', $component->id);
  57. if (!empty($items)) {
  58. foreach ($items as $item)
  59. {
  60. if (isset($item->query) && isset($item->query['view'])) {
  61. // Build the view lookup.
  62. $view = $item->query['view'];
  63. if (!isset(self::$lookup[$view])) {
  64. // This extension only supports view. First in best dressed.
  65. self::$lookup[$view] = $item->id;
  66. }
  67. }
  68. }
  69. }
  70. // Finished building reverse-lookup array.
  71. }
  72. if ($needles) {
  73. // Search the needles against the lookup array and try to find match.
  74. foreach ($needles as $view => $itemId)
  75. {
  76. // This component only has one view so it's quite trivial.
  77. if (isset(self::$lookup[$view])) {
  78. return self::$lookup[$view];
  79. }
  80. }
  81. // No needle matches found.
  82. }
  83. else {
  84. // No needles so just get the active page.
  85. $active = $menus->getActive();
  86. if ($active) {
  87. return $active->id;
  88. }
  89. }
  90. return null;
  91. }
  92. }