Back to PhocaGalleryRoute class

Method getCategoriesRoute

public static
getCategoriesRoute
()

Method getCategoriesRoute - Source code

public static function getCategoriesRoute()
{
    // TEST SOLUTION
    $app = Factory::getApplication();
    $menu = $app->getMenu();
    $active = $menu->getActive();
    $activeId = 0;
    if (isset($active->id)) {
        $activeId = $active->id;
    }
    $itemId = 0;
    /* There cannot be $item->id yet
    		// 1) get standard item id if exists
    		if (isset($item->id)) {
    			$itemId = (int)$item->id;
    		}*/
    $option = $app->input->get('option', '', 'string');
    $view = $app->input->get('view', '', 'string');
    if ($option == 'com_phocagallery' && $view == 'category') {
        if ((int) $activeId > 0) {
            // 2) if there are two menu links, try to select the one active
            $itemId = $activeId;
        }
    }
    $needles = array('categories' => '');
    $link = 'index.php?option=com_phocagallery&view=categories';
    if ($item = PhocaGalleryRoute::_findItem($needles, 1)) {
        if (isset($item->query['layout'])) {
            $link .= '&layout=' . $item->query['layout'];
        }
        // TEST SOLUTION
        /*if ((int)$itemId > 0) {
        			$link .= '&Itemid='.(int)$itemId;
        		} else if (isset($item->id) && ((int)$item->id > 0)) {
        			$link .= '&Itemid='.$item->id;
        		}*/
        // $item->id should be a "categories view" and it should have preference to category view
        // so first we check item->id then itemId
        // 1) there can be two categories view, when yes, first set itemId then item->id
        // 2) but when there is one category view, and one categories view - first select item->id (categories view)
        // 3) then select itemid even we don't know if categories or category view
        if ((int) $itemId > 0 && isset($active->query['view']) && $active->query['view'] == 'categories') {
            $link .= '&Itemid=' . (int) $itemId;
        } else {
            if (isset($item->id) && (int) $item->id > 0) {
                $link .= '&Itemid=' . $item->id;
            } else {
                if ((int) $itemId > 0) {
                    $link .= '&Itemid=' . (int) $itemId;
                }
            }
        }
    }
    return $link;
}