Project::GetFirst PHP Method

GetFirst() public method

public GetFirst ( )
    public function GetFirst()
    {
        $projects_assigned = false;
        if ($this->assigned) {
            foreach ($this->projects as $project => $data) {
                if (in_array($data['path'], $this->assigned)) {
                    $this->name = $data['name'];
                    $this->path = $data['path'];
                    break;
                }
            }
        } else {
            $this->name = $this->projects[0]['name'];
            $this->path = $this->projects[0]['path'];
        }
        // Set Sessions
        $_SESSION['project'] = $this->path;
        if (!$this->no_return) {
            echo formatJSEND("success", array("name" => $this->name, "path" => $this->path));
        }
    }

Usage Example

Example #1
0
checkSession();
$Project = new Project();
//////////////////////////////////////////////////////////////////
// Get Current Project
//////////////////////////////////////////////////////////////////
$no_return = false;
if (isset($_GET['no_return'])) {
    $no_return = true;
}
if ($_GET['action'] == 'get_current') {
    if (!isset($_SESSION['project'])) {
        // Load default/first project
        if ($no_return) {
            $Project->no_return = true;
        }
        $Project->GetFirst();
    } else {
        // Load current
        $Project->path = $_SESSION['project'];
        $project_name = $Project->GetName();
        if (!$no_return) {
            echo formatJSEND("success", array("name" => $project_name, "path" => $_SESSION['project']));
        }
    }
}
//////////////////////////////////////////////////////////////////
// Open Project
//////////////////////////////////////////////////////////////////
if ($_GET['action'] == 'open') {
    if (!checkPath($_GET['path'])) {
        die(formatJSEND("error", "No Access"));