also looking at this
Tags attachment
#50
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.
| @@ -270,7 +270,7 @@ class Folder | ||
| 270 | 270 | * |
| 271 | 271 | * @throws InvalidFormatException |
| 272 | 272 | */ |
| 273 | public function addFolderToMedia($id, $name): array | |
| 273 | protected function addFolderToMedia($id, $name): array | |
| 274 | 274 | { |
| 275 | 275 | if (! is_int($id)) { |
| 276 | 276 | throw new InvalidFormatException(); |
| @@ -289,7 +289,7 @@ class Folder | ||
| 289 | 289 | * |
| 290 | 290 | * @throws InvalidFormatException |
| 291 | 291 | */ |
| 292 | public function deleteFolderFromMedia($id, $folderId) | |
| 292 | protected function deleteFolderFromMedia($id, $folderId) | |
| 293 | 293 | { |
| 294 | 294 | if (! is_int($id) || ! is_int($folderId)) { |
| 295 | 295 | throw new InvalidFormatException(); |
| @@ -298,6 +298,32 @@ class Folder | ||
| 298 | 298 | return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}"); |
| 299 | 299 | } |
| 300 | 300 | |
| 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 | ||
| 301 | 327 | /** |
| 302 | 328 | * Initialize media model. |
| 303 | 329 | * |
| @@ -449,7 +449,7 @@ class Media | ||
| 449 | 449 | * |
| 450 | 450 | * @return array |
| 451 | 451 | */ |
| 452 | public function fetchMediaForFolder($id): array | |
| 452 | protected function fetchMediaForFolder($id): array | |
| 453 | 453 | { |
| 454 | 454 | return $this->client->request('GET', "folders/{$id}/media"); |
| 455 | 455 | } |
| @@ -461,7 +461,7 @@ class Media | ||
| 461 | 461 | * |
| 462 | 462 | * @return array |
| 463 | 463 | */ |
| 464 | public function fetchMediaForTag($id): array | |
| 464 | protected function fetchMediaForTag($id): array | |
| 465 | 465 | { |
| 466 | 466 | return $this->client->request('GET', "tags/{$id}/media"); |
| 467 | 467 | } |
| @@ -471,7 +471,7 @@ class Media | ||
| 471 | 471 | * |
| 472 | 472 | * @return array |
| 473 | 473 | */ |
| 474 | public function fetchForModel() | |
| 474 | protected function fetchForModel() | |
| 475 | 475 | { |
| 476 | 476 | $data = []; |
| 477 | 477 | |
| @@ -489,4 +489,30 @@ class Media | ||
| 489 | 489 | |
| 490 | 490 | return $data; |
| 491 | 491 | } |
| 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 | } | |
| 492 | 518 | } |
| @@ -138,6 +138,30 @@ class Tag | ||
| 138 | 138 | return $this->client->request('DELETE', "tags/{$id}"); |
| 139 | 139 | } |
| 140 | 140 | |
| 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 | ||
| 141 | 165 | /** |
| 142 | 166 | * Initialize the media model. |
| 143 | 167 | * |
| @@ -173,7 +197,7 @@ class Tag | ||
| 173 | 197 | * |
| 174 | 198 | * @return array |
| 175 | 199 | */ |
| 176 | public function fetchTagsForMedia($id): array | |
| 200 | protected function fetchTagsForMedia($id): array | |
| 177 | 201 | { |
| 178 | 202 | return $this->client->request('GET', "media/{$id}/tags"); |
| 179 | 203 | } |
| @@ -185,7 +209,7 @@ class Tag | ||
| 185 | 209 | * |
| 186 | 210 | * @return array |
| 187 | 211 | */ |
| 188 | public function fetchTagsForFolder($id): array | |
| 212 | protected function fetchTagsForFolder($id): array | |
| 189 | 213 | { |
| 190 | 214 | return $this->client->request('GET', "folders/{$id}/tags"); |
| 191 | 215 | } |
| @@ -233,7 +257,7 @@ class Tag | ||
| 233 | 257 | * |
| 234 | 258 | * @return array |
| 235 | 259 | */ |
| 236 | public function fetchForModel(): array | |
| 260 | protected function fetchForModel(): array | |
| 237 | 261 | { |
| 238 | 262 | $data = []; |
| 239 | 263 | |
| @@ -250,4 +274,106 @@ class Tag | ||
| 250 | 274 | |
| 251 | 275 | return $data; |
| 252 | 276 | } |
| 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 | } | |
| 253 | 379 | } |