Completed
Pull Request — master (#16)
by
unknown
07:33
created

Card::setCheckListItemClosed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 4
crap 2
1
<?php
2
3
namespace Trello\Api;
4
5
use Trello\Exception\InvalidArgumentException;
6
7
/**
8
 * Trello Card API
9
 * @link https://trello.com/docs/api/card
10
 *
11
 * Unimplemented:
12
 * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklistcurrent-checkitem-idcheckitem
13
 * - https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-converttocard
14
 * - https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-markassociatednotificationsread
15
 */
16
class Card extends AbstractApi
17
{
18
    /**
19
     * Base path of cards api
20
     * @var string
21
     */
22
    protected $path = 'cards';
23
24
    /**
25
     * Card fields
26
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-field
27
     * @var array
28
     */
29
    public static $fields = array(
30
        'badges',
31
        'checkItemStates',
32
        'closed',
33
        'dateLastActivity',
34
        'desc',
35
        'descData',
36
        'due',
37
        'email',
38
        'idBoard',
39
        'idChecklists',
40
        'idList',
41
        'idMembers',
42
        'idMembersVoted',
43
        'idShort',
44
        'idAttachmentCover',
45
        'manualCoverAttachment',
46
        'labels',
47
        'name',
48
        'pos',
49
        'shortLink',
50
        'shortUrl',
51
        'subscribed',
52
        'url',
53
    );
54
55
    /**
56
     * Find a card by id
57
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink
58
     *
59
     * @param string $id     the card's id or short link
60
     * @param array  $params optional attributes
61
     *
62
     * @return array card info
63
     */
64
    public function show($id, array $params = array())
65
    {
66
        return $this->get($this->getPath().'/'.rawurlencode($id), $params);
67
    }
68 1
69
    /**
70 1
     * Create a card
71
     * @link https://trello.com/docs/api/card/#post-1-cards
72
     *
73
     * @param array  $params optional attributes
74
     *
75
     * @return array card info
76
     */
77
    public function create(array $params = array())
78
    {
79
        $this->validateRequiredParameters(array('idList', 'name'), $params);
80
81 3
        if (!array_key_exists('due', $params)) {
82
            $params['due'] = null;
83 3
        }
84
        if (!array_key_exists('urlSource', $params)) {
85 1
            $params['urlSource'] = null;
86 1
        }
87 1
88 1
        return $this->post($this->getPath(), $params);
89 1
    }
90 1
    
91
       /**
92 1
     * Create a checklist Item
93
     * @link https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem
94
     *
95
     * @param string $cardId id of the card the item is added to
96
     * @param string $checkListId id of the checklist the item is added to  
97
     * @param array  $params optional attributes
98
     *
99
     * @return array card info
100
     */
101
102
    public function createCheckListItem($cardId, $checkListId, $params = Array()){
103
        
104 1
        $this->validateRequiredParameters(array('idChecklist', 'name'), $params);
105
106 1
        return $this->post($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem', $params);
107
    }
108
109
    /**
110
     * Update a card
111
     * @link https://trello.com/docs/api/card/#put-1-cards
112
     *
113
     * @param string $id     the card's id or short link
114
     * @param array  $params card attributes to update
115
     *
116
     * @return array card info
117
     */
118 1
    public function update($id, array $params = array())
119
    {
120 1
        return $this->put($this->getPath().'/'.rawurlencode($id), $params);
121
    }
122
123
    /**
124
     * Set a given card's board
125
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idboard
126
     *
127
     * @param string $id      the card's id or short link
128
     * @param string $boardId the board's id
129
     *
130
     * @return array board info
131
     */
132 1
    public function setBoard($id, $boardId)
133
    {
134 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idBoard', array('value' => $boardId));
135
    }
136
137
    /**
138
     * Get a given card's board
139
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idboard
140
     *
141
     * @param string $id     the card's id or short link
142
     * @param array  $params optional parameters
143
     *
144
     * @return array board info
145
     */
146
    public function getBoard($id, array $params = array())
147
    {
148 2
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board', $params);
149
    }
150 2
151
    /**
152 1
     * Get the field of a board of a given card
153
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-board-field
154
     *
155
     * @param string $id    the card's id
156
     * @param array  $field the name of the field
157
     *
158
     * @return array board info
159
     *
160
     * @throws InvalidArgumentException if the field does not exist
161
     */
162
    public function getBoardField($id, $field)
163
    {
164 1
        $this->validateAllowedParameters(Board::$fields, $field, 'field');
165
166 1
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field));
167
    }
168
169
    /**
170
     * Get the checkitemstates, for now will return the full list of checkitem states;
171
     * @link https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-checkitemstates
172
     *
173
     * @param string $id     the card's id or short link
174
     *
175
     * @return array list info
176
     */
177
    public function getCheckItemStates($id){
178 1
179
        return $this->get($this->getPath().'/'.rawurlencode($id).'/checkItemStates', array('value' => 'all'));
180 1
    }
181
    
182
     /**
183
     * Get the members;
184
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-members
185
     *
186
     * @param string $id the card's id or short link
187
     *
188
     * @return array list info
189
     */
190
    public function getMembers($id){
191
        return $this->get($this->getPath().'/'.rawurlencode($id).'/members', array('value' => 'all'));
192
    }
193
    /**
194 2
     * Set a given card's list
195
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idlist
196 2
     *
197
     * @param string $id     the card's id or short link
198 1
     * @param string $listId the list's id
199
     *
200
     * @return array list info
201
     */
202
    public function setList($id, $listId)
203
    {
204
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idList', array('value' => $listId));
205
    }
206
207
    /**
208
     * Get a given card's list
209
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-list
210 1
     *
211
     * @param string $id     the card's id or short link
212 1
     * @param array  $params optional parameters
213
     *
214
     * @return array list info
215
     */
216
    public function getList($id, array $params = array())
217
    {
218
        return $this->get($this->getPath().'/'.rawurlencode($id).'/list', $params);
219
    }
220
221
    /**
222
     * Get the field of a list of a given card
223
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-list-field
224 1
     *
225
     * @param string $id    the card's id
226 1
     * @param array  $field the name of the field
227
     *
228
     * @return array board info
229
     *
230
     * @throws InvalidArgumentException if the field does not exist
231
     */
232
    public function getListField($id, $field)
233
    {
234
        $this->validateAllowedParameters(Cardlist::$fields, $field, 'field');
235
236
        return $this->get($this->getPath().'/'.rawurlencode($id).'/list/'.rawurlencode($field));
237
    }
238 1
239
    /**
240 1
     * Set a given card's name
241
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-name
242
     *
243
     * @param string $id   the card's id or short link
244
     * @param string $name the name
245
     *
246
     * @return array card info
247
     */
248
    public function setName($id, $name)
249
    {
250
        return $this->put($this->getPath().'/'.rawurlencode($id).'/name', array('value' => $name));
251
    }
252 1
253
    /**
254 1
     * Set a given card's description
255
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-desc
256
     *
257
     * @param string $id          the card's id or short link
258
     * @param string $description the description
259
     *
260
     * @return array card info
261
     */
262
    public function setDescription($id, $description)
263
    {
264
        return $this->put($this->getPath().'/'.rawurlencode($id).'/desc', array('value' => $description));
265
    }
266
267 1
    /**
268
     * Set a given card's state
269 1
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-closed
270
     *
271
     * @param string $id     the card's id or short link
272
     * @param bool   $closed whether the card should be closed or not
273
     *
274
     * @return array card info
275
     */
276
    public function setClosed($id, $closed = true)
277
    {
278
        return $this->put($this->getPath().'/'.rawurlencode($id).'/closed', array('value' => $closed));
279
    }
280
281 1
    /**
282
     * Set a given card's due date
283 1
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-due
284
     *
285
     * @param string    $id   the card's id or short link
286
     * @param \DateTime $date the due date
287
     *
288
     * @return array card info
289
     */
290
    public function setDueDate($id, \DateTime $date = null)
291 1
    {
292
        return $this->put($this->getPath().'/'.rawurlencode($id).'/due', array('value' => $date));
293 1
    }
294
295
    /**
296
     * Set a given card's position
297
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-pos
298
     *
299
     * @param string         $id       the card's id or short link
300
     * @param string|integer $position the position, eg. 'top', 'bottom'
301 1
     *                                 or a positive number
302
     *
303 1
     * @return array card info
304
     */
305
    public function setPosition($id, $position)
306
    {
307
        return $this->put($this->getPath().'/'.rawurlencode($id).'/pos', array('value' => $position));
308
    }
309
310
    /**
311 1
     * Set a given card's subscription state
312
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-subscribed
313 1
     *
314
     * @param string $id         the list's id
315
     * @param bool   $subscribed subscription state
316
     *
317
     * @return array list info
318
     */
319
    public function setSubscribed($id, $subscribed)
320
    {
321 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/subscribed', array('value' => $subscribed));
322
    }
323 1
324
325
    /**
326
     * Set a given card's memberId
327
     * @link tbd
328
     *
329
     * @param string $id         the list's id
330
     * @param string $idMembers comma seperated list of responsible members
331 1
     *
332
     * @return array list info
333 1
     */
334
    public function setIdMembers($id, $idMembers)
335
    {
336
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idMembers', array('value' => $idMembers));
337
    }
338
    
339
/**
340
     * Set a given checklist item name
341 1
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-name
342
     *
343 1
     * @param string $cardId the cards's id
344
     * @param string $checkListId the checklist's id
345
     * @param string $itemId the item's id
346
     * @param string   $name new name value
347
     *
348
     * @return array list info
349
     */
350
    public function setCheckListItemName($cardId,$checkListId,$itemId, $name)
351
    {
352
        return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/name', array('value' => $name));
353
    }
354
355
    /**
356
     * Set a given checklist item position
357
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-pos
358
     *
359
     * @param string $cardId the cards's id
360
     * @param string $checkListId the checklist's id
361
     * @param string $itemId the item's id
362
     * @param string $position new position value
363
     *
364
     * @return array list info
365
     */
366
    public function setCheckListItemPosition($cardId,$checkListId,$itemId, $position)
367
    {
368
        return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/pos', array('value' => $position));
369
    }
370
371
    /**
372
     * Set a given checklist item closed state
373
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-state
374
     *
375
     * @param string $cardId the cards's id
376
     * @param string $checkListId the checklist's id
377
     * @param string $itemId the item's id
378
     * @param bool   $complete new complete value, defaults to true
379
     *
380
     * @return array list info
381
     */
382
    public function setCheckListItemClosed($cardId,$checkListId,$itemId, $complete = true)
383
    {
384
        return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/state', array('value' => $complete));
385
    }
386
387
    /**
388
     * Update checklist item by parameter array
389
     * @link https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-checklist-idchecklistcurrent-checkitem-idcheckitem
390
     *
391
     * @param string $cardId the cards's id
392
     * @param string $checkListId the checklist's id
393
     * @param string $itemId the item's id
394
     * @param array $params item attributes to update
395
     *
396
     * @return array list info
397
     */
398
    public function updateCheckListItem($cardId,$checkListId,$itemId, $params = array())
399
    {
400
        return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId), $params);
