ReviewOS

also looking at this

meemalabs/meema-client-php

Bulk folders

#31
Merged glennmichael123 wants to merge bulk-folders into main
3 files +80 -14
src/Models/Favorite.phpmodified+13-2
Changes to src/Models/Favorite.php
@@ -116,10 +116,21 @@ class Favorite
116116 */
117117 public function delete($id)
118118 {
119 if (! is_int($id)) {
120 throw new InvalidFormatException();
119 $ids = is_array($id) ? $id : func_get_args();
120
121 foreach ($ids as $id) {
122 if (! is_int($id)) {
123 throw new InvalidFormatException();
124 }
121125 }
122126
127 if (count($ids) > 1) {
128 return $this->client->request('POST', 'bulk/favorites/delete', ['favorite_ids' => $ids]);
129 }
130
131 // If count is equal to 1 get the first element
132 $id = $ids[0];
133
123134 return $this->client->request('DELETE', "favorites/{$id}");
124135 }
125136}
src/Models/Folder.phpmodified+54-10
Changes to src/Models/Folder.php
@@ -137,14 +137,25 @@ class Folder
137137 */
138138 public function delete($id)
139139 {
140 if (! is_int($id)) {
141 throw new InvalidFormatException();
140 $ids = is_array($id) ? $id : func_get_args();
141
142 foreach ($ids as $id) {
143 if (! is_int($id)) {
144 throw new InvalidFormatException();
145 }
146
147 if ($this->model) {
148 return $this->deleteFolderFromMedia($this->model->getId(), $id);
149 }
142150 }
143151
144 if ($this->model) {
145 return $this->deleteFolderFromMedia($this->model->getId(), $id);
152 if (count($ids) > 1) {
153 return $this->client->request('POST', 'bulk/folders/delete', ['folder_ids' => $ids]);
146154 }
147155
156 // If count is equal to 1 get the first element
157 $id = $ids[0];
158
148159 return $this->client->request('DELETE', "folders/{$id}");
149160 }
150161
@@ -171,10 +182,21 @@ class Folder
171182 */
172183 public function archive($id)
173184 {
174 if (! is_int($id)) {
175 throw new InvalidFormatException();
185 $ids = is_array($id) ? $id : func_get_args();
186
187 foreach ($ids as $id) {
188 if (! is_int($id)) {
189 throw new InvalidFormatException();
190 }
176191 }
177192
193 if (count($ids) > 1) {
194 return $this->client->request('POST', 'bulk/folders/archive', ['folder_ids' => $ids]);
195 }
196
197 // If count is equal to 1 get the first element
198 $id = $ids[0];
199
178200 return $this->client->request('POST', "folders/{$id}/archive");
179201 }
180202
@@ -189,10 +211,21 @@ class Folder
189211 */
190212 public function unarchive($id)
191213 {
192 if (! is_int($id)) {
193 throw new InvalidFormatException();
214 $ids = is_array($id) ? $id : func_get_args();
215
216 foreach ($ids as $id) {
217 if (! is_int($id)) {
218 throw new InvalidFormatException();
219 }
194220 }
195221
222 if (count($ids) > 1) {
223 return $this->client->request('POST', 'bulk/folders/unarchive', ['folder_ids' => $ids]);
224 }
225
226 // If count is equal to 1 get the first element
227 $id = $ids[0];
228
196229 return $this->client->request('POST', "folders/{$id}/unarchive");
197230 }
198231
@@ -207,10 +240,21 @@ class Folder
207240 */
208241 public function duplicate($id): array
209242 {
210 if (! is_int($id)) {
211 throw new InvalidFormatException();
243 $ids = is_array($id) ? $id : func_get_args();
244
245 foreach ($ids as $id) {
246 if (! is_int($id)) {
247 throw new InvalidFormatException();
248 }
212249 }
213250
251 if (count($ids) > 1) {
252 return $this->client->request('POST', 'bulk/folders/duplicate', ['folder_ids' => $ids]);
253 }
254
255 // If count is equal to 1 get the first element
256 $id = $ids[0];
257
214258 return $this->client->request('POST', "folders/{$id}/duplicate");
215259 }
216260
src/Models/Tag.phpmodified+13-2
Changes to src/Models/Tag.php
@@ -127,10 +127,21 @@ class Tag
127127 */
128128 public function delete($id)
129129 {
130 if (! is_int($id)) {
131 throw new InvalidFormatException();
130 $ids = is_array($id) ? $id : func_get_args();
131
132 foreach ($ids as $id) {
133 if (! is_int($id)) {
134 throw new InvalidFormatException();
135 }
132136 }
133137
138 if (count($ids) > 1) {
139 return $this->client->request('POST', 'bulk/tags/delete', ['tag_ids' => $ids]);
140 }
141
142 // If count is equal to 1 get the first element
143 $id = $ids[0];
144
134145 return $this->client->request('DELETE', "tags/{$id}");
135146 }
136147