1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Trello\Api\Card; |
4
|
|
|
|
5
|
|
|
use Trello\Api\AbstractApi; |
6
|
|
|
use Trello\Exception\MissingArgumentException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Trello Card Checklists API |
10
|
|
|
* @link https://trello.com/docs/api/card |
11
|
|
|
* |
12
|
|
|
* Fully implemented. |
13
|
|
|
*/ |
14
|
|
|
class Checklists extends AbstractApi |
15
|
|
|
{ |
16
|
|
|
protected $path = 'cards/#id#/checklists'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get checklists related to a given card |
20
|
|
|
* @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-checklists |
21
|
|
|
* |
22
|
|
|
* @param string $id the card's id or short link |
23
|
|
|
* @param array $params optional parameters |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
1 |
|
public function all($id, array $params = array()) |
28
|
|
|
{ |
29
|
1 |
|
return $this->get('cards/'.rawurlencode($id).'/checklists', $params); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Add a checklist to a given card |
34
|
|
|
* @link https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklists |
35
|
|
|
* |
36
|
|
|
* @param string $id the card's id or short link |
37
|
|
|
* @param array $params All parameters are optional, but at least one has to be provided: |
38
|
|
|
* - value : id of the checklist to add, or null to create a new one. |
39
|
|
|
* - name : the checklist's name |
40
|
|
|
* - idChecklistSource : id of the source checklist to copy |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
* |
44
|
|
|
* @throws MissingArgumentException If there is not at least of the |
45
|
|
|
* following parameters: 'value', 'name', 'idChecklistSource' |
46
|
|
|
*/ |
47
|
2 |
View Code Duplication |
public function create($id, array $params) |
|
|
|
|
48
|
|
|
{ |
49
|
2 |
|
$atLeastOneOf = array('value', 'name', 'idChecklistSource'); |
50
|
2 |
|
$this->validateAtLeastOneOf($atLeastOneOf, $params); |
51
|
|
|
|
52
|
1 |
|
return $this->post($this->getPath($id), $params); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Remove a given checklist from a given card |
57
|
|
|
* @link https://trello.com/docs/api/card/#delete-1-cards-card-id-or-shortlink-checklists-idchecklist |
58
|
|
|
* |
59
|
|
|
* @param string $id the card's id or short link |
60
|
|
|
* @param string $checklistId the checklist's id |
61
|
|
|
* |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
1 |
|
public function remove($id, $checklistId) |
65
|
|
|
{ |
66
|
1 |
|
return $this->delete($this->getPath($id).'/'.rawurlencode($checklistId)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get a given card's checklist item states |
71
|
|
|
* @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-checkitemstates |
72
|
|
|
* |
73
|
|
|
* @param string $id the card's id or short link |
74
|
|
|
* |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
1 |
|
public function itemStates($id, array $params = array()) |
78
|
|
|
{ |
79
|
1 |
|
return $this->get('cards/'.rawurlencode($id).'/checkItemStates', $params); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Update a given check item |
84
|
|
|
* @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklistcurrent-checkitem-idcheckitem |
85
|
|
|
* |
86
|
|
|
* @param string $id the card's id or short link |
87
|
|
|
* @param string $checklistId the checklist's id |
88
|
|
|
* @param string $checkItemId the check item's id |
89
|
|
|
* @param array $data check item data |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
1 |
|
public function updateItem($id, $checklistId, $checkItemId, array $data) |
94
|
|
|
{ |
95
|
1 |
|
return $this->put( |
96
|
1 |
|
$this->getPath($id).'/'.rawurlencode($checklistId).'/checkItem/'.rawurlencode($checkItemId), |
97
|
|
|
$data |
98
|
1 |
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Create a check item |
103
|
|
|
* @link https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem |
104
|
|
|
* |
105
|
|
|
* @param string $id the card's id or short link |
106
|
|
|
* @param string $checklistId the checklist's id |
107
|
|
|
* @param string $name check item name |
108
|
|
|
* @param array $data check item data |
109
|
|
|
* |
110
|
|
|
* @return array |
111
|
|
|
*/ |
112
|
1 |
|
public function createItem($id, $checklistId, $name, array $data = array()) |
113
|
|
|
{ |
114
|
1 |
|
$data['idChecklist'] = $checklistId; |
115
|
1 |
|
$data['name'] = $name; |
116
|
|
|
|
117
|
1 |
|
return $this->post($this->getPath($id).'/'.rawurlencode($checklistId).'/checkItem', $data); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Convert a check item to card |
122
|
|
|
* @link https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem |
123
|
|
|
* |
124
|
|
|
* @param string $id the card's id or short link |
125
|
|
|
* @param string $checklistId the checklist's id |
126
|
|
|
* @param string $checkItemId the check item's id |
127
|
|
|
* |
128
|
|
|
* @return array |
129
|
|
|
*/ |
130
|
1 |
|
public function convertItemToCard($id, $checklistId, $checkItemId) |
131
|
|
|
{ |
132
|
1 |
|
return $this->post( |
133
|
1 |
|
$this->getPath($id).'/'.rawurlencode($checklistId).'/checkItem/'.rawurlencode($checkItemId).'/convertToCard' |
134
|
1 |
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Remove a check item from card |
139
|
|
|
* @link https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem |
140
|
|
|
* |
141
|
|
|
* @param string $id the card's id or short link |
142
|
|
|
* @param string $checklistId the checklist's id |
143
|
|
|
* @param string $checkItemId the check item's id |
144
|
|
|
* |
145
|
|
|
* @return array |
146
|
|
|
*/ |
147
|
1 |
|
public function removeItem($id, $checklistId, $checkItemId) |
148
|
|
|
{ |
149
|
1 |
|
return $this->delete( |
150
|
1 |
|
$this->getPath($id).'/'.rawurlencode($checklistId).'/checkItem/'.rawurlencode($checkItemId) |
151
|
1 |
|
); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.