also looking at this
Tags model
#14
5 files
+165
-74
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.
| @@ -235,16 +235,4 @@ class Folder | ||
| 235 | 235 | |
| 236 | 236 | return (new Tag($client))->setFolder($this); |
| 237 | 237 | } |
| 238 | ||
| 239 | /** | |
| 240 | * Initialize the tags model. | |
| 241 | * | |
| 242 | * @return Meema\MeemaApi\Models\Tag | |
| 243 | */ | |
| 244 | public function tags(): Tag | |
| 245 | { | |
| 246 | $client = new Client($this->client->getAccessKey()); | |
| 247 | ||
| 248 | return (new Tag($client))->setFolder($this); | |
| 249 | } | |
| 250 | 238 | } |
| @@ -189,6 +189,17 @@ class Media | ||
| 189 | 189 | return (new Folder($this->client))->setMedia($this); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | /** | |
| 193 | * Initialize the tags model. | |
| 194 | * | |
| 195 | * @return Meema\MeemaApi\Models\Tag | |
| 196 | */ | |
| 197 | public function tags(): Tag | |
| 198 | { | |
| 199 | $client = new Client($this->client->getAccessKey()); | |
| 200 | ||
| 201 | return (new Tag($client))->setMedia($this); | |
| 202 | } | |
| 192 | 203 | |
| 193 | 204 | /** |
| 194 | 205 | * Fetch the media for the folder. |
| @@ -205,7 +216,21 @@ class Media | ||
| 205 | 216 | } |
| 206 | 217 | |
| 207 | 218 | /** |
| 208 | * Get the protected id. | |
| 219 | * Initialize media model. | |
| 220 | * | |
| 221 | * @param Meema\MeemaApi\Models\Folder $folder | |
| 222 | * | |
| 223 | * @return self | |
| 224 | */ | |
| 225 | public function setTag($tag): self | |
| 226 | { | |
| 227 | $this->model = $tag; | |
| 228 | ||
| 229 | return $this; | |
| 230 | } | |
| 231 | ||
| 232 | /** | |
| 233 | * Get the protected id | |
| 209 | 234 | * |
| 210 | 235 | * @return int |
| 211 | 236 | */ |
| @@ -214,4 +239,51 @@ class Media | ||
| 214 | 239 | return $this->id; |
| 215 | 240 | } |
| 216 | 241 | |
| 242 | /** | |
| 243 | * Fetch the media for the folder. | |
| 244 | * | |
| 245 | * @param int $id | |
| 246 | * | |
| 247 | * @return array | |
| 248 | */ | |
| 249 | public function fetchMediaForFolder($id): array | |
| 250 | { | |
| 251 | return $this->client->request('GET', "folders/{$id}/media"); | |
| 252 | } | |
| 253 | ||
| 254 | /** | |
| 255 | * Fetch the media for tags. | |
| 256 | * | |
| 257 | * @param int $id | |
| 258 | * | |
| 259 | * @return array | |
| 260 | */ | |
| 261 | public function fetchMediaForTag($id): array | |
| 262 | { | |
| 263 | return $this->client->request('GET', "tags/{$id}/media"); | |
| 264 | } | |
| 265 | ||
| 266 | /** | |
| 267 | * Fetch child relations for this instance. | |
| 268 | * | |
| 269 | * @return array | |
| 270 | */ | |
| 271 | public function fetchForModel() | |
| 272 | { | |
| 273 | $data = []; | |
| 274 | ||
| 275 | switch (get_class($this->model)) { | |
| 276 | case Folder::class: | |
| 277 | $data = $this->fetchMediaForFolder($this->model->getId()); | |
| 278 | break; | |
| 279 | case Tag::class: | |
| 280 | $data = $this->fetchMediaForTag($this->model->getId()); | |
| 281 | break; | |
| 282 | default: | |
| 283 | $data = []; | |
| 284 | break; | |
| 285 | } | |
| 286 | ||
| 287 | return $data; | |
| 288 | } | |
| 217 | 289 | } |