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