| @@ 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 |
|
| @@ 419-450 (lines=32) @@ | ||
| 416 | * @param AbstractLabelRemoved $labelRemoved |
|
| 417 | * @return JsonDocument |
|
| 418 | */ |
|
| 419 | protected function applyLabelRemoved(AbstractLabelRemoved $labelRemoved) |
|
| 420 | { |
|
| 421 | $document = $this->loadDocumentFromRepository($labelRemoved); |
|
| 422 | ||
| 423 | $offerLd = $document->getBody(); |
|
| 424 | ||
| 425 | // Don't presume that the label visibility is correct when removing. |
|
| 426 | // So iterate over both the visible and invisible labels. |
|
| 427 | $labelsProperties = ['labels', 'hiddenLabels']; |
|
| 428 | ||
| 429 | foreach ($labelsProperties as $labelsProperty) { |
|
| 430 | if (isset($offerLd->{$labelsProperty}) && is_array($offerLd->{$labelsProperty})) { |
|
| 431 | $offerLd->{$labelsProperty} = array_filter( |
|
| 432 | $offerLd->{$labelsProperty}, |
|
| 433 | function ($label) use ($labelRemoved) { |
|
| 434 | return !$labelRemoved->getLabel()->equals( |
|
| 435 | new Label($label) |
|
| 436 | ); |
|
| 437 | } |
|
| 438 | ); |
|
| 439 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 440 | // as an array and not as an object. |
|
| 441 | if (count($offerLd->{$labelsProperty}) > 0) { |
|
| 442 | $offerLd->{$labelsProperty} = array_values($offerLd->{$labelsProperty}); |
|
| 443 | } else { |
|
| 444 | unset($offerLd->{$labelsProperty}); |
|
| 445 | } |
|
| 446 | } |
|
| 447 | } |
|
| 448 | ||
| 449 | return $document->withBody($offerLd); |
|
| 450 | } |
|
| 451 | ||
| 452 | /** |
|
| 453 | * Apply the imageAdded event to the item repository. |
|