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

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/Models/Folder.phpmodified+0-12
Changes to src/Models/Folder.php
@@ -235,16 +235,4 @@ class Folder
235235
236236 return (new Tag($client))->setFolder($this);
237237 }
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 }
250238}
src/Models/Media.phpmodified+73-1
Changes to src/Models/Media.php
@@ -189,6 +189,17 @@ 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(): Tag
198 {
199 $client = new Client($this->client->getAccessKey());
200
201 return (new Tag($client))->setMedia($this);
202 }
192203
193204 /**
194205 * Fetch the media for the folder.
@@ -205,7 +216,21 @@ class Media
205216 }
206217
207218 /**
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
209234 *
210235 * @return int
211236 */
@@ -214,4 +239,51 @@ class Media
214239 return $this->id;
215240 }
216241
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 }
217289}