summaryrefslogtreecommitdiff
path: root/app/Api/Procedure/LinkProcedure.php
blob: b4cecf3a256bd045f92cd9a616c89d0f0bca0b10 (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
100
101
102
103
104
105
106
107
108
109
110
111
<?php

namespace Kanboard\Api\Procedure;

/**
 * Link API controller
 *
 * @package  Kanboard\Api\Procedure
 * @author   Frederic Guillot
 */
class LinkProcedure extends BaseProcedure
{
    /**
     * Get a link by id
     *
     * @access public
     * @param  integer   $link_id   Link id
     * @return array
     */
    public function getLinkById($link_id)
    {
        return $this->linkModel->getById($link_id);
    }

    /**
     * Get a link by name
     *
     * @access public
     * @param  string $label
     * @return array
     */
    public function getLinkByLabel($label)
    {
        return $this->linkModel->getByLabel($label);
    }

    /**
     * Get the opposite link id
     *
     * @access public
     * @param  integer   $link_id   Link id
     * @return integer
     */
    public function getOppositeLinkId($link_id)
    {
        return $this->linkModel->getOppositeLinkId($link_id);
    }

    /**
     * Get all links
     *
     * @access public
     * @return array
     */
    public function getAllLinks()
    {
        return $this->linkModel->getAll();
    }

    /**
     * Create a new link label
     *
     * @access public
     * @param  string   $label
     * @param  string   $opposite_label
     * @return boolean|integer
     */
    public function createLink($label, $opposite_label = '')
    {
        $values = array(
            'label' => $label,
            'opposite_label' => $opposite_label,
        );

        list($valid, ) = $this->linkValidator->validateCreation($values);
        return $valid ? $this->linkModel->create($label, $opposite_label) : false;
    }

    /**
     * Update a link
     *
     * @access public
     * @param  integer  $link_id
     * @param  integer  $opposite_link_id
     * @param  string   $label
     * @return boolean
     */
    public function updateLink($link_id, $opposite_link_id, $label)
    {
        $values = array(
            'id' => $link_id,
            'opposite_id' => $opposite_link_id,
            'label' => $label,
        );

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

    /**
     * Remove a link a the relation to its opposite
     *
     * @access public
     * @param  integer  $link_id
     * @return boolean
     */
    public function removeLink($link_id)
    {
        return $this->linkModel->remove($link_id);
    }
}