ReviewOS

also looking at this

meemalabs/meema-client-php

Tags model

#14
Merged glennmichael123 wants to merge tags-model-2 into main
5 files +165 -74
src/Models/Media.phpmodified+68-6
Changes to src/Models/Media.php
@@ -50,7 +50,7 @@ class Media
5050 public function get($id = null)
5151 {
5252 if ($this->model) {
53 return $this->fetchMediaForFolder($this->model->getId());
53 return $this->fetchForModel();
5454 }
5555
5656 if (! $id) {
@@ -189,16 +189,30 @@ class Media
189189 return (new Folder($this->client))->setMedia($this);
190190 }
191191
192 /**
193 * Initialize the tags model.
194 *
195 * @return Meema\MeemaApi\Models\Tag
196 */
197 public function tags($id = null): Tag
198 {
199 $this->id = $id;
200
201 return (new Tag($this->client))->setMedia($this);
202 }
203
192204 /**
193205 * Fetch the media for the folder.
194206 *
195207 * @param int $id
196208 *
197 * @return array
209 * @return self
198210 */
199 public function fetchMediaForFolder($id): array
211 public function setFolder($folder): self
200212 {
201 return $this->client->request('GET', "folders/{$id}/media");
213 $this->model = $folder;
214
215 return $this;
202216 }
203217
204218 /**
@@ -208,9 +222,9 @@ class Media
208222 *
209223 * @return self
210224 */
211 public function setFolder($folder): self
225 public function setTag($tag): self
212226 {
213 $this->model = $folder;
227 $this->model = $tag;
214228
215229 return $this;
216230 }
@@ -224,4 +238,52 @@ class Media
224238 {
225239 return $this->id;
226240 }
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 }
227289}