also looking at this
Tags attachment
#50
4 files
+187
-9
| @@ -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 | } |