Completed
Pull Request — master (#16)
by
unknown
05:32
created

Card::createCheckListItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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 checklists, for now will return the full list of checkitem states;
184
     * @link https://trello.readme.io/v1.0/reference#cardsidchecklists
185
     *
186
     * @param string $id     the card's id or short link
187
     * @param array $fields (optional) an array with the requested fields, all by default
188
     *
189
     * @return array checklist info
190
     */
191
    public function getCheckLists($id, array $fields = array('fields'=>'all')){
192
193
        return $this->get($this->getPath().'/'.rawurlencode($id).'/checklists', $fields);
194 2
        
195
    }
196 2
    
197
     /**
198 1
     * Get the members;
199
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-members
200
     *
201
     * @param string $id the card's id or short link
202
     *
203
     * @return array list info
204
     */
205
    public function getMembers($id){
206
        return $this->get($this->getPath().'/'.rawurlencode($id).'/members', array('value' => 'all'));
207
    }
208
    /**
209
     * Set a given card's list
210 1
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idlist
211
     *
212 1
     * @param string $id     the card's id or short link
213
     * @param string $listId the list's id
214
     *
215
     * @return array list info
216
     */
217
    public function setList($id, $listId)
218
    {
219
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idList', array('value' => $listId));
220
    }
221
222
    /**
223
     * Get a given card's list
224 1
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-list
225
     *
226 1
     * @param string $id     the card's id or short link
227
     * @param array  $params optional parameters
228
     *
229
     * @return array list info
230
     */
231
    public function getList($id, array $params = array())
232
    {
233
        return $this->get($this->getPath().'/'.rawurlencode($id).'/list', $params);
234
    }
235
236
    /**
237
     * Get the field of a list of a given card
238 1
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-list-field
239
     *
240 1
     * @param string $id    the card's id
241
     * @param array  $field the name of the field
242
     *
243
     * @return array board info
244
     *
245
     * @throws InvalidArgumentException if the field does not exist
246
     */
247
    public function getListField($id, $field)
248
    {
249
        $this->validateAllowedParameters(Cardlist::$fields, $field, 'field');
250
251
        return $this->get($this->getPath().'/'.rawurlencode($id).'/list/'.rawurlencode($field));
252 1
    }
253
254 1
    /**
255
     * Set a given card's name
256
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-name
257
     *
258
     * @param string $id   the card's id or short link
259
     * @param string $name the name
260
     *
261
     * @return array card info
262
     */
263
    public function setName($id, $name)
264
    {
265
        return $this->put($this->getPath().'/'.rawurlencode($id).'/name', array('value' => $name));
266
    }
267 1
268
    /**
269 1
     * Set a given card's description
270
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-desc
271
     *
272
     * @param string $id          the card's id or short link
273
     * @param string $description the description
274
     *
275
     * @return array card info
276
     */
277
    public function setDescription($id, $description)
278
    {
279
        return $this->put($this->getPath().'/'.rawurlencode($id).'/desc', array('value' => $description));
280
    }
281 1
282
    /**
283 1
     * Set a given card's state
284
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-closed
285
     *
286
     * @param string $id     the card's id or short link
287
     * @param bool   $closed whether the card should be closed or not
288
     *
289
     * @return array card info
290
     */
291 1
    public function setClosed($id, $closed = true)
292
    {
293 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/closed', array('value' => $closed));
294
    }
295
296
    /**
297
     * Set a given card's due date
298
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-due
299
     *
300
     * @param string    $id   the card's id or short link
301 1
     * @param \DateTime $date the due date
302
     *
303 1
     * @return array card info
304
     */
305
    public function setDueDate($id, \DateTime $date = null)
306
    {
307
        return $this->put($this->getPath().'/'.rawurlencode($id).'/due', array('value' => $date));
308
    }
309
310
    /**
311 1
     * Set a given card's position
312
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-pos
313 1
     *
314
     * @param string         $id       the card's id or short link
315
     * @param string|integer $position the position, eg. 'top', 'bottom'
316
     *                                 or a positive number
317
     *
318
     * @return array card info
319
     */
320
    public function setPosition($id, $position)
321 1
    {
322
        return $this->put($this->getPath().'/'.rawurlencode($id).'/pos', array('value' => $position));
323 1
    }
324
325
    /**
326
     * Set a given card's subscription state
327
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-subscribed
328
     *
329
     * @param string $id         the list's id
330
     * @param bool   $subscribed subscription state
331 1
     *
332
     * @return array list info
333 1
     */
334
    public function setSubscribed($id, $subscribed)
335
    {
336
        return $this->put($this->getPath().'/'.rawurlencode($id).'/subscribed', array('value' => $subscribed));
337
    }
338
339
340
    /**
341 1
     * Set a given card's memberId
342
     * @link tbd
343 1
     *
344
     * @param string $id         the list's id
345
     * @param string $idMembers comma seperated list of responsible members
346
     *
347
     * @return array list info
348
     */
349
    public function setIdMembers($id, $idMembers)
350
    {
351
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idMembers', array('value' => $idMembers));
352
    }
353
    
354
/**
355
     * Set a given checklist item name
356
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-name
357
     *
358
     * @param string $cardId the cards's id
359
     * @param string $checkListId the checklist's id
360
     * @param string $itemId the item's id
361
     * @param string   $name new name value
362
     *
363
     * @return array list info
364
     */
365
    public function setCheckListItemName($cardId,$checkListId,$itemId, $name)
366
    {
367
        return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/name', array('value' => $name));
368
    }
369
370
    /**
371
     * Set a given checklist item position
372
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-pos
373
     *
374
     * @param string $cardId the cards's id
375
     * @param string $checkListId the checklist's id
376
     * @param string $itemId the item's id
377
     * @param string $position new position value
378
     *
379
     * @return array list info
380
     */
381
    public function setCheckListItemPosition($cardId,$checkListId,$itemId, $position)
382
    {
383
        return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/pos', array('value' => $position));
384
    }
385
386
    /**
387
     * Set a given checklist item closed state
388
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-state
389
     *
390
     * @param string $cardId the cards's id
391
     * @param string $checkListId the checklist's id
392
     * @param string $itemId the item's id
393
     * @param bool   $complete new complete value, defaults to true
394
     *
395
     * @return array list info
396
     */
397
    public function setCheckListItemClosed($cardId,$checkListId,$itemId, $complete = true)
398
    {
399
        return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/state', array('value' => $complete));
400
    }
401
402
    /**
403
     * Update checklist item by parameter array
404
     * @link https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-checklist-idchecklistcurrent-checkitem-idcheckitem
405
     *
406
     * @param string $cardId the cards's id
407
     * @param string $checkListId the checklist's id
408
     * @param string $itemId the item's id
409
     * @param array $params item attributes to update
410
     *
411
     * @return array list info
412
     */
413
    public function updateCheckListItem($cardId,$checkListId,$itemId, $params = array())
414
    {
415
        return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId), $params);
