Completed
Pull Request — master (#16)
by
unknown
12:10 queued 02:08
created

Checklist::items()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Trello\Api;
4
5
use Trello\Exception\InvalidArgumentException;
6
7
/**
8
 * Trello Checkist API
9
 * @link https://trello.com/docs/api/checklist
10
 *
11
 * Fully implemented.
12
 */
13
class Checklist extends AbstractApi
14
{
15
    /**
16
     * Base path of checklists api
17
     * @var string
18
     */
19
    protected $path = 'checklists';
20
21
    /**
22
     * Card fields
23
     * @link https://trello.com/docs/api/list/#get-1-lists-list-id-or-shortlink-field
24
     * @var array
25
     */
26
    public static $fields = array(
27
        'name',
28
        'idBoard',
29
        'idCard',
30
        'pos',
31
    );
32
33
    /**
34
     * Find a list by id
35
     * @link https://trello.com/docs/api/checklist/#get-1-checklists-idchecklist
36
     *
37
     * @param string $id     the checklist's id
38
     * @param array  $params optional attributes
39
     *
40
     * @return array list info
41
     */
42 1
    public function show($id, array $params = array())
43
    {
44 1
        return $this->get($this->getPath().'/'.rawurlencode($id), $params);
45
    }
46
47
    /**
48
     * Create a checklist
49
     * @link https://trello.com/docs/api/checklist/#post-1-checklists
50
     *
51
     * @param array $params optional attributes: 'name', 'idBoard', 'idCard', 'pos', 'idChecklistSource'
52
     *
53
     * @return array
54
     */
55 3
    public function create(array $params = array())
56
    {
57 3
        $this->validateRequiredParameters(array('name', 'idCard'), $params);
58
59 1
        return $this->post($this->getPath(), $params);
60
    }
61
62
    /**
63
     * Update a checklist
64
     * @link https://trello.com/docs/api/checklist/#put-1-checklists-idchecklist
65
     *
66
     * @param string $id     the list's id
67
     * @param array  $params list attributes to update
68
     *
69
     * @return array list info
70
     */
71 1
    public function update($id, array $params = array())
72
    {
73 1
        return $this->put($this->getPath().'/'.rawurlencode($id), $params);
74
    }
75
76
    /**
77
     * Remove a checklist
78
     * @link https://trello.com/docs/api/checklist/#delete-1-checklists-idchecklist
79
     *
80
     * @param string $id the checklist's id
81
     *
82
     * @return array
83
     */
84 1
    public function remove($id)
85
    {
86 1
        return $this->delete($this->getPath().'/'.rawurlencode($id));
87
    }
88
    
89
    /**
90
     * Remove a listitem from a checklist
91
     * @link https://trello.com/docs/api/checklist/index.html#delete-1-checklists-idchecklist-checkitems-idcheckitem
92
     *
93
     * @param string $checkListId the checklist's id
94
     * @param string $listItemId the listItem id
95
     *
96
     * @return array
97
     */
98 1
    public function removeListItem($checkListId, $listItemId)
99
    {
100 1
        return $this->delete($this->getPath().'/'.rawurlencode($checkListId).'/checkItems/'.rawurlencode($listItemId));
101
    }
102
    
103
    
104
    /**
105
     * get checklist items from a checklist
106
     * @link https://trello.readme.io/v1.0/reference#checklistsidcardscheckitems
107
     *
108
     * @param string $checkListId the checklist's id
109
     * @param string $listItemId (optional) the listItem id
110
     * @param array $fields (options) the fi
111
     *
112
     * @return array
113
     */
114 2
    public function getListItems($checkListId, $listItemId = null, array $fields = array('fields' => 'all')
115
    {
116 2
        if($listItemId == null){
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_IF
Loading history...
117
            
118 1
            return $this->get($this->getPath().'/'.rawurlencode($checkListId).'/checkItems', $fields);
119
    
120
        }else{
121
            
122
            return $this->get($this->getPath().'/'.rawurlencode($checkListId).'/checkItems/'.rawurlencode($listItemId), $fields);
123
         
124
        }
125
    }
126
                                 
127
    /**
128
     * Get the board of a given checklist
129
     * @link https://trello.com/docs/api/checklist/#get-1-checklists-idchecklist-board
130 1
     *
131
     * @param string $id     the checklist's id
132 1
     * @param array  $params optional parameters
133
     *
134
     * @return array board info
135
     */
136
    public function getBoard($id, array $params = array())
137
    {
138
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board', $params);
139
    }
140
141
    /**
142
     * Get the field of a board of a given checklist
143
     * @link https://trello.com/docs/api/checklist/#get-1-checklists-idchecklist-board-field
144 1
     *
145
     * @param string $id    the checklist's id
146 1
     * @param array  $field the name of the field
147
     *
148
     * @return array board info
149
     *
150
     * @throws InvalidArgumentException if the field does not exist
151
     */
152
    public function getBoardField($id, $field)
153
    {
154
        $this->validateAllowedParameters(Board::$fields, $field, 'field');
155
156
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field));
157
    }
158
159 1
    /**
160
     * Set a given checklist's card
161 1
     * @link https://trello.com/docs/api/checklist/#put-1-checklists-idchecklist-idcard
162
     *
163
     * @param string $id     the list's id
164
     * @param string $cardId the card's id
165
     *
166
     * @return array
167
     */
168
    public function setCard($id, $cardId)
169 1
    {
170
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idCard', array('value' => $cardId));
171 1
    }
172
173
    /**
174
     * Set a given checklist's name
175
     * @link https://trello.com/docs/api/checklist/#put-1-checklists-idchecklist-name
176
     *
177
     * @param string $id   the checklist's id
178
     * @param string $name the name
179 1
     *
180
     * @return array
181 1
     */
182
    public function setName($id, $name)
183
    {
184
        return $this->put($this->getPath().'/'.rawurlencode($id).'/name', array('value' => $name));
185
    }
186
187
    /**
188
     * Set a given checklist's position
189
     * @link https://trello.com/docs/api/checklist/#put-1-checklists-idchecklist-pos
190
     *
191
     * @param string         $id       the list's id
192
     * @param string|integer $position the position, eg. 'top', 'bottom'
193
     *                                 or a positive number
194
     *
195
     * @return array list info
196
     */
197
    public function setPosition($id, $position)
198
    {
199
        return $this->put($this->getPath().'/'.rawurlencode($id).'/pos', array('value' => $position));
200
    }
201
202
    /**
203
     * Cards API
204
     *
205
     * @return Checklist\Cards
206
     */
207
    public function cards()
208
    {
209
        return new Checklist\Cards($this->client);
210
    }
211
212
    /**
213
     * Items API
214
     *
215
     * @return Checklist\Items
216
     */
217
    public function items()
218
    {
219
        return new Checklist\Items($this->client);
220
    }
221
}
222