| @@ 365-396 (lines=32) @@ | ||
| 362 | /** |
|
| 363 | * @param LabelRemoved $labelRemoved |
|
| 364 | */ |
|
| 365 | private function applyLabelRemoved(LabelRemoved $labelRemoved) |
|
| 366 | { |
|
| 367 | $document = $this->repository->get($labelRemoved->getOrganizerId()); |
|
| 368 | $jsonLD = $document->getBody(); |
|
| 369 | ||
| 370 | // Don't presume that the label visibility is correct when removing. |
|
| 371 | // So iterate over both the visible and invisible labels. |
|
| 372 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 373 | ||
| 374 | foreach ($labelsProperties as $labelsProperty) { |
|
| 375 | if (isset($jsonLD->{$labelsProperty}) && is_array($jsonLD->{$labelsProperty})) { |
|
| 376 | $jsonLD->{$labelsProperty} = array_filter( |
|
| 377 | $jsonLD->{$labelsProperty}, |
|
| 378 | function ($label) use ($labelRemoved) { |
|
| 379 | return !$labelRemoved->getLabel()->equals( |
|
| 380 | new Label($label) |
|
| 381 | ); |
|
| 382 | } |
|
| 383 | ); |
|
| 384 | ||
| 385 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 386 | // as an array and not as an object. |
|
| 387 | if (count($jsonLD->{$labelsProperty}) > 0) { |
|
| 388 | $jsonLD->{$labelsProperty} = array_values($jsonLD->{$labelsProperty}); |
|
| 389 | } else { |
|
| 390 | unset($jsonLD->{$labelsProperty}); |
|
| 391 | } |
|
| 392 | } |
|
| 393 | } |
|
| 394 | ||
| 395 | return $document->withBody($jsonLD); |
|
| 396 | } |
|
| 397 | ||
| 398 | /** |
|
| 399 | * @param OrganizerDeleted $organizerDeleted |
|
| @@ 320-351 (lines=32) @@ | ||
| 317 | * @param AbstractLabelRemoved $labelRemoved |
|
| 318 | * @return JsonDocument |
|
| 319 | */ |
|
| 320 | protected function applyLabelRemoved(AbstractLabelRemoved $labelRemoved) |
|
| 321 | { |
|
| 322 | $document = $this->loadDocumentFromRepository($labelRemoved); |
|
| 323 | ||
| 324 | $offerLd = $document->getBody(); |
|
| 325 | ||
| 326 | // Don't presume that the label visibility is correct when removing. |
|
| 327 | // So iterate over both the visible and invisible labels. |
|
| 328 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 329 | ||
| 330 | foreach ($labelsProperties as $labelsProperty) { |
|
| 331 | if (isset($offerLd->{$labelsProperty}) && is_array($offerLd->{$labelsProperty})) { |
|
| 332 | $offerLd->{$labelsProperty} = array_filter( |
|
| 333 | $offerLd->{$labelsProperty}, |
|
| 334 | function ($label) use ($labelRemoved) { |
|
| 335 | return !$labelRemoved->getLabel()->equals( |
|
| 336 | new Label($label) |
|
| 337 | ); |
|
| 338 | } |
|
| 339 | ); |
|
| 340 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 341 | // as an array and not as an object. |
|
| 342 | if (count($offerLd->{$labelsProperty}) > 0) { |
|
| 343 | $offerLd->{$labelsProperty} = array_values($offerLd->{$labelsProperty}); |
|
| 344 | } else { |
|
| 345 | unset($offerLd->{$labelsProperty}); |
|
| 346 | } |
|
| 347 | } |
|
| 348 | } |
|
| 349 | ||
| 350 | return $document->withBody($offerLd); |
|
| 351 | } |
|
| 352 | ||
| 353 | /** |
|
| 354 | * Apply the imageAdded event to the item repository. |
|