Esempio n. 1
0
 public function getUrl($query, $url)
 {
     static $cache = array();
     // Get a list of menus for the current view.
     $itemMenus = FRoute::getMenus($this->name, 'item');
     // For single group item
     // index.php?option=com_easysocial&view=events&layout=item&id=xxxx
     $items = array('item', 'info', 'edit');
     if (isset($query['layout']) && in_array($query['layout'], $items) && isset($query['id']) && !empty($itemMenus)) {
         foreach ($itemMenus as $menu) {
             $id = (int) $menu->segments->id;
             $queryId = (int) $query['id'];
             if ($queryId == $id) {
                 // The query cannot contain appId
                 if ($query['layout'] == 'item' && !isset($query['appId'])) {
                     $url = 'index.php?Itemid=' . $menu->id;
                     return $url;
                 }
                 $url .= '&Itemid=' . $menu->id;
                 return $url;
             }
         }
     }
     // For group categories
     $menus = FRoute::getMenus($this->name, 'category');
     $items = array('category');
     if (isset($query['layout']) && in_array($query['layout'], $items) && isset($query['id']) && !empty($itemMenus)) {
         foreach ($menus as $menu) {
             $id = (int) $menu->segments->id;
             $queryId = (int) $query['id'];
             if ($queryId == $id) {
                 if ($query['layout'] == 'category') {
                     $url = 'index.php?Itemid=' . $menu->id;
                     return $url;
                 }
                 $url .= '&Itemid=' . $menu->id;
                 return $url;
             }
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Retrieves the item id of the current view.
  *
  * @since   1.0
  * @access  public
  * @param   string
  * @return
  */
 public static function getItemId($view, $layout = '', $id = '')
 {
     static $views = array();
     // Cache the result
     $key = $view . $layout . $id;
     if (!isset($views[$key])) {
         // Retrieve the list of default menu
         $defaultMenu = FRoute::getMenus('dashboard', '');
         // Initial menu should be false
         $menuId = false;
         if (!empty($layout)) {
             // Try to locate menu with just the view if we still can't find a menu id.
             $menus = FRoute::getMenus($view, $layout, $id);
             if (!$menuId && $menus) {
                 // If this menu contains data about "id", we shouldn't simply use it.
                 // if (!isset($menus[0]->segments->id)) {
                 //     $menuId     = $menus[0]->id;
                 // }
                 // var_dump($menus[0]);exit;
                 $menuId = $menus[0]->id;
             }
         }
         // Try to locate menu with just the view if we still can't find a menu id.
         $menus = FRoute::getMenus($view, '', '');
         // If menu id for view + layout doesn't exists, use the one from the view
         if (!$menuId && $menus) {
             $menuId = $menus[0]->id;
         }
         // If we still don't have a menu id, we use the default dashboard view.
         if (!$menuId && $defaultMenu) {
             $menuId = $defaultMenu[0]->id;
         }
         $views[$key] = $menuId;
     }
     return $views[$key];
 }