Project::Create PHP Method

Create() public method

public Create ( )
    public function Create()
    {
        if ($this->name != '' && $this->path != '') {
            $this->path = $this->cleanPath();
            $this->name = htmlspecialchars($this->name);
            if (!$this->isAbsPath($this->path)) {
                $this->path = $this->SanitizePath();
            }
            if ($this->path != '') {
                $pass = $this->checkDuplicate();
                if ($pass) {
                    if (!$this->isAbsPath($this->path)) {
                        mkdir(WORKSPACE . '/' . $this->path);
                    } else {
                        if (defined('WHITEPATHS')) {
                            $allowed = false;
                            foreach (explode(",", WHITEPATHS) as $whitepath) {
                                if (strpos($this->path, $whitepath) === 0) {
                                    $allowed = true;
                                }
                            }
                            if (!$allowed) {
                                die(formatJSEND("error", "Absolute Path Only Allowed for " . WHITEPATHS));
                            }
                        }
                        if (!file_exists($this->path)) {
                            if (!mkdir($this->path . '/', 0755, true)) {
                                die(formatJSEND("error", "Unable to create Absolute Path"));
                            }
                        } else {
                            if (!is_writable($this->path) || !is_readable($this->path)) {
                                die(formatJSEND("error", "No Read/Write Permission"));
                            }
                        }
                    }
                    $this->projects[] = array("name" => $this->name, "path" => $this->path);
                    saveJSON('projects.php', $this->projects);
                    // Pull from Git Repo?
                    if ($this->gitrepo && filter_var($this->gitrepo, FILTER_VALIDATE_URL) !== false) {
                        $this->git_branch = $this->SanitizeGitBranch();
                        if (!$this->isAbsPath($this->path)) {
                            $this->command_exec = "cd " . escapeshellarg(WORKSPACE . '/' . $this->path) . " && git init && git remote add origin " . escapeshellarg($this->gitrepo) . " && git pull origin " . escapeshellarg($this->gitbranch);
                        } else {
                            $this->command_exec = "cd " . escapeshellarg($this->path) . " && git init && git remote add origin " . escapeshellarg($this->gitrepo) . " && git pull origin " . escapeshellarg($this->gitbranch);
                        }
                        $this->ExecuteCMD();
                    }
                    echo formatJSEND("success", array("name" => $this->name, "path" => $this->path));
                } else {
                    echo formatJSEND("error", "A Project With the Same Name or Path Exists");
                }
            } else {
                echo formatJSEND("error", "Project Name/Folder not allowed");
            }
        } else {
            echo formatJSEND("error", "Project Name/Folder is empty");
        }
    }

Usage Example

Exemplo n.º 1
0
 public function testCreateProject()
 {
     $client = Client::GetClient(2);
     $project = Project::Create('Gatuanyaga Phase II', 'Gatu, Kiambu', '24/08/2015', 'Description', $client->id);
     //create project account, a sub account of client (debtor account)
     $qid1 = '252';
     $qid2 = '254';
     $project->importQuote($qid1);
     $project->importQuote($qid2);
     $project->authorize();
     $this->assertInstanceOf('Project', $project);
     $this->assertTrue(count($project->quotations) == 2);
 }
All Usage Examples Of Project::Create