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