416
    }
417
    
418
    /**
419
     * Get checkitem from a given card
420
     * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-2
421
     *
422
     * @param string $id        the card's id or short link
423
     * @param string $checkItemId the check item id
424
     * @param array $params the parameter array to retrieve, default is to retrieve all fields
425
     *
426
     * @return array
427
     */
428
    public function getCheckItem($id, $checkItemId, array $params = array('fields'=> 'all'))
429
    {
430
        return $this->get($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId), $params);
431
    }
432
433
    /**
434
     * Update checkItem for  a given card
435
     * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-1
436
     *
437
     * @param string $id        the card's id or short link
438
     * @param string $checkItemId the check item id
439
     * @param array $updateFields the fields that should be updated
440
     * @return array
441
     */
442
    public function updateCheckItem($id, $checkItemId, array $updateFields = array())
443
    {
444
        return $this->put($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId), $updateFields);
445
    }
446
    
447
    /**
448
     * Remove checkitem from a given card
449
     * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-2
450
     *
451
     * @param string $id        the card's id or short link
452
     * @param string $checkItemId the checklist item id
453
     *
454
     * @return array
455
     */
456
    public function removeCheckItem($id, $checkItemId)
457
    {
458
        return $this->delete($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId));
459
    }
460
461
    /**
462
     * Actions API
463
     *
464
     * @return Card\Actions
465
     */
466
    public function actions()
467
    {
468
        return new Card\Actions($this->client);
469
    }
470
471
    /**
472
     * Attachments API
473
     *
474
     * @return Card\Attachments
475
     */
476
    public function attachments()
477
    {
478
        return new Card\Attachments($this->client);
479
    }
480
481
    /**
482
     * Checklists API
483
     *
484
     * @return Card\Checklists
485
     */
486
    public function checklists()
487
    {
488
        return new Card\Checklists($this->client);
489
    }
490
491
    /**
492
     * Labels API
493
     *
494
     * @return Card\Labels
495
     */
496
    public function labels()
497
    {
498
        return new Card\Labels($this->client);
499
    }
500
501
    /**
502
     * Members API
503
     *
504
     * @return Card\Members
505
     */
506
    public function members()
507
    {
508
        return new Card\Members($this->client);
509
    }
510
511
    /**
512
     * Stickers API
513
     *
514
     * @return Card\Stickers
515
     */
516
    public function stickers()
517
    {
518
        return new Card\Stickers($this->client);
519
    }
520
521
    /**
522
     * CustomFieldItems API
523
     *
524
     * @return Card\CustomFieldItems
525
     */
526
    public function customFieldItems()
527
    {
528
        return new Card\CustomFieldItems($this->client);
529
    }
530
}
531