Пример #1
0
 /**
  * Determines the Itemid
  *
  * searches if a menuitem for this item exists
  * if not the active menuitem will be returned
  *
  * @param array The id and view
  *
  *
  * @return int Itemid
  */
 protected static function _findItem($needles = null)
 {
     $app = JFactory::getApplication();
     $menus = $app->getMenu('site');
     if (!isset(self::$FixedItemid)) {
         $settings = JEMHelper::globalattribs();
         $defaultItemid = $settings->get('default_Itemid');
     } else {
         if (isset(self::$FixedItemid)) {
             $defaultItemid = self::$FixedItemid;
         }
     }
     // Prepare the reverse lookup array.
     if (!isset(self::$lookup2)) {
         self::$lookup2 = array();
         $component = JComponentHelper::getComponent('com_jem');
         $items = $menus->getItems('component_id', $component->id);
         // loop trough the menu-items of the component
         if ($items) {
             foreach ($items as $item) {
                 if (isset($item->query) && isset($item->query['view'])) {
                     // skip Calendar-layout
                     if (isset($item->query['layout']) && $item->query['layout'] == 'calendar') {
                         continue;
                     }
                     // define $view variable
                     $view = $item->query['view'];
                     // skip several views
                     if (isset($item->query['view'])) {
                         if ($view == 'calendar' || $view == 'search' || $view == 'venues') {
                             continue;
                         }
                     }
                     if (!isset(self::$lookup2[$view])) {
                         self::$lookup2[$view] = array();
                     }
                 }
                 // check for Id's
                 if (isset($item->query['id'])) {
                     if (!isset(self::$lookup2[$view][$item->query['id']])) {
                         self::$lookup2[$view][$item->query['id']] = $item->id;
                     }
                 } else {
                     // Some views have no ID, but we have to set one
                     self::$lookup2[$view][self::ARTIFICALID] = $item->id;
                 }
             }
         }
     }
     // at this point we collected itemid's linking to the component
     if ($needles) {
         foreach ($needles as $view => $ids) {
             if (isset(self::$lookup2[$view])) {
                 foreach ($ids as $id) {
                     if (isset(self::$lookup2[$view][(int) $id])) {
                         return self::$lookup2[$view][(int) $id];
                     }
                 }
             }
         }
     }
     if ($defaultItemid) {
         return $defaultItemid;
     } else {
         $active = $menus->getActive();
         if ($active && $active->component == 'com_jem') {
             return $active->id;
         }
         $component = JComponentHelper::getComponent('com_jem');
         $items = $menus->getItems(array('component_id', 'link'), array($component->id, 'index.php?option=com_jem&view=eventslist'), false);
         $default = reset($items);
         return !empty($default->id) ? $default->id : null;
     }
 }