401
    }
402
    
403
    /**
404
     * Get checkitem from a given card
405
     * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-2
406
     *
407
     * @param string $id        the card's id or short link
408
     * @param string $checkItemId the check item id
409
     * @param array $params the parameter array to retrieve, default is to retrieve all fields
410
     *
411
     * @return array
412
     */
413
    public function getCheckItem($id, $checkItemId, array $params = array('fields'=> 'all'))
414
    {
415
        return $this->get($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId), $params);
416
    }
417
418
    /**
419
     * Update checkItem for  a given card
420
     * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-1
421
     *
422
     * @param string $id        the card's id or short link
423
     * @param string $checkItemId the check item id
424
     * @param array $updateFields the fields that should be updated
425
     * @return array
426
     */
427
    public function updateCheckItem($id, $checkItemId, array $updateFields = array())
428
    {
429
        return $this->put($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId), $updateFields);
430
    }
431
    
432
    /**
433
     * Remove checkitem from a given card
434
     * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-2
435
     *
436
     * @param string $id        the card's id or short link
437
     * @param string $checkItemId the checklist item id
438
     *
439
     * @return array
440
     */
441
    public function removeCheckItem($id, $checkItemId)
442
    {
443
        return $this->delete($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId));
444
    }
445
446
    /**
447
     * Actions API
448
     *
449
     * @return Card\Actions
450
     */
451
    public function actions()
452
    {
453
        return new Card\Actions($this->client);
454
    }
455
456
    /**
457
     * Attachments API
458
     *
459
     * @return Card\Attachments
460
     */
461
    public function attachments()
462
    {
463
        return new Card\Attachments($this->client);
464
    }
465
466
    /**
467
     * Checklists API
468
     *
469
     * @return Card\Checklists
470
     */
471
    public function checklists()
472
    {
473
        return new Card\Checklists($this->client);
474
    }
475
476
    /**
477
     * Labels API
478
     *
479
     * @return Card\Labels
480
     */
481
    public function labels()
482
    {
483
        return new Card\Labels($this->client);
484
    }
485
486
    /**
487
     * Members API
488
     *
489
     * @return Card\Members
490
     */
491
    public function members()
492
    {
493
        return new Card\Members($this->client);
494
    }
495
496
    /**
497
     * Stickers API
498
     *
499
     * @return Card\Stickers
500
     */
501
    public function stickers()
502
    {
503
        return new Card\Stickers($this->client);
504
    }
505
}
506