| @@ 445-476 (lines=32) @@ | ||
| 442 | * @param AbstractLabelRemoved $labelRemoved |
|
| 443 | * @return JsonDocument |
|
| 444 | */ |
|
| 445 | protected function applyLabelRemoved(AbstractLabelRemoved $labelRemoved) |
|
| 446 | { |
|
| 447 | $document = $this->loadDocumentFromRepository($labelRemoved); |
|
| 448 | ||
| 449 | $offerLd = $document->getBody(); |
|
| 450 | ||
| 451 | // Don't presume that the label visibility is correct when removing. |
|
| 452 | // So iterate over both the visible and invisible labels. |
|
| 453 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 454 | ||
| 455 | foreach ($labelsProperties as $labelsProperty) { |
|
| 456 | if (isset($offerLd->{$labelsProperty}) && is_array($offerLd->{$labelsProperty})) { |
|
| 457 | $offerLd->{$labelsProperty} = array_filter( |
|
| 458 | $offerLd->{$labelsProperty}, |
|
| 459 | function ($label) use ($labelRemoved) { |
|
| 460 | return !$labelRemoved->getLabel()->equals( |
|
| 461 | new Label($label) |
|
| 462 | ); |
|
| 463 | } |
|
| 464 | ); |
|
| 465 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 466 | // as an array and not as an object. |
|
| 467 | if (count($offerLd->{$labelsProperty}) > 0) { |
|
| 468 | $offerLd->{$labelsProperty} = array_values($offerLd->{$labelsProperty}); |
|
| 469 | } else { |
|
| 470 | unset($offerLd->{$labelsProperty}); |
|
| 471 | } |
|
| 472 | } |
|
| 473 | } |
|
| 474 | ||
| 475 | return $document->withBody($offerLd); |
|
| 476 | } |
|
| 477 | ||
| 478 | /** |
|
| 479 | * Apply the imageAdded event to the item repository. |
|
| @@ 381-412 (lines=32) @@ | ||
| 378 | * @param LabelRemoved $labelRemoved |
|
| 379 | * @return JsonDocument |
|
| 380 | */ |
|
| 381 | private function applyLabelRemoved(LabelRemoved $labelRemoved) |
|
| 382 | { |
|
| 383 | $document = $this->repository->get($labelRemoved->getOrganizerId()); |
|
| 384 | $jsonLD = $document->getBody(); |
|
| 385 | ||
| 386 | // Don't presume that the label visibility is correct when removing. |
|
| 387 | // So iterate over both the visible and invisible labels. |
|
| 388 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 389 | ||
| 390 | foreach ($labelsProperties as $labelsProperty) { |
|
| 391 | if (isset($jsonLD->{$labelsProperty}) && is_array($jsonLD->{$labelsProperty})) { |
|
| 392 | $jsonLD->{$labelsProperty} = array_filter( |
|
| 393 | $jsonLD->{$labelsProperty}, |
|
| 394 | function ($label) use ($labelRemoved) { |
|
| 395 | return !$labelRemoved->getLabel()->equals( |
|
| 396 | new Label($label) |
|
| 397 | ); |
|
| 398 | } |
|
| 399 | ); |
|
| 400 | ||
| 401 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 402 | // as an array and not as an object. |
|
| 403 | if (count($jsonLD->{$labelsProperty}) > 0) { |
|
| 404 | $jsonLD->{$labelsProperty} = array_values($jsonLD->{$labelsProperty}); |
|
| 405 | } else { |
|
| 406 | unset($jsonLD->{$labelsProperty}); |
|
| 407 | } |
|
| 408 | } |
|
| 409 | } |
|
| 410 | ||
| 411 | return $document->withBody($jsonLD); |
|
| 412 | } |
|
| 413 | ||
| 414 | /** |
|
| 415 | * @param OrganizerDeleted $organizerDeleted |
|