ReviewOS

also looking at this

meemalabs/meema-client-php

Media model

#6
Merged glennmichael123 wants to merge media-model into main
7 files +1700 -76
src/Models/Folder.phpmodified+106-6
Changes to src/Models/Folder.php
@@ -3,18 +3,24 @@
33namespace Meema\MeemaApi\Models;
44
55use Meema\MeemaApi\Client;
6use Meema\MeemaApi\Response\Response;
67
78class Folder
89{
910 /**
10 * @var Meema\MeemaApi\Client
11 * @var \Meema\MeemaApi\Client
1112 */
12 public $client;
13 protected $client;
1314
1415 /**
1516 * @var int
1617 */
17 public $id;
18 protected $id;
19
20 /**
21 * @var object
22 */
23 protected $model;
1824
1925 /**
2026 * Construct Folder model.
@@ -39,6 +45,8 @@ class Folder
3945 /**
4046 * Get specific folders.
4147 *
48 * @param int $id
49 *
4250 * @return array
4351 */
4452 public function get($id = null)
@@ -49,7 +57,23 @@ class Folder
4957
5058 $ids = is_array($id) ? $id : func_get_args();
5159
52 return $this->client->request('GET', 'folders/show', ['folder_ids' => $ids]);
60 return $this->client->request('GET', 'folders', ['folder_ids' => $ids]);
61 }
62
63 /**
64 * Get specific folders.
65 *
66 * @param int $id
67 *
68 * @return Response
69 */
70 public function find($id): Response
71 {
72 $response = $this->client->request('GET', "folders/${id}");
73
74 $this->id = $response['data']['id'];
75
76 return new Response($this, $response);
5377 }
5478
5579 /**
@@ -63,14 +87,20 @@ class Folder
6387 {
6488 $name = is_array($name) ? $name : compact('name');
6589
90 if ($this->model) {
91 $folderName = ['folder_name' => $name['name']];
92
93 return $this->addFolderToMedia($this->model->getId(), $folderName);
94 }
95
6696 return $this->client->request('POST', "folders/{$this->client->getAccessKey()}", $name);
6797 }
6898
6999 /**
70100 * Update folder.
71101 *
72 * @param int $id
73102 * @param string $name
103 * @param int $id
74104 *
75105 * @return array
76106 */
@@ -84,18 +114,24 @@ class Folder
84114 /**
85115 * Delete a folder.
86116 *
87 * @param int|array $id
117 * @param int $id
88118 *
89119 * @return null
90120 */
91121 public function delete($id)
92122 {
123 if ($this->model) {
124 return $this->deleteFolderFromMedia($this->model->getId(), $id);
125 }
126
93127 return $this->client->request('DELETE', "folders/{$id}");
94128 }
95129
96130 /**
97131 * Archive a folder.
98132 *
133 * @param int $id
134 *
99135 * @return array
100136 */
101137 public function archive($id): array
@@ -106,6 +142,8 @@ class Folder
106142 /**
107143 * Unarchive a folder.
108144 *
145 * @param int $id
146 *
109147 * @return array
110148 */
111149 public function unarchive($id): array
@@ -116,10 +154,72 @@ class Folder
116154 /**
117155 * Duplicate a folder.
118156 *
157 * @param int $id
158 *
119159 * @return array
120160 */
121161 public function duplicate($id): array
122162 {
123163 return $this->client->request('POST', "folders/{$id}/duplicate");
124164 }
165
166 /**
167 * Add folder to media.
168 *
169 * @param int $id
170 *
171 * @return array
172 */
173 public function addFolderToMedia($id, $name): array
174 {
175 return $this->client->request('POST', "media/{$id}/folders", $name);
176 }
177
178 /**
179 * Add folder to media.
180 *
181 * @param int $id
182 *
183 * @return null
184 */
185 public function deleteFolderFromMedia($mediaId, $folderId)
186 {
187 return $this->client->request('DELETE', "media/{$mediaId}/folders/{$folderId}");
188 }
189
190 /**
191 * Initialize media model.
192 *
193 * @param Meema\MeemaApi\Models\Media $media
194 *
195 * @return self
196 */
src/Models/Folder.php:196
  1. harlekoySun Oct 25 2026 00:09:39 GMT+0000 (Coordinated Universal Time)

    @glennmichael123 can we have something like this instead.

    return (new Media($this->client))->setFolder($this->id);
197 public function setMedia($media): self
198 {
199 $this->model = $media;
200
201 return $this;
202 }
203
204 /**
205 * Get the protected id.
206 *
207 * @return int
208 */
209 public function getId(): int
210 {
211 return $this->id;
212 }
213
214 /**
215 * Initialize the media model.
216 *
217 * @return Meema\MeemaApi\Models\Media
218 */
219 public function media($id = null): Media
220 {
221 $this->id = $id;
222
223 return (new Media($this->client))->setFolder($this);
224 }
125225}