| @@ 286-314 (lines=29) @@ | ||
| 283 | /** |
|
| 284 | * @param AbstractLabelDeleted $deleteLabel |
|
| 285 | */ |
|
| 286 | protected function applyLabelDeleted(AbstractLabelDeleted $deleteLabel) |
|
| 287 | { |
|
| 288 | $document = $this->loadDocumentFromRepository($deleteLabel); |
|
| 289 | ||
| 290 | $offerLd = $document->getBody(); |
|
| 291 | ||
| 292 | // Check the visibility of the label to update the right property. |
|
| 293 | $labelsProperty = $deleteLabel->getLabel()->isVisible() ? 'labels' : 'hiddenLabels'; |
|
| 294 | ||
| 295 | if (isset($offerLd->{$labelsProperty}) && is_array($offerLd->{$labelsProperty})) { |
|
| 296 | $offerLd->{$labelsProperty} = array_filter( |
|
| 297 | $offerLd->{$labelsProperty}, |
|
| 298 | function ($label) use ($deleteLabel) { |
|
| 299 | return !$deleteLabel->getLabel()->equals( |
|
| 300 | new Label($label) |
|
| 301 | ); |
|
| 302 | } |
|
| 303 | ); |
|
| 304 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 305 | // as an array and not as an object. |
|
| 306 | if (count($offerLd->{$labelsProperty}) > 0) { |
|
| 307 | $offerLd->{$labelsProperty} = array_values($offerLd->{$labelsProperty}); |
|
| 308 | } else { |
|
| 309 | unset($offerLd->{$labelsProperty}); |
|
| 310 | } |
|
| 311 | } |
|
| 312 | ||
| 313 | $this->repository->save($document->withBody($offerLd)); |
|
| 314 | } |
|
| 315 | ||
| 316 | /** |
|
| 317 | * Apply the imageAdded event to the item repository. |
|
| @@ 239-267 (lines=29) @@ | ||
| 236 | /** |
|
| 237 | * @param LabelRemoved $labelRemoved |
|
| 238 | */ |
|
| 239 | public function applyLabelRemoved(LabelRemoved $labelRemoved) |
|
| 240 | { |
|
| 241 | $document = $this->repository->get($labelRemoved->getOrganizerId()); |
|
| 242 | $jsonLD = $document->getBody(); |
|
| 243 | ||
| 244 | // Check the visibility of the label to update the right property. |
|
| 245 | $labelsProperty = $labelRemoved->getLabel()->isVisible() ? 'labels' : 'hiddenLabels'; |
|
| 246 | ||
| 247 | if (isset($jsonLD->{$labelsProperty}) && is_array($jsonLD->{$labelsProperty})) { |
|
| 248 | $jsonLD->{$labelsProperty} = array_filter( |
|
| 249 | $jsonLD->{$labelsProperty}, |
|
| 250 | function ($label) use ($labelRemoved) { |
|
| 251 | return !$labelRemoved->getLabel()->equals( |
|
| 252 | new Label($label) |
|
| 253 | ); |
|
| 254 | } |
|
| 255 | ); |
|
| 256 | ||
| 257 | // Ensure array keys start with 0 so json_encode() does encode it |
|
| 258 | // as an array and not as an object. |
|
| 259 | if (count($jsonLD->{$labelsProperty}) > 0) { |
|
| 260 | $jsonLD->{$labelsProperty} = array_values($jsonLD->{$labelsProperty}); |
|
| 261 | } else { |
|
| 262 | unset($jsonLD->{$labelsProperty}); |
|
| 263 | } |
|
| 264 | ||
| 265 | $this->repository->save($document->withBody($jsonLD)); |
|
| 266 | } |
|
| 267 | } |
|
| 268 | ||
| 269 | /** |
|
| 270 | * @param OrganizerDeleted $organizerDeleted |
|