summaryrefslogtreecommitdiff
path: root/app/Api/ProjectApi.php
blob: 29a9cd799b71c1eeb14615863a0fdb8e8c7fb216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php

namespace Kanboard\Api;

/**
 * Project API controller
 *
 * @package  Kanboard\Api
 * @author   Frederic Guillot
 */
class ProjectApi extends BaseApi
{
    public function getProjectById($project_id)
    {
        $this->checkProjectPermission($project_id);
        return $this->formatProject($this->projectModel->getById($project_id));
    }

    public function getProjectByName($name)
    {
        return $this->formatProject($this->projectModel->getByName($name));
    }

    public function getAllProjects()
    {
        return $this->formatProjects($this->projectModel->getAll());
    }

    public function removeProject($project_id)
    {
        return $this->projectModel->remove($project_id);
    }

    public function enableProject($project_id)
    {
        return $this->projectModel->enable($project_id);
    }

    public function disableProject($project_id)
    {
        return $this->projectModel->disable($project_id);
    }

    public function enableProjectPublicAccess($project_id)
    {
        return $this->projectModel->enablePublicAccess($project_id);
    }

    public function disableProjectPublicAccess($project_id)
    {
        return $this->projectModel->disablePublicAccess($project_id);
    }

    public function getProjectActivities(array $project_ids)
    {
        return $this->helper->projectActivity->getProjectsEvents($project_ids);
    }

    public function getProjectActivity($project_id)
    {
        $this->checkProjectPermission($project_id);
        return $this->helper->projectActivity->getProjectEvents($project_id);
    }

    public function createProject($name, $description = null)
    {
        $values = array(
            'name' => $name,
            'description' => $description
        );

        list($valid, ) = $this->projectValidator->validateCreation($values);
        return $valid ? $this->projectModel->create($values) : false;
    }

    public function updateProject($id, $name, $description = null)
    {
        $values = array(
            'id' => $id,
            'name' => $name,
            'description' => $description
        );

        list($valid, ) = $this->projectValidator->validateModification($values);
        return $valid && $this->projectModel->update($values);
    }
}