Example #1
0
/**
 * Method to build Route
 *
 * @param array $query
 *
 * @return array
 */
function CrowdFundingBuildRoute(&$query)
{
    $segments = array();
    // get a menu item based on Itemid or currently active
    $app = JFactory::getApplication();
    $menu = $app->getMenu();
    // we need a menu item.  Either the one specified in the query, or the current active one if none specified
    if (empty($query['Itemid'])) {
        $menuItem = $menu->getActive();
    } else {
        $menuItem = $menu->getItem($query['Itemid']);
    }
    $mOption = empty($menuItem->query['option']) ? null : $menuItem->query['option'];
    $mView = empty($menuItem->query['view']) ? null : $menuItem->query['view'];
    $mCatid = empty($menuItem->query['catid']) ? null : $menuItem->query['catid'];
    $mId = empty($menuItem->query['id']) ? null : $menuItem->query['id'];
    // If is set view and Itemid missing, we have to put the view to the segments
    if (isset($query['view'])) {
        $view = $query['view'];
        if (empty($query['Itemid']) or $mOption !== "com_crowdfunding") {
            $segments[] = $query['view'];
        }
        // We need to keep the view for forms since they never have their own menu item
        if ($view != 'form') {
            unset($query['view']);
        }
    }
    // are we dealing with a category that is attached to a menu item?
    if (isset($view) and $mView == $view and isset($query['id']) and $mId == intval($query['id'])) {
        unset($query['view']);
        unset($query['catid']);
        unset($query['id']);
        return $segments;
    }
    // Views
    if (isset($view)) {
        switch ($view) {
            case "backing":
                $catId = $query['catid'];
                CrowdFundingHelperRoute::prepareCategoriesSegments($catId, $segments, $mId);
                $id = $query['id'];
                $segments[] = $id;
                unset($query['id']);
                unset($query['catid']);
                $segments[] = "backing";
                break;
            case "details":
                $catId = $query['catid'];
                CrowdFundingHelperRoute::prepareCategoriesSegments($catId, $segments, $mId);
                $id = $query['id'];
                $segments[] = $id;
                unset($query['id']);
                unset($query['catid']);
                break;
            case "embed":
                $catId = $query['catid'];
                CrowdFundingHelperRoute::prepareCategoriesSegments($catId, $segments, $mId);
                unset($query['catid']);
                $id = $query['id'];
                $segments[] = $id;
                unset($query['id']);
                $segments[] = "embed";
                break;
            case "project":
                // Form for adding projects
                if ($menuItem->query["view"] == $view) {
                    unset($query['view']);
                }
                break;
            case "reward":
                // Form for adding projects
                $query['view'] = "reward";
                break;
        }
    }
    // Layout
    if (isset($query['layout'])) {
        if (!empty($query['Itemid']) && isset($menuItem->query['layout'])) {
            if ($query['layout'] == $menuItem->query['layout']) {
                unset($query['layout']);
            }
        } else {
            if ($query['layout'] == 'default') {
                unset($query['layout']);
            }
        }
    }
    // Screen
    if (isset($query["screen"])) {
        $segments[] = $query["screen"];
        unset($query['screen']);
    }
    return $segments;
}