| @@ 239-271 (lines=33) @@ | ||
| 236 | /** |
|
| 237 | * @param LabelRemoved $labelRemoved |
|
| 238 | */ |
|
| 239 | public function applyLabelRemoved(LabelRemoved $labelRemoved) |
|
| 240 | { |
|
| 241 | $document = $this->repository->get($labelRemoved->getOrganizerId()); |
|
| 242 | $jsonLD = $document->getBody(); |
|
| 243 | ||
| 244 | // Don't presume that the label visibility is correct when removing. |
|
| 245 | // So iterate over both the visible and invisible labels. |
|
| 246 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 247 | ||
| 248 | foreach ($labelsProperties as $labelsProperty) { |
|
| 249 | if (isset($jsonLD->{$labelsProperty}) && is_array($jsonLD->{$labelsProperty})) { |
|
| 250 | $jsonLD->{$labelsProperty} = array_filter( |
|
| 251 | $jsonLD->{$labelsProperty}, |
|
| 252 | function ($label) use ($labelRemoved) { |
|
| 253 | return !$labelRemoved->getLabel()->equals( |
|
| 254 | new Label($label) |
|
| 255 | ); |
|
| 256 | } |
|
| 257 | ); |
|
| 258 | ||
| 259 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 260 | // as an array and not as an object. |
|
| 261 | if (count($jsonLD->{$labelsProperty}) > 0) { |
|
| 262 | $jsonLD->{$labelsProperty} = array_values($jsonLD->{$labelsProperty}); |
|
| 263 | } else { |
|
| 264 | unset($jsonLD->{$labelsProperty}); |
|
| 265 | } |
|
| 266 | } |
|
| 267 | } |
|
| 268 | ||
| 269 | $this->repository->save($document->withBody($jsonLD)); |
|
| 270 | } |
|
| 271 | ||
| 272 | /** |
|
| 273 | * @param OrganizerDeleted $organizerDeleted |
|
| 274 | */ |
|
| @@ 290-321 (lines=32) @@ | ||
| 287 | /** |
|
| 288 | * @param AbstractLabelRemoved $labelRemoved |
|
| 289 | */ |
|
| 290 | protected function applyLabelRemoved(AbstractLabelRemoved $labelRemoved) |
|
| 291 | { |
|
| 292 | $document = $this->loadDocumentFromRepository($labelRemoved); |
|
| 293 | ||
| 294 | $offerLd = $document->getBody(); |
|
| 295 | ||
| 296 | // Don't presume that the label visibility is correct when removing. |
|
| 297 | // So iterate over both the visible and invisible labels. |
|
| 298 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 299 | ||
| 300 | foreach ($labelsProperties as $labelsProperty) { |
|
| 301 | if (isset($offerLd->{$labelsProperty}) && is_array($offerLd->{$labelsProperty})) { |
|
| 302 | $offerLd->{$labelsProperty} = array_filter( |
|
| 303 | $offerLd->{$labelsProperty}, |
|
| 304 | function ($label) use ($labelRemoved) { |
|
| 305 | return !$labelRemoved->getLabel()->equals( |
|
| 306 | new Label($label) |
|
| 307 | ); |
|
| 308 | } |
|
| 309 | ); |
|
| 310 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 311 | // as an array and not as an object. |
|
| 312 | if (count($offerLd->{$labelsProperty}) > 0) { |
|
| 313 | $offerLd->{$labelsProperty} = array_values($offerLd->{$labelsProperty}); |
|
| 314 | } else { |
|
| 315 | unset($offerLd->{$labelsProperty}); |
|
| 316 | } |
|
| 317 | } |
|
| 318 | } |
|
| 319 | ||
| 320 | $this->repository->save($document->withBody($offerLd)); |
|
| 321 | } |
|
| 322 | ||
| 323 | /** |
|
| 324 | * Apply the imageAdded event to the item repository. |
|