1 | <?php |
||
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 | * |
||
521 |