DNRoot::Navigation PHP Method

Navigation() public method

Returns top level navigation of projects.
public Navigation ( integer $limit = 5 ) : ArrayList
$limit integer
return ArrayList
    public function Navigation($limit = 5)
    {
        $navigation = new ArrayList();
        $currentProject = $this->getCurrentProject();
        $currentEnvironment = $this->getCurrentEnvironment();
        $actionType = $this->getCurrentActionType();
        $projects = $this->getStarredProjects();
        if ($projects->count() < 1) {
            $projects = $this->DNProjectList();
        } else {
            $limit = -1;
        }
        if ($projects->count() > 0) {
            $activeProject = false;
            if ($limit > 0) {
                $limitedProjects = $projects->limit($limit);
            } else {
                $limitedProjects = $projects;
            }
            foreach ($limitedProjects as $project) {
                $isActive = $currentProject && $currentProject->ID == $project->ID;
                if ($isActive) {
                    $activeProject = true;
                }
                $isCurrentEnvironment = false;
                if ($project && $currentEnvironment) {
                    $isCurrentEnvironment = (bool) $project->DNEnvironmentList()->find('ID', $currentEnvironment->ID);
                }
                $navigation->push(['Project' => $project, 'IsCurrentEnvironment' => $isCurrentEnvironment, 'IsActive' => $currentProject && $currentProject->ID == $project->ID, 'IsOverview' => $actionType == self::PROJECT_OVERVIEW && !$isCurrentEnvironment && $currentProject->ID == $project->ID]);
            }
            // Ensure the current project is in the list
            if (!$activeProject && $currentProject) {
                $navigation->unshift(['Project' => $currentProject, 'IsActive' => true, 'IsCurrentEnvironment' => $currentEnvironment, 'IsOverview' => $actionType == self::PROJECT_OVERVIEW && !$currentEnvironment]);
                if ($limit > 0 && $navigation->count() > $limit) {
                    $navigation->pop();
                }
            }
        }
        return $navigation;
    }