Completed
Pull Request — master (#340)
by Luc
05:12
created

Offer::updateGeoCoordinates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Offer;
4
5
use Broadway\EventSourcing\EventSourcedAggregateRoot;
6
use CultureFeed_Cdb_Item_Base;
7
use CultuurNet\Geocoding\Coordinate\Coordinates;
8
use CultuurNet\UDB3\BookingInfo;
9
use CultuurNet\UDB3\Calendar;
10
use CultuurNet\UDB3\ContactPoint;
11
use CultuurNet\UDB3\Description;
12
use CultuurNet\UDB3\Event\EventType;
13
use CultuurNet\UDB3\Label;
14
use CultuurNet\UDB3\LabelAwareAggregateRoot;
15
use CultuurNet\UDB3\LabelCollection;
16
use CultuurNet\UDB3\Media\Image;
17
use CultuurNet\UDB3\Media\ImageCollection;
18
use CultuurNet\UDB3\Offer\Commands\Image\AbstractUpdateImage;
19
use CultuurNet\UDB3\Language;
20
use CultuurNet\UDB3\Offer\Events\AbstractBookingInfoUpdated;
21
use CultuurNet\UDB3\Offer\Events\AbstractContactPointUpdated;
22
use CultuurNet\UDB3\Offer\Events\AbstractFacilitiesUpdated;
23
use CultuurNet\UDB3\Offer\Events\AbstractGeoCoordinatesUpdated;
24
use CultuurNet\UDB3\Offer\Events\AbstractThemeUpdated;
25
use CultuurNet\UDB3\Offer\Events\AbstractTitleTranslated;
26
use CultuurNet\UDB3\Offer\Events\AbstractTitleUpdated;
27
use CultuurNet\UDB3\Offer\Events\AbstractDescriptionTranslated;
28
use CultuurNet\UDB3\Offer\Events\AbstractDescriptionUpdated;
29
use CultuurNet\UDB3\Offer\Events\AbstractLabelAdded;
30
use CultuurNet\UDB3\Offer\Events\AbstractLabelRemoved;
31
use CultuurNet\UDB3\Offer\Events\AbstractOfferDeleted;
32
use CultuurNet\UDB3\Offer\Events\AbstractOrganizerDeleted;
33
use CultuurNet\UDB3\Offer\Events\AbstractOrganizerUpdated;
34
use CultuurNet\UDB3\Offer\Events\AbstractPriceInfoUpdated;
35
use CultuurNet\UDB3\Offer\Events\AbstractTypeUpdated;
36
use CultuurNet\UDB3\Offer\Events\AbstractTypicalAgeRangeDeleted;
37
use CultuurNet\UDB3\Offer\Events\AbstractTypicalAgeRangeUpdated;
38
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageAdded;
39
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageRemoved;
40
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesEvent;
41
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesImportedFromUDB2;
42
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesUpdatedFromUDB2;
43
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageUpdated;
44
use CultuurNet\UDB3\Offer\Events\Image\AbstractMainImageSelected;
45
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractApproved;
46
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractFlaggedAsDuplicate;
47
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractFlaggedAsInappropriate;
48
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractPublished;
49
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractRejected;
50
use CultuurNet\UDB3\PriceInfo\PriceInfo;
51
use CultuurNet\UDB3\Theme;
52
use CultuurNet\UDB3\Title;
53
use Exception;
54
use ValueObjects\Identity\UUID;
55
use ValueObjects\StringLiteral\StringLiteral;
56
57
abstract class Offer extends EventSourcedAggregateRoot implements LabelAwareAggregateRoot
58
{
59
    const DUPLICATE_REASON = 'duplicate';
60
    const INAPPROPRIATE_REASON = 'inappropriate';
61
62
    /**
63
     * @var LabelCollection
64
     */
65
    protected $labels;
66
67
    /**
68
     * @var ImageCollection
69
     */
70
    protected $images;
71
72
    /**
73
     * @var string
74
     *
75
     * Organizer ids can come from UDB2 which does not strictly use UUIDs.
76
     */
77
    protected $organizerId;
78
79
    /**
80
     * @var WorkflowStatus
81
     */
82
    protected $workflowStatus;
83
84
    /**
85
     * @var StringLiteral|null
86
     */
87
    protected $rejectedReason;
88
89
    /**
90
     * @var PriceInfo
91
     */
92
    protected $priceInfo;
93
94
    /**
95
     * @var StringLiteral[]
96
     */
97
    protected $titles;
98
99
    /**
100
     * @var Description[]
101
     */
102
    protected $descriptions;
103
104
    /**
105
     * @var Language
106
     */
107
    protected $mainLanguage;
108
109
    /**
110
     * @var string;
111
     */
112
    protected $typeId;
113
114
    /**
115
     * @var string;
116
     */
117
    protected $themeId;
118
119
    /**
120
     * Offer constructor.
121
     */
122
    public function __construct()
123
    {
124
        // For now the main language is hard coded on nl.
125
        // In the future it should be set on create.
126
        $this->mainLanguage = new Language('nl');
127
128
        $this->titles = [];
129
        $this->descriptions = [];
130
        $this->labels = new LabelCollection();
131
        $this->images = new ImageCollection();
132
    }
133
134
    /**
135
     * @param EventType $type
136
     */
137
    public function updateType(EventType $type)
138
    {
139
        if (!$this->typeId || $this->typeId !== $type->getId()) {
140
            $this->apply($this->createTypeUpdatedEvent($type));
141
        }
142
    }
143
144
    /**
145
     * @param Theme $theme
146
     */
147
    public function updateTheme(Theme $theme)
148
    {
149
        if (!$this->themeId || $this->themeId !== $theme->getId()) {
150
            $this->apply($this->createThemeUpdatedEvent($theme));
151
        }
152
    }
153
154
    /**
155
     * @param array $facilities
156
     */
157
    public function updateFacilities(array $facilities)
158
    {
159
        $this->apply($this->createFacilitiesUpdatedEvent($facilities));
160
    }
161
162
    /**
163
     * Get the id of the main image if one is selected for this offer.
164
     *
165
     * @return UUID|null
166
     */
167
    protected function getMainImageId()
168
    {
169
        $mainImage = $this->images->getMain();
170
        return isset($mainImage) ? $mainImage->getMediaObjectId() : null;
171
    }
172
173
    /**
174
     * @inheritdoc
175
     */
176
    public function addLabel(Label $label)
177
    {
178
        if (!$this->labels->contains($label)) {
179
            $this->apply(
180
                $this->createLabelAddedEvent($label)
181
            );
182
        }
183
    }
184
185
    /**
186
     * @inheritdoc
187
     */
188
    public function removeLabel(Label $label)
189
    {
190
        if ($this->labels->contains($label)) {
191
            $this->apply(
192
                $this->createLabelRemovedEvent($label)
193
            );
194
        }
195
    }
196
197
    /**
198
     * @param Language $language
199
     * @param Title $title
200
     */
201
    public function updateTitle(Language $language, Title $title)
202
    {
203
        if ($this->isTitleChanged($title, $language)) {
204
            if ($language->getCode() !== $this->mainLanguage->getCode()) {
205
                $event = $this->createTitleTranslatedEvent($language, $title);
206
            } else {
207
                $event = $this->createTitleUpdatedEvent($title);
208
            }
209
210
            $this->apply($event);
211
        }
212
    }
213
214
    /**
215
     * @param Description $description
216
     * @param Language $language
217
     */
218
    public function updateDescription(Description $description, Language $language)
219
    {
220
        if ($this->isDescriptionChanged($description, $language)) {
221
            if ($language->getCode() !== $this->mainLanguage->getCode()) {
222
                $event = $this->createDescriptionTranslatedEvent($language, $description);
223
            } else {
224
                $event = $this->createDescriptionUpdatedEvent((string) $description);
225
            }
226
227
            $this->apply($event);
228
        }
229
    }
230
231
    /**
232
     * @param Calendar $calendar
233
     */
234
    public function updateCalendar(Calendar $calendar)
235
    {
236
        // For now no special business rules for updating the calendar.
237
        $this->apply(
238
            $this->createCalendarUpdatedEvent($calendar)
239
        );
240
    }
241
242
    /**
243
     * @param string $typicalAgeRange
244
     */
245
    public function updateTypicalAgeRange($typicalAgeRange)
246
    {
247
        $this->apply(
248
            $this->createTypicalAgeRangeUpdatedEvent($typicalAgeRange)
249
        );
250
    }
251
252
    public function deleteTypicalAgeRange()
253
    {
254
        $this->apply(
255
            $this->createTypicalAgeRangeDeletedEvent()
256
        );
257
    }
258
259
    /**
260
     * @param string $organizerId
261
     */
262
    public function updateOrganizer($organizerId)
263
    {
264
        if ($this->organizerId !== $organizerId) {
265
            $this->apply(
266
                $this->createOrganizerUpdatedEvent($organizerId)
267
            );
268
        }
269
    }
270
271
    /**
272
     * Delete the given organizer.
273
     *
274
     * @param string $organizerId
275
     */
276
    public function deleteOrganizer($organizerId)
277
    {
278
        if ($this->organizerId === $organizerId) {
279
            $this->apply(
280
                $this->createOrganizerDeletedEvent($organizerId)
281
            );
282
        }
283
    }
284
285
    /**
286
     * Updated the contact info.
287
     * @param ContactPoint $contactPoint
288
     */
289
    public function updateContactPoint(ContactPoint $contactPoint)
290
    {
291
        $this->apply(
292
            $this->createContactPointUpdatedEvent($contactPoint)
293
        );
294
    }
295
296
    /**
297
     * @param Coordinates $coordinates
298
     */
299
    public function updateGeoCoordinates(Coordinates $coordinates)
300
    {
301
        // Note: DON'T compare to previous coordinates and apply only on
302
        // changes. Various projectors expect GeoCoordinatesUpdated after
303
        // MajorInfoUpdated and PlaceUpdatedFromUDB2, even if the address
304
        // and thus the coordinates haven't actually changed.
305
        $this->apply(
306
            $this->createGeoCoordinatesUpdatedEvent($coordinates)
307
        );
308
    }
309
310
    /**
311
     * Updated the booking info.
312
     *
313
     * @param BookingInfo $bookingInfo
314
     */
315
    public function updateBookingInfo(BookingInfo $bookingInfo)
316
    {
317
        $this->apply(
318
            $this->createBookingInfoUpdatedEvent($bookingInfo)
319
        );
320
    }
321
322
    /**
323
     * @param PriceInfo $priceInfo
324
     */
325
    public function updatePriceInfo(PriceInfo $priceInfo)
326
    {
327
        if (is_null($this->priceInfo) || $priceInfo->serialize() !== $this->priceInfo->serialize()) {
328
            $this->apply(
329
                $this->createPriceInfoUpdatedEvent($priceInfo)
330
            );
331
        }
332
    }
333
334
    /**
335
     * @param AbstractPriceInfoUpdated $priceInfoUpdated
336
     */
337
    protected function applyPriceInfoUpdated(AbstractPriceInfoUpdated $priceInfoUpdated)
338
    {
339
        $this->priceInfo = $priceInfoUpdated->getPriceInfo();
340
    }
341
342
    /**
343
     * @param AbstractLabelAdded $labelAdded
344
     */
345
    protected function applyLabelAdded(AbstractLabelAdded $labelAdded)
346
    {
347
        $this->labels = $this->labels->with($labelAdded->getLabel());
348
    }
349
350
    /**
351
     * @param AbstractLabelRemoved $labelRemoved
352
     */
353
    protected function applyLabelRemoved(AbstractLabelRemoved $labelRemoved)
354
    {
355
        $this->labels = $this->labels->without($labelRemoved->getLabel());
356
    }
357
358
    /**
359
     * @param AbstractThemeUpdated $themeUpdated
360
     */
361
    protected function applyThemeUpdated(AbstractThemeUpdated $themeUpdated)
362
    {
363
        $this->themeId = $themeUpdated->getTheme()->getId();
364
    }
365
366
    /**
367
     * @param AbstractTypeUpdated $themeUpdated
368
     */
369
    protected function applyTypeUpdated(AbstractTypeUpdated $themeUpdated)
370
    {
371
        $this->typeId = $themeUpdated->getType()->getId();
372
    }
373
374
    protected function applyDescriptionUpdated(AbstractDescriptionUpdated $descriptionUpdated)
375
    {
376
        $mainLanguageCode = $this->mainLanguage->getCode();
377
        $this->descriptions[$mainLanguageCode] = new Description($descriptionUpdated->getDescription());
378
    }
379
380
    protected function applyDescriptionTranslated(AbstractDescriptionTranslated $descriptionTranslated)
381
    {
382
        $languageCode = $descriptionTranslated->getLanguage()->getCode();
383
        $this->descriptions[$languageCode] = $descriptionTranslated->getDescription();
384
    }
385
386
    /**
387
     * Add a new image.
388
     *
389
     * @param Image $image
390
     */
391
    public function addImage(Image $image)
392
    {
393
        if (!$this->images->contains($image)) {
394
            $this->apply(
395
                $this->createImageAddedEvent($image)
396
            );
397
        }
398
    }
399
400
    /**
401
     * @param AbstractUpdateImage $updateImageCommand
402
     */
403
    public function updateImage(AbstractUpdateImage $updateImageCommand)
404
    {
405
        if ($this->images->findImageByUUID($updateImageCommand->getMediaObjectId())) {
406
            $this->apply(
407
                $this->createImageUpdatedEvent($updateImageCommand)
408
            );
409
        }
410
    }
411
412
    /**
413
     * Remove an image.
414
     *
415
     * @param Image $image
416
     */
417
    public function removeImage(Image $image)
418
    {
419
        if ($this->images->contains($image)) {
420
            $this->apply(
421
                $this->createImageRemovedEvent($image)
422
            );
423
        }
424
    }
425
426
    /**
427
     * Make an existing image of the item the main image.
428
     *
429
     * @param Image $image
430
     */
431
    public function selectMainImage(Image $image)
432
    {
433
        if (!$this->images->contains($image)) {
434
            throw new \InvalidArgumentException('You can not select a random image to be main, it has to be added to the item.');
435
        }
436
437
        $oldMainImage = $this->images->getMain();
438
439
        if (!isset($oldMainImage) || $oldMainImage->getMediaObjectId() !== $image->getMediaObjectId()) {
440
            $this->apply(
441
                $this->createMainImageSelectedEvent($image)
442
            );
443
        }
444
    }
445
446
    /**
447
     * Delete the offer.
448
     */
449
    public function delete()
450
    {
451
        $this->apply(
452
            $this->createOfferDeletedEvent()
453
        );
454
    }
455
456
    /**
457
     * @param CultureFeed_Cdb_Item_Base $cdbItem
458
     */
459
    protected function importWorkflowStatus(CultureFeed_Cdb_Item_Base $cdbItem)
460
    {
461
        try {
462
            $workflowStatus = WorkflowStatus::fromNative($cdbItem->getWfStatus());
463
        } catch (\InvalidArgumentException $exception) {
464
            $workflowStatus = WorkflowStatus::READY_FOR_VALIDATION();
465
        }
466
        $this->workflowStatus = $workflowStatus;
467
    }
468
469
    /**
470
     * Publish the offer when it has workflowstatus draft.
471
     * @param \DateTimeInterface $publicationDate
472
     */
473
    public function publish(\DateTimeInterface $publicationDate)
474
    {
475
        $this->guardPublish() ?: $this->apply(
476
            $this->createPublishedEvent($publicationDate)
477
        );
478
    }
479
480
    /**
481
     * @return bool
482
     * @throws Exception
483
     */
484 View Code Duplication
    private function guardPublish()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
485
    {
486
        if ($this->workflowStatus === WorkflowStatus::READY_FOR_VALIDATION()) {
487
            return true; // nothing left to do if the offer has already been published
488
        }
489
490
        if ($this->workflowStatus !== WorkflowStatus::DRAFT()) {
491
            throw new Exception('You can not publish an offer that is not draft');
492
        }
493
494
        return false;
495
    }
496
497
    /**
498
     * Approve the offer when it's waiting for validation.
499
     */
500
    public function approve()
501
    {
502
        $this->guardApprove() ?: $this->apply($this->createApprovedEvent());
503
    }
504
505
    /**
506
     * @return bool
507
     * @throws Exception
508
     */
509 View Code Duplication
    private function guardApprove()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
510
    {
511
        if ($this->workflowStatus === WorkflowStatus::APPROVED()) {
512
            return true; // nothing left to do if the offer has already been approved
513
        }
514
515
        if ($this->workflowStatus !== WorkflowStatus::READY_FOR_VALIDATION()) {
516
            throw new Exception('You can not approve an offer that is not ready for validation');
517
        }
518
519
        return false;
520
    }
521
522
    /**
523
     * Reject an offer that is waiting for validation with a given reason.
524
     * @param StringLiteral $reason
525
     */
526
    public function reject(StringLiteral $reason)
527
    {
528
        $this->guardRejection($reason) ?: $this->apply($this->createRejectedEvent($reason));
529
    }
530
531
    public function flagAsDuplicate()
532
    {
533
        $reason = new StringLiteral(self::DUPLICATE_REASON);
534
        $this->guardRejection($reason) ?: $this->apply($this->createFlaggedAsDuplicate());
535
    }
536
537
    public function flagAsInappropriate()
538
    {
539
        $reason = new StringLiteral(self::INAPPROPRIATE_REASON);
540
        $this->guardRejection($reason) ?: $this->apply($this->createFlaggedAsInappropriate());
541
    }
542
543
    /**
544
     * @param StringLiteral $reason
545
     * @return bool
546
     *  false when the offer can still be rejected, true when the offer is already rejected for the same reason
547
     * @throws Exception
548
     */
549
    private function guardRejection(StringLiteral $reason)
550
    {
551
        if ($this->workflowStatus === WorkflowStatus::REJECTED()) {
552
            if ($this->rejectedReason && $reason->sameValueAs($this->rejectedReason)) {
553
                return true; // nothing left to do if the offer has already been rejected for the same reason
554
            } else {
555
                throw new Exception('The offer has already been rejected for another reason: ' . $this->rejectedReason);
556
            }
557
        }
558
559
        if ($this->workflowStatus !== WorkflowStatus::READY_FOR_VALIDATION()) {
560
            throw new Exception('You can not reject an offer that is not ready for validation');
561
        }
562
563
        return false;
564
    }
565
566
    /**
567
     * @param Title $title
568
     * @param Language $language
569
     * @return bool
570
     */
571 View Code Duplication
    private function isTitleChanged(Title $title, Language $language)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
572
    {
573
        $languageCode = $language->getCode();
574
575
        return !isset($this->titles[$languageCode]) ||
576
            !$title->sameValueAs($this->titles[$languageCode]);
577
    }
578
579
    /**
580
     * @param Description $description
581
     * @param Language $language
582
     * @return bool
583
     */
584 View Code Duplication
    private function isDescriptionChanged(Description $description, Language $language)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
585
    {
586
        $languageCode = $language->getCode();
587
588
        return !isset($this->descriptions[$languageCode]) ||
589
            !$description->sameValueAs($this->descriptions[$languageCode]);
590
    }
591
592
    /**
593
     * Overwrites or resets the main image and all media objects
594
     * by importing a new collection of images from UDB2.
595
     *
596
     * @param ImageCollection $images
597
     */
598
    public function importImagesFromUDB2(ImageCollection $images)
599
    {
600
        $this->apply($this->createImagesImportedFromUDB2($images));
601
    }
602
603
    /**
604
     * Overwrites or resets the main image and all media objects
605
     * by updating with a new collection of images from UDB2.
606
     *
607
     * @param ImageCollection $images
608
     */
609
    public function updateImagesFromUDB2(ImageCollection $images)
610
    {
611
        $this->apply($this->createImagesUpdatedFromUDB2($images));
612
    }
613
614
    /**
615
     * @param AbstractPublished $published
616
     */
617
    protected function applyPublished(AbstractPublished $published)
0 ignored issues
show
Unused Code introduced by
The parameter $published is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
618
    {
619
        $this->workflowStatus = WorkflowStatus::READY_FOR_VALIDATION();
620
    }
621
622
    /**
623
     * @param AbstractApproved $approved
624
     */
625
    protected function applyApproved(AbstractApproved $approved)
0 ignored issues
show
Unused Code introduced by
The parameter $approved is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
626
    {
627
        $this->workflowStatus = WorkflowStatus::APPROVED();
628
    }
629
630
    /**
631
     * @param AbstractRejected $rejected
632
     */
633
    protected function applyRejected(AbstractRejected $rejected)
634
    {
635
        $this->rejectedReason = $rejected->getReason();
636
        $this->workflowStatus = WorkflowStatus::REJECTED();
637
    }
638
639
    /**
640
     * @param AbstractFlaggedAsDuplicate $flaggedAsDuplicate
641
     */
642
    protected function applyFlaggedAsDuplicate(AbstractFlaggedAsDuplicate $flaggedAsDuplicate)
0 ignored issues
show
Unused Code introduced by
The parameter $flaggedAsDuplicate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
643
    {
644
        $this->rejectedReason = new StringLiteral(self::DUPLICATE_REASON);
645
        $this->workflowStatus = WorkflowStatus::REJECTED();
646
    }
647
648
    /**
649
     * @param AbstractFlaggedAsInappropriate $flaggedAsInappropriate
650
     */
651
    protected function applyFlaggedAsInappropriate(AbstractFlaggedAsInappropriate $flaggedAsInappropriate)
0 ignored issues
show
Unused Code introduced by
The parameter $flaggedAsInappropriate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
652
    {
653
        $this->rejectedReason = new StringLiteral(self::INAPPROPRIATE_REASON);
654
        $this->workflowStatus = WorkflowStatus::REJECTED();
655
    }
656
657
    protected function applyImageAdded(AbstractImageAdded $imageAdded)
658
    {
659
        $this->images = $this->images->with($imageAdded->getImage());
660
    }
661
662
    protected function applyImageRemoved(AbstractImageRemoved $imageRemoved)
663
    {
664
        $this->images = $this->images->without($imageRemoved->getImage());
665
    }
666
667
    protected function applyMainImageSelected(AbstractMainImageSelected $mainImageSelected)
668
    {
669
        $this->images = $this->images->withMain($mainImageSelected->getImage());
670
    }
671
672
    protected function applyOrganizerUpdated(AbstractOrganizerUpdated $organizerUpdated)
673
    {
674
        $this->organizerId = $organizerUpdated->getOrganizerId();
675
    }
676
677
    protected function applyOrganizerDeleted(AbstractOrganizerDeleted $organizerDeleted)
0 ignored issues
show
Unused Code introduced by
The parameter $organizerDeleted is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
678
    {
679
        $this->organizerId = null;
680
    }
681
682
    /**
683
     * @param AbstractImagesImportedFromUDB2 $imagesImportedFromUDB2
684
     */
685
    protected function applyImagesImportedFromUDB2(AbstractImagesImportedFromUDB2 $imagesImportedFromUDB2)
686
    {
687
        $this->applyUdb2ImagesEvent($imagesImportedFromUDB2);
688
    }
689
690
    /**
691
     * @param AbstractImagesUpdatedFromUDB2 $imagesUpdatedFromUDB2
692
     */
693
    protected function applyImagesUpdatedFromUDB2(AbstractImagesUpdatedFromUDB2 $imagesUpdatedFromUDB2)
694
    {
695
        $this->applyUdb2ImagesEvent($imagesUpdatedFromUDB2);
696
    }
697
698
    /**
699
     * This indirect apply method can be called internally to deal with images coming from UDB2.
700
     * Imports from UDB2 only contain the native Dutch content.
701
     * @see https://github.com/cultuurnet/udb3-udb2-bridge/blob/db0a7ab2444f55bb3faae3d59b82b39aaeba253b/test/Media/ImageCollectionFactoryTest.php#L79-L103
702
     * Because of this we have to make sure translated images are left in place.
703
     *
704
     * @param AbstractImagesEvent $imagesEvent
705
     */
706
    protected function applyUdb2ImagesEvent(AbstractImagesEvent $imagesEvent)
707
    {
708
        $newMainImage = $imagesEvent->getImages()->getMain();
709
        $dutchImagesList = $imagesEvent->getImages()->toArray();
710
        $translatedImagesList = array_filter(
711
            $this->images->toArray(),
712
            function (Image $image) {
713
                return $image->getLanguage()->getCode() !== 'nl';
714
            }
715
        );
716
717
        $imagesList = array_merge($dutchImagesList, $translatedImagesList);
718
        $images = ImageCollection::fromArray($imagesList);
719
720
        $this->images = isset($newMainImage) ? $images->withMain($newMainImage) : $images;
721
    }
722
723
    /**
724
     * @param Label $label
725
     * @return AbstractLabelAdded
726
     */
727
    abstract protected function createLabelAddedEvent(Label $label);
728
729
    /**
730
     * @param Label $label
731
     * @return AbstractLabelRemoved
732
     */
733
    abstract protected function createLabelRemovedEvent(Label $label);
734
735
    /**
736
     * @param Language $language
737
     * @param StringLiteral $title
738
     * @return AbstractTitleTranslated
739
     */
740
    abstract protected function createTitleTranslatedEvent(Language $language, StringLiteral $title);
741
742
    /**
743
     * @param Language $language
744
     * @param StringLiteral $description
745
     * @return AbstractDescriptionTranslated
746
     */
747
    abstract protected function createDescriptionTranslatedEvent(Language $language, StringLiteral $description);
748
749
    /**
750
     * @param Image $image
751
     * @return AbstractImageAdded
752
     */
753
    abstract protected function createImageAddedEvent(Image $image);
754
755
    /**
756
     * @param Image $image
757
     * @return AbstractImageRemoved
758
     */
759
    abstract protected function createImageRemovedEvent(Image $image);
760
761
    /**
762
     * @param AbstractUpdateImage $updateImageCommand
763
     * @return AbstractImageUpdated
764
     */
765
    abstract protected function createImageUpdatedEvent(
766
        AbstractUpdateImage $updateImageCommand
767
    );
768
769
    /**
770
     * @param Image $image
771
     * @return AbstractMainImageSelected
772
     */
773
    abstract protected function createMainImageSelectedEvent(Image $image);
774
775
    /**
776
     * @return AbstractOfferDeleted
777
     */
778
    abstract protected function createOfferDeletedEvent();
779
780
    /**
781
     * @param Title $title
782
     * @return AbstractTitleUpdated
783
     */
784
    abstract protected function createTitleUpdatedEvent(Title $title);
785
786
    /**
787
     * @param string $description
788
     * @return AbstractDescriptionUpdated
789
     */
790
    abstract protected function createDescriptionUpdatedEvent($description);
791
792
    /**
793
     * @param Calendar $calendar
794
     * @return AbstractCalendarUpdated
795
     */
796
    abstract protected function createCalendarUpdatedEvent(Calendar $calendar);
797
798
    /**
799
     * @param string $typicalAgeRange
800
     * @return AbstractTypicalAgeRangeUpdated
801
     */
802
    abstract protected function createTypicalAgeRangeUpdatedEvent($typicalAgeRange);
803
804
    /**
805
     * @return AbstractTypicalAgeRangeDeleted
806
     */
807
    abstract protected function createTypicalAgeRangeDeletedEvent();
808
809
    /**
810
     * @param string $organizerId
811
     * @return AbstractOrganizerUpdated
812
     */
813
    abstract protected function createOrganizerUpdatedEvent($organizerId);
814
815
    /**
816
     * @param string $organizerId
817
     * @return AbstractOrganizerDeleted
818
     */
819
    abstract protected function createOrganizerDeletedEvent($organizerId);
820
821
    /**
822
     * @param ContactPoint $contactPoint
823
     * @return AbstractContactPointUpdated
824
     */
825
    abstract protected function createContactPointUpdatedEvent(ContactPoint $contactPoint);
826
827
    /**
828
     * @param Coordinates $coordinates
829
     * @return AbstractGeoCoordinatesUpdated
830
     */
831
    abstract protected function createGeoCoordinatesUpdatedEvent(Coordinates $coordinates);
832
833
    /**
834
     * @param BookingInfo $bookingInfo
835
     * @return AbstractBookingInfoUpdated
836
     */
837
    abstract protected function createBookingInfoUpdatedEvent(BookingInfo $bookingInfo);
838
839
    /**
840
     * @param PriceInfo $priceInfo
841
     * @return AbstractPriceInfoUpdated
842
     */
843
    abstract protected function createPriceInfoUpdatedEvent(PriceInfo $priceInfo);
844
845
    /**
846
     * @param \DateTimeInterface $publicationDate
847
     * @return AbstractPublished
848
     */
849
    abstract protected function createPublishedEvent(\DateTimeInterface $publicationDate);
850
851
    /**
852
     * @return AbstractApproved
853
     */
854
    abstract protected function createApprovedEvent();
855
856
    /**
857
     * @param StringLiteral $reason
858
     * @return AbstractRejected
859
     */
860
    abstract protected function createRejectedEvent(StringLiteral $reason);
861
862
    /**
863
     * @return AbstractFlaggedAsDuplicate
864
     */
865
    abstract protected function createFlaggedAsDuplicate();
866
867
    /**
868
     * @return AbstractFlaggedAsInappropriate
869
     */
870
    abstract protected function createFlaggedAsInappropriate();
871
872
    /**
873
     * @param ImageCollection $images
874
     * @return AbstractImagesImportedFromUDB2
875
     */
876
    abstract protected function createImagesImportedFromUDB2(ImageCollection $images);
877
878
    /**
879
     * @param ImageCollection $images
880
     * @return AbstractImagesUpdatedFromUDB2
881
     */
882
    abstract protected function createImagesUpdatedFromUDB2(ImageCollection $images);
883
884
    /**
885
     * @param EventType $type
886
     * @return AbstractTypeUpdated
887
     */
888
    abstract protected function createTypeUpdatedEvent(EventType $type);
889
890
    /**
891
     * @param Theme $theme
892
     * @return AbstractThemeUpdated
893
     */
894
    abstract protected function createThemeUpdatedEvent(Theme $theme);
895
896
    /**
897
     * @param array $facilities
898
     * @return AbstractFacilitiesUpdated
899
     */
900
    abstract protected function createFacilitiesUpdatedEvent(array $facilities);
901
}
902