summaryrefslogtreecommitdiff
path: root/app/Api/Procedure/SwimlaneProcedure.php
blob: edc1e0060208235166ac1c3821c9cc7f91a141b7 (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
88
89
90
91
92
93
94
95
96
97
98
99
<?php

namespace Kanboard\Api\Procedure;

use Kanboard\Api\Authorization\ProjectAuthorization;
use Kanboard\Model\SwimlaneModel;

/**
 * Swimlane API controller
 *
 * @package  Kanboard\Api\Procedure
 * @author   Frederic Guillot
 */
class SwimlaneProcedure extends BaseProcedure
{
    public function getActiveSwimlanes($project_id)
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getActiveSwimlanes', $project_id);
        return $this->swimlaneModel->getAllByStatus($project_id, SwimlaneModel::ACTIVE);
    }

    public function getAllSwimlanes($project_id)
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllSwimlanes', $project_id);
        return $this->swimlaneModel->getAll($project_id);
    }

    public function getSwimlaneById($swimlane_id)
    {
        $swimlane = $this->swimlaneModel->getById($swimlane_id);
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSwimlaneById', $swimlane['project_id']);
        return $swimlane;
    }

    public function getSwimlaneByName($project_id, $name)
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSwimlaneByName', $project_id);
        return $this->swimlaneModel->getByName($project_id, $name);
    }

    public function getSwimlane($swimlane_id)
    {
        return $this->swimlaneModel->getById($swimlane_id);
    }

    public function addSwimlane($project_id, $name, $description = '')
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addSwimlane', $project_id);
        return $this->swimlaneModel->create($project_id, $name, $description);
    }

    public function updateSwimlane($project_id, $swimlane_id, $name, $description = null)
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateSwimlane', $project_id);

        $values = array(
            'project_id' => $project_id,
            'id'         => $swimlane_id,
            'name'       => $name,
        );

        if (! is_null($description)) {
            $values['description'] = $description;
        }

        list($valid, $errors) = $this->swimlaneValidator->validateModification($values);

        if (! $valid) {
            $this->logger->debug(__METHOD__.': Validation error: '.var_export($errors, true));
            return false;
        }

        return $this->swimlaneModel->update($swimlane_id, $values);
    }

    public function removeSwimlane($project_id, $swimlane_id)
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeSwimlane', $project_id);
        return $this->swimlaneModel->remove($project_id, $swimlane_id);
    }

    public function disableSwimlane($project_id, $swimlane_id)
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableSwimlane', $project_id);
        return $this->swimlaneModel->disable($project_id, $swimlane_id);
    }

    public function enableSwimlane($project_id, $swimlane_id)
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableSwimlane', $project_id);
        return $this->swimlaneModel->enable($project_id, $swimlane_id);
    }

    public function changeSwimlanePosition($project_id, $swimlane_id, $position)
    {
        ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeSwimlanePosition', $project_id);
        return $this->swimlaneModel->changePosition($project_id, $swimlane_id, $position);
    }
}