also looking at this
Bulk folders
#31
3 files
+80
-14
| @@ -137,14 +137,25 @@ class Folder | ||
| 137 | 137 | */ |
| 138 | 138 | public function delete($id) |
| 139 | 139 | { |
| 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 | } | |
| 142 | 150 | } |
| 143 | 151 | |
| 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]); | |
| 146 | 154 | } |
| 147 | 155 | |
| 156 | // If count is equal to 1 get the first element | |
| 157 | $id = $ids[0]; | |
| 158 | ||
| 148 | 159 | return $this->client->request('DELETE', "folders/{$id}"); |
| 149 | 160 | } |
| 150 | 161 | |
| @@ -171,10 +182,21 @@ class Folder | ||
| 171 | 182 | */ |
| 172 | 183 | public function archive($id) |
| 173 | 184 | { |
| 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 | } | |
| 176 | 191 | } |
| 177 | 192 | |
| 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 | ||
| 178 | 200 | return $this->client->request('POST', "folders/{$id}/archive"); |
| 179 | 201 | } |
| 180 | 202 | |
| @@ -189,10 +211,21 @@ class Folder | ||
| 189 | 211 | */ |
| 190 | 212 | public function unarchive($id) |
| 191 | 213 | { |
| 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 | } | |
| 194 | 220 | } |
| 195 | 221 | |
| 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 | ||
| 196 | 229 | return $this->client->request('POST', "folders/{$id}/unarchive"); |
| 197 | 230 | } |
| 198 | 231 | |
| @@ -207,10 +240,21 @@ class Folder | ||
| 207 | 240 | */ |
| 208 | 241 | public function duplicate($id): array |
| 209 | 242 | { |
| 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 | } | |
| 212 | 249 | } |
| 213 | 250 | |
| 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 | ||
| 214 | 258 | return $this->client->request('POST', "folders/{$id}/duplicate"); |
| 215 | 259 | } |
| 216 | 260 | |