ReviewOS

also looking at this

meemalabs/meema-client-php

Tags attachment

#50
Merged glennmichael123 wants to merge tag-attach into main
4 files +187 -9

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

src/Client.phpmodified+1-1
Changes to src/Client.php
@@ -74,7 +74,7 @@ class Client
7474
7575 $body = json_decode($content, true);
7676
77 if ($body && $body['data']) {
77 if ($body && array_key_exists('data', $body)) {
7878 return $body['data'];
7979 }
8080
src/Models/Folder.phpmodified+28-2
Changes to src/Models/Folder.php
@@ -270,7 +270,7 @@ class Folder
270270 *
271271 * @throws InvalidFormatException
272272 */
273 public function addFolderToMedia($id, $name): array
273 protected function addFolderToMedia($id, $name): array
274274 {
275275 if (! is_int($id)) {
276276 throw new InvalidFormatException();
@@ -289,7 +289,7 @@ class Folder
289289 *
290290 * @throws InvalidFormatException
291291 */
292 public function deleteFolderFromMedia($id, $folderId)
292 protected function deleteFolderFromMedia($id, $folderId)
293293 {
294294 if (! is_int($id) || ! is_int($folderId)) {
295295 throw new InvalidFormatException();
@@ -298,6 +298,32 @@ class Folder
298298 return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}");
299299 }
300300
301 /**
302 * Associate tag to a folder.
303 *
304 * @param int $id
305 * @param array $tag
306 *
307 * @return array
308 */
309 public function associateTag($id, $tag)
310 {
311 return $this->client->request('POST', "folders/{$id}/tag/attach", $tag);
312 }
313
314 /**
315 * Disassociate tag from a folder.
316 *
317 * @param int $id
318 * @param array $tag
319 *
320 * @return array
321 */
322 public function disassociateTag($id, $tag)
323 {
324 return $this->client->request('POST', "folders/{$id}/tag/detach", $tag);
325 }
326
301327 /**
302328 * Initialize media model.
303329 *
src/Models/Media.phpmodified+29-3
Changes to src/Models/Media.php
@@ -449,7 +449,7 @@ class Media
449449 *
450450 * @return array
451451 */
452 public function fetchMediaForFolder($id): array
452 protected function fetchMediaForFolder($id): array
453453 {
454454 return $this->client->request('GET', "folders/{$id}/media");
455455 }
@@ -461,7 +461,7 @@ class Media
461461 *
462462 * @return array
463463 */
464 public function fetchMediaForTag($id): array
464 protected function fetchMediaForTag($id): array
465465 {
466466 return $this->client->request('GET', "tags/{$id}/media");
467467 }
@@ -471,7 +471,7 @@ class Media
471471 *
472472 * @return array
473473 */
474 public function fetchForModel()
474 protected function fetchForModel()
475475 {
476476 $data = [];
477477
@@ -489,4 +489,30 @@ class Media
489489
490490 return $data;
491491 }
492
493 /**
494 * Associate tag to a media.
495 *
496 * @param int $id
497 * @param array $tag
498 *
499 * @return array
500 */
501 public function associateTag($id, $tag)
502 {
503 return $this->client->request('POST', "media/{$id}/tag/attach", $tag);
504 }
505
506 /**
507 * Disassociate tag from a media.
508 *
509 * @param int $id
510 * @param array $tag
511 *
512 * @return array
513 */
514 public function disassociateTag($id, $tag)
515 {
516 return $this->client->request('POST', "media/{$id}/tag/detach", $tag);
517 }
492518}
src/Models/Tag.phpmodified+129-3
Changes to src/Models/Tag.php
@@ -138,6 +138,30 @@ class Tag
138138 return $this->client->request('DELETE', "tags/{$id}");
139139 }
140140
141 /**
142 * Associate tags to a model.
143 *
144 * @param array $tag
145 *
146 * @return array
147 */
148 public function associate($tag)
149 {
150 return $this->associateToModel($tag);
151 }
152
153 /**
154 * Associate tags to media.
155 *
156 * @param array $tag
157 *
158 * @return array
159 */
160 public function disassociate($tag)
161 {
162 return $this->disassociateToModel($tag);
163 }
164
141165 /**
142166 * Initialize the media model.
143167 *
@@ -173,7 +197,7 @@ class Tag
173197 *
174198 * @return array
175199 */
176 public function fetchTagsForMedia($id): array
200 protected function fetchTagsForMedia($id): array
177201 {
178202 return $this->client->request('GET', "media/{$id}/tags");
179203 }
@@ -185,7 +209,7 @@ class Tag
185209 *
186210 * @return array
187211 */
188 public function fetchTagsForFolder($id): array
212 protected function fetchTagsForFolder($id): array
189213 {
190214 return $this->client->request('GET', "folders/{$id}/tags");
191215 }
@@ -233,7 +257,7 @@ class Tag
233257 *
234258 * @return array
235259 */
236 public function fetchForModel(): array
260 protected function fetchForModel(): array
237261 {
238262 $data = [];
239263
@@ -250,4 +274,106 @@ class Tag
250274
251275 return $data;
252276 }
277
278 /**
279 * Associate tags to a folder or media.
280 *
281 * @param array $tag
282 *
283 * @return array
284 */
285 protected function associateToModel($tag): array
286 {
287 $data = [];
288
289 switch (get_class($this->model)) {
290 case Folder::class:
291 $data = $this->associateTagToFolder($this->model->getId(), $tag);
292 break;
293 case Media::class:
294 $data = $this->associateTagToMedia($this->model->getId(), $tag);
295 break;
296 default:
297 $data = [];
298 }
299
300 return $data;
301 }
302
303 /**
304 * Associate tags to a folder or media.
305 *
306 * @param array $tag
307 *
308 * @return array
309 */
310 protected function disassociateToModel($tag): array
311 {
312 $data = [];
313
314 switch (get_class($this->model)) {
315 case Folder::class:
316 $data = $this->disassociateTagFromFolder($this->model->getId(), $tag);
317 break;
318 case Media::class:
319 $data = $this->disassociateTagFromMedia($this->model->getId(), $tag);
320 break;
321 default:
322 $data = [];
323 }
324
325 return $data;
326 }
327
328 /**
329 * Associate tag to a folder.
330 *
331 * @param int $id
332 * @param array $tag
333 *
334 * @return array
335 */
336 protected function associateTagToFolder($id, $tag)
337 {
338 return $this->client->request('POST', "folders/{$id}/tag/attach", $tag);
339 }
340
341 /**
342 * Disassociate tag from a folder.
343 *
344 * @param int $id
345 * @param array $tag
346 *
347 * @return array
348 */
349 protected function disassociateTagFromFolder($id, $tag)
350 {
351 return $this->client->request('POST', "folders/{$id}/tag/detach", $tag);
352 }
353
354 /**
355 * Associate tag to a media.
356 *
357 * @param int $id
358 * @param array $tag
359 *
360 * @return array
361 */
362 protected function associateTagToMedia($id, $tag)
363 {
364 return $this->client->request('POST', "media/{$id}/tag/attach", $tag);
365 }
366
367 /**
368 * Disassociate tag from a media.
369 *
370 * @param int $id
371 * @param array $tag
372 *
373 * @return array
374 */
375 protected function disassociateTagFromMedia($id, $tag)
376 {
377 return $this->client->request('POST', "media/{$id}/tag/detach", $tag);
378 }
253379}