| @@ 281-312 (lines=32) @@ | ||
| 278 | /** |
|
| 279 | * @param AbstractLabelRemoved $labelRemoved |
|
| 280 | */ |
|
| 281 | protected function applyLabelRemoved(AbstractLabelRemoved $labelRemoved) |
|
| 282 | { |
|
| 283 | $document = $this->loadDocumentFromRepository($labelRemoved); |
|
| 284 | ||
| 285 | $offerLd = $document->getBody(); |
|
| 286 | ||
| 287 | // Don't presume that the label visibility is correct when removing. |
|
| 288 | // So iterate over both the visible and invisible labels. |
|
| 289 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 290 | ||
| 291 | foreach ($labelsProperties as $labelsProperty) { |
|
| 292 | if (isset($offerLd->{$labelsProperty}) && is_array($offerLd->{$labelsProperty})) { |
|
| 293 | $offerLd->{$labelsProperty} = array_filter( |
|
| 294 | $offerLd->{$labelsProperty}, |
|
| 295 | function ($label) use ($labelRemoved) { |
|
| 296 | return !$labelRemoved->getLabel()->equals( |
|
| 297 | new Label($label) |
|
| 298 | ); |
|
| 299 | } |
|
| 300 | ); |
|
| 301 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 302 | // as an array and not as an object. |
|
| 303 | if (count($offerLd->{$labelsProperty}) > 0) { |
|
| 304 | $offerLd->{$labelsProperty} = array_values($offerLd->{$labelsProperty}); |
|
| 305 | } else { |
|
| 306 | unset($offerLd->{$labelsProperty}); |
|
| 307 | } |
|
| 308 | } |
|
| 309 | } |
|
| 310 | ||
| 311 | $this->repository->save($document->withBody($offerLd)); |
|
| 312 | } |
|
| 313 | ||
| 314 | /** |
|
| 315 | * Apply the imageAdded event to the item repository. |
|
| @@ 299-331 (lines=33) @@ | ||
| 296 | /** |
|
| 297 | * @param LabelRemoved $labelRemoved |
|
| 298 | */ |
|
| 299 | private function applyLabelRemoved(LabelRemoved $labelRemoved) |
|
| 300 | { |
|
| 301 | $document = $this->repository->get($labelRemoved->getOrganizerId()); |
|
| 302 | $jsonLD = $document->getBody(); |
|
| 303 | ||
| 304 | // Don't presume that the label visibility is correct when removing. |
|
| 305 | // So iterate over both the visible and invisible labels. |
|
| 306 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 307 | ||
| 308 | foreach ($labelsProperties as $labelsProperty) { |
|
| 309 | if (isset($jsonLD->{$labelsProperty}) && is_array($jsonLD->{$labelsProperty})) { |
|
| 310 | $jsonLD->{$labelsProperty} = array_filter( |
|
| 311 | $jsonLD->{$labelsProperty}, |
|
| 312 | function ($label) use ($labelRemoved) { |
|
| 313 | return !$labelRemoved->getLabel()->equals( |
|
| 314 | new Label($label) |
|
| 315 | ); |
|
| 316 | } |
|
| 317 | ); |
|
| 318 | ||
| 319 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 320 | // as an array and not as an object. |
|
| 321 | if (count($jsonLD->{$labelsProperty}) > 0) { |
|
| 322 | $jsonLD->{$labelsProperty} = array_values($jsonLD->{$labelsProperty}); |
|
| 323 | } else { |
|
| 324 | unset($jsonLD->{$labelsProperty}); |
|
| 325 | } |
|
| 326 | } |
|
| 327 | } |
|
| 328 | ||
| 329 | $this->repository->save($document->withBody($jsonLD)); |
|
| 330 | } |
|
| 331 | ||
| 332 | /** |
|
| 333 | * @param OrganizerDeleted $organizerDeleted |
|
| 334 | */ |
|