also looking at this
Tags model
#14
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.
| @@ -235,4 +235,16 @@ class Folder | ||
| 235 | 235 | |
| 236 | 236 | return (new Tag($client))->setFolder($this); |
| 237 | 237 | } |
| 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 | } | |
| 238 | 250 | } |
| @@ -189,10 +189,11 @@ class Media | ||
| 189 | 189 | return (new Folder($this->client))->setMedia($this); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | ||
| 192 | 193 | /** |
| 193 | * Initialize media model. | |
| 194 | * Fetch the media for the folder. | |
| 194 | 195 | * |
| 195 | * @param Meema\MeemaApi\Models\Folder $folder | |
| 196 | * @param int $id | |
| 196 | 197 | * |
| 197 | 198 | * @return self |
| 198 | 199 | */ |
| @@ -119,8 +119,6 @@ class Tag | ||
| 119 | 119 | */ |
| 120 | 120 | public function delete($id) |
| 121 | 121 | { |
| 122 | $id = $this->id ?? $id; | |
| 123 | ||
| 124 | 122 | return $this->client->request('DELETE', "tags/{$id}"); |
| 125 | 123 | } |
| 126 | 124 | |
| @@ -133,7 +131,7 @@ class Tag | ||
| 133 | 131 | { |
| 134 | 132 | $client = new Client($this->client->getAccessKey()); |
| 135 | 133 | |
| 136 | return new Media($client, $this); | |
| 134 | return (new Media($client))->setTag($this); | |
| 137 | 135 | } |
| 138 | 136 | |
| 139 | 137 | /** |
| @@ -186,6 +184,20 @@ class Tag | ||
| 186 | 184 | return $this; |
| 187 | 185 | } |
| 188 | 186 | |
| 187 | /** | |
| 188 | * Initialize media model. | |
| 189 | * | |
| 190 | * @param Meema\MeemaApi\Models\Media $media | |
| 191 | * | |
| 192 | * @return self | |
| 193 | */ | |
| 194 | public function setMedia($media): self | |
| 195 | { | |
| 196 | $this->model = $media; | |
| 197 | ||
| 198 | return $this; | |
| 199 | } | |
| 200 | ||
| 189 | 201 | /** |
| 190 | 202 | * Fetch child relations for this instance. |
| 191 | 203 | * |
| @@ -193,15 +205,19 @@ class Tag | ||
| 193 | 205 | */ |
| 194 | 206 | public function fetchForModel(): array |
| 195 | 207 | { |
| 208 | $data = []; | |
| 209 | ||
| 196 | 210 | switch (get_class($this->model)) { |
| 197 | 211 | case Folder::class: |
| 198 | return $this->fetchTagsForFolder($this->model->id); | |
| 212 | $data = $this->fetchTagsForFolder($this->model->getId()); | |
| 213 | break; | |
| 199 | 214 | case Media::class: |
| 200 | return $this->fetchTagsForMedia($this->model->id); | |
| 215 | $data = $this->fetchTagsForMedia($this->model->getId()); | |
| 216 | break; | |
| 201 | 217 | default: |
| 202 | return []; | |
| 218 | $data = []; | |
| 203 | 219 | } |
| 204 | 220 | |
| 205 | return []; | |
| 221 | return $data; | |
| 206 | 222 | } |
| 207 | 223 | } |