/** * 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'); // Prepare the reverse lookup array. if (self::$lookup === null) { self::$lookup = array(); $component = JComponentHelper::getComponent('com_jem'); $items = $menus->getItems('component_id', $component->id); if ($items) { foreach ($items as $item) { if (isset($item->query) && isset($item->query['view'])) { if (isset($item->query['layout']) && ($item->query['layout'] == 'calendar')) { continue; // skip calendars } $view = $item->query['view']; if (!isset(self::$lookup[$view])) { self::$lookup[$view] = array(); } if (isset($item->query['id'])) { self::$lookup[$view][$item->query['id']] = $item->id; } // Some views have no ID, but we have to set one else { self::$lookup[$view][self::ARTIFICALID] = $item->id; } } } } } if ($needles) { foreach ($needles as $view => $ids) { if (isset(self::$lookup[$view])) { foreach($ids as $id) { if (isset(self::$lookup[$view][(int)$id])) { // TODO: Check on access. See commented code below return self::$lookup[$view][(int)$id]; } } } } } else { $active = $menus->getActive(); if ($active) { return $active->id; } } return null; // $user = JemFactory::getUser(); // //false if there exists no menu item at all // if (!$items) { // return false; // } else { // //Not needed currently but kept because of a possible hierarchic link structure in future // foreach($needles as $needle => $id) // { // foreach($items as $item) // { // if (($item->query['view'] == $needle) && ($item->query['id'] == $id)) { // return $item; // } // } // /* // //no menuitem exists -> return first possible match // foreach($items as $item) // { // if ($item->published == 1 && $item->access <= $gid) { // return $item; // } // } // */ // } // } // return false; }