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