Completed
Pull Request — master (#328)
by
unknown
07:15
created

Offer::updateType()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
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\UDB3\BookingInfo;
8
use CultuurNet\UDB3\Calendar;
9
use CultuurNet\UDB3\ContactPoint;
10
use CultuurNet\UDB3\Description;
11
use CultuurNet\UDB3\Event\EventType;
12
use CultuurNet\UDB3\Label;
13
use CultuurNet\UDB3\LabelAwareAggregateRoot;
14
use CultuurNet\UDB3\LabelCollection;
15
use CultuurNet\UDB3\Media\Image;
16
use CultuurNet\UDB3\Media\ImageCollection;
17
use CultuurNet\UDB3\Offer\Commands\Image\AbstractUpdateImage;
18
use CultuurNet\UDB3\Language;
19
use CultuurNet\UDB3\Offer\Events\AbstractBookingInfoUpdated;
20
use CultuurNet\UDB3\Offer\Events\AbstractContactPointUpdated;
21
use CultuurNet\UDB3\Offer\Events\AbstractThemeUpdated;
22
use CultuurNet\UDB3\Offer\Events\AbstractTitleTranslated;
23
use CultuurNet\UDB3\Offer\Events\AbstractTitleUpdated;
24
use CultuurNet\UDB3\Offer\Events\AbstractDescriptionTranslated;
25
use CultuurNet\UDB3\Offer\Events\AbstractDescriptionUpdated;
26
use CultuurNet\UDB3\Offer\Events\AbstractLabelAdded;
27
use CultuurNet\UDB3\Offer\Events\AbstractLabelRemoved;
28
use CultuurNet\UDB3\Offer\Events\AbstractOfferDeleted;
29
use CultuurNet\UDB3\Offer\Events\AbstractOrganizerDeleted;
30
use CultuurNet\UDB3\Offer\Events\AbstractOrganizerUpdated;
31
use CultuurNet\UDB3\Offer\Events\AbstractPriceInfoUpdated;
32
use CultuurNet\UDB3\Offer\Events\AbstractTypeUpdated;
33
use CultuurNet\UDB3\Offer\Events\AbstractTypicalAgeRangeDeleted;
34
use CultuurNet\UDB3\Offer\Events\AbstractTypicalAgeRangeUpdated;
35
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageAdded;
36
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageRemoved;
37
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesEvent;
38
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesImportedFromUDB2;
39
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesUpdatedFromUDB2;
40
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageUpdated;
41
use CultuurNet\UDB3\Offer\Events\Image\AbstractMainImageSelected;
42
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractApproved;
43
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractFlaggedAsDuplicate;
44
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractFlaggedAsInappropriate;
45
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractPublished;
46
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractRejected;
47
use CultuurNet\UDB3\PriceInfo\PriceInfo;
48
use CultuurNet\UDB3\Theme;
49
use CultuurNet\UDB3\Title;
50
use Exception;
51
use ValueObjects\Identity\UUID;
52
use ValueObjects\StringLiteral\StringLiteral;
53
54
abstract class Offer extends EventSourcedAggregateRoot implements LabelAwareAggregateRoot
55
{
56
    const DUPLICATE_REASON = 'duplicate';
57
    const INAPPROPRIATE_REASON = 'inappropriate';
58
59
    /**
60
     * @var LabelCollection
61
     */
62
    protected $labels;
63
64
    /**
65
     * @var ImageCollection
66
     */
67
    protected $images;
68
69
    /**
70
     * @var string
71
     *
72
     * Organizer ids can come from UDB2 which does not strictly use UUIDs.
73
     */
74
    protected $organizerId;
75
76
    /**
77
     * @var WorkflowStatus
78
     */
79
    protected $workflowStatus;
80
81
    /**
82
     * @var StringLiteral|null
83
     */
84
    protected $rejectedReason;
85
86
    /**
87
     * @var PriceInfo
88
     */
89
    protected $priceInfo;
90
91
    /**
92
     * @var StringLiteral[]
93
     */
94
    protected $titles;
95
96
    /**
97
     * @var Description[]
98
     */
99
    protected $descriptions;
100
101
    /**
102
     * @var Language
103
     */
104
    protected $mainLanguage;
105
106
    /**
107
     * @var string;
108
     */
109
    protected $typeId;
110
111
    /**
112
     * @var string;
113
     */
114
    protected $themeId;
115
116
    /**
117
     * Offer constructor.
118
     */
119
    public function __construct()
120
    {
121
        // For now the main language is hard coded on nl.
122
        // In the future it should be set on create.
123
        $this->mainLanguage = new Language('nl');
124
125
        $this->titles = [];
126
        $this->descriptions = [];
127
        $this->labels = new LabelCollection();
128
        $this->images = new ImageCollection();
129
    }
130
131
    /**
132
     * @param EventType $type
133
     */
134
    public function updateType(EventType $type)
135
    {
136
        if (!$this->typeId || $this->typeId !== $type->getId()) {
137
            $this->apply($this->createTypeUpdatedEvent($type));
138
        }
139
    }
140
141
    /**
142
     * @param Theme $theme
143
     */
144
    public function updateTheme(Theme $theme)
145
    {
146
        if (!$this->themeId || $this->themeId !== $theme->getId()) {
147
            $this->apply($this->createThemeUpdatedEvent($theme));
148
        }
149
    }
150
151
    /**
152
     * Get the id of the main image if one is selected for this offer.
153
     *
154
     * @return UUID|null
155
     */
156
    protected function getMainImageId()
157
    {
158
        $mainImage = $this->images->getMain();
159
        return isset($mainImage) ? $mainImage->getMediaObjectId() : null;
160
    }
161
162
    /**
163
     * @inheritdoc
164
     */
165
    public function addLabel(Label $label)
166
    {
167
        if (!$this->labels->contains($label)) {
168
            $this->apply(
169
                $this->createLabelAddedEvent($label)
170
            );
171
        }
172
    }
173
174
    /**
175
     * @inheritdoc
176
     */
177
    public function removeLabel(Label $label)
178
    {
179
        if ($this->labels->contains($label)) {
180
            $this->apply(
181
                $this->createLabelRemovedEvent($label)
182
            );
183
        }
184
    }
185
186
    /**
187
     * @param Language $language
188
     * @param Title $title
189
     */
190
    public function updateTitle(Language $language, Title $title)
191
    {
192
        if ($this->isTitleChanged($title, $language)) {
193
            if ($language->getCode() !== $this->mainLanguage->getCode()) {
194
                $event = $this->createTitleTranslatedEvent($language, $title);
195
            } else {
196
                $event = $this->createTitleUpdatedEvent($title);
197
            }
198
199
            $this->apply($event);
200
        }
201
    }
202
203
    /**
204
     * @param Description $description
205
     * @param Language $language
206
     */
207
    public function updateDescription(Description $description, Language $language)
208
    {
209
        if ($this->isDescriptionChanged($description, $language)) {
210
            if ($language->getCode() !== $this->mainLanguage->getCode()) {
211
                $event = $this->createDescriptionTranslatedEvent($language, $description);
212
            } else {
213
                $event = $this->createDescriptionUpdatedEvent((string) $description);
214
            }
215
216
            $this->apply($event);
217
        }
218
    }
219
220
    /**
221
     * @param Calendar $calendar
222
     */
223
    public function updateCalendar(Calendar $calendar)
224
    {
225
        // For now no special business rules for updating the calendar.
226
        $this->apply(
227
            $this->createCalendarUpdatedEvent($calendar)
228
        );
229
    }
230
231
    /**
232
     * @param string $typicalAgeRange
233
     */
234
    public function updateTypicalAgeRange($typicalAgeRange)
235
    {
236
        $this->apply(
237
            $this->createTypicalAgeRangeUpdatedEvent($typicalAgeRange)
238
        );
239
    }
240
241
    public function deleteTypicalAgeRange()
242
    {
243
        $this->apply(
244
            $this->createTypicalAgeRangeDeletedEvent()
245
        );
246
    }
247
248
    /**
249
     * @param string $organizerId
250
     */
251
    public function updateOrganizer($organizerId)
252
    {
253
        if ($this->organizerId !== $organizerId) {
254
            $this->apply(
255
                $this->createOrganizerUpdatedEvent($organizerId)
256
            );
257
        }
258
    }
259
260
    /**
261
     * Delete the given organizer.
262
     *
263
     * @param string $organizerId
264
     */
265
    public function deleteOrganizer($organizerId)
266
    {
267
        if ($this->organizerId === $organizerId) {
268
            $this->apply(
269
                $this->createOrganizerDeletedEvent($organizerId)
270
            );
271
        }
272
    }
273
274
    /**
275
     * Updated the contact info.
276
     * @param ContactPoint $contactPoint
277
     */
278
    public function updateContactPoint(ContactPoint $contactPoint)
279
    {
280
        $this->apply(
281
            $this->createContactPointUpdatedEvent($contactPoint)
282
        );
283
    }
284
285
    /**
286
     * Updated the booking info.
287
     *
288
     * @param BookingInfo $bookingInfo
289
     */
290
    public function updateBookingInfo(BookingInfo $bookingInfo)
291
    {
292
        $this->apply(
293
            $this->createBookingInfoUpdatedEvent($bookingInfo)
294
        );
295
    }
296
297
    /**
298
     * @param PriceInfo $priceInfo
299
     */
300
    public function updatePriceInfo(PriceInfo $priceInfo)
301
    {
302
        if (is_null($this->priceInfo) || $priceInfo->serialize() !== $this->priceInfo->serialize()) {
303
            $this->apply(
304
                $this->createPriceInfoUpdatedEvent($priceInfo)
305
            );
306
        }
307
    }
308
309
    /**
310
     * @param AbstractPriceInfoUpdated $priceInfoUpdated
311
     */
312
    protected function applyPriceInfoUpdated(AbstractPriceInfoUpdated $priceInfoUpdated)
313
    {
314
        $this->priceInfo = $priceInfoUpdated->getPriceInfo();
315
    }
316
317
    /**
318
     * @param AbstractLabelAdded $labelAdded
319
     */
320
    protected function applyLabelAdded(AbstractLabelAdded $labelAdded)
321
    {
322
        $this->labels = $this->labels->with($labelAdded->getLabel());
323
    }
324
325
    /**
326
     * @param AbstractLabelRemoved $labelRemoved
327
     */
328
    protected function applyLabelRemoved(AbstractLabelRemoved $labelRemoved)
329
    {
330
        $this->labels = $this->labels->without($labelRemoved->getLabel());
331
    }
332
333
    protected function applyDescriptionUpdated(AbstractDescriptionUpdated $descriptionUpdated)
334
    {
335
        $mainLanguageCode = $this->mainLanguage->getCode();
336
        $this->descriptions[$mainLanguageCode] = new Description($descriptionUpdated->getDescription());
337
    }
338
339
    protected function applyDescriptionTranslated(AbstractDescriptionTranslated $descriptionTranslated)
340
    {
341
        $languageCode = $descriptionTranslated->getLanguage()->getCode();
342
        $this->descriptions[$languageCode] = $descriptionTranslated->getDescription();
343
    }
344
345
    /**
346
     * Add a new image.
347
     *
348
     * @param Image $image
349
     */
350
    public function addImage(Image $image)
351
    {
352
        if (!$this->images->contains($image)) {
353
            $this->apply(
354
                $this->createImageAddedEvent($image)
355
            );
356
        }
357
    }
358
359
    /**
360
     * @param AbstractUpdateImage $updateImageCommand
361
     */
362
    public function updateImage(AbstractUpdateImage $updateImageCommand)
363
    {
364
        if ($this->images->findImageByUUID($updateImageCommand->getMediaObjectId())) {
365
            $this->apply(
366
                $this->createImageUpdatedEvent($updateImageCommand)
367
            );
368
        }
369
    }
370
371
    /**
372
     * Remove an image.
373
     *
374
     * @param Image $image
375
     */
376
    public function removeImage(Image $image)
377
    {
378
        if ($this->images->contains($image)) {
379
            $this->apply(
380
                $this->createImageRemovedEvent($image)
381
            );
382
        }
383
    }
384
385
    /**
386
     * Make an existing image of the item the main image.
387
     *
388
     * @param Image $image
389
     */
390
    public function selectMainImage(Image $image)
391
    {
392
        if (!$this->images->contains($image)) {
393
            throw new \InvalidArgumentException('You can not select a random image to be main, it has to be added to the item.');
394
        }
395
396
        $oldMainImage = $this->images->getMain();
397
398
        if (!isset($oldMainImage) || $oldMainImage->getMediaObjectId() !== $image->getMediaObjectId()) {
399
            $this->apply(
400
                $this->createMainImageSelectedEvent($image)
401
            );
402
        }
403
    }
404
405
    /**
406
     * Delete the offer.
407
     */
408
    public function delete()
409
    {
410
        $this->apply(
411
            $this->createOfferDeletedEvent()
412
        );
413
    }
414
415
    /**
416
     * @param CultureFeed_Cdb_Item_Base $cdbItem
417
     */
418
    protected function importWorkflowStatus(CultureFeed_Cdb_Item_Base $cdbItem)
419
    {
420
        try {
421
            $workflowStatus = WorkflowStatus::fromNative($cdbItem->getWfStatus());
422
        } catch (\InvalidArgumentException $exception) {
423
            $workflowStatus = WorkflowStatus::READY_FOR_VALIDATION();
424
        }
425
        $this->workflowStatus = $workflowStatus;
426
    }
427
428
    /**
429
     * Publish the offer when it has workflowstatus draft.
430
     * @param \DateTimeInterface $publicationDate
431
     */
432
    public function publish(\DateTimeInterface $publicationDate)
433
    {
434
        $this->guardPublish() ?: $this->apply(
435
            $this->createPublishedEvent($publicationDate)
436
        );
437
    }
438
439
    /**
440
     * @return bool
441
     * @throws Exception
442
     */
443 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...
444
    {
445
        if ($this->workflowStatus === WorkflowStatus::READY_FOR_VALIDATION()) {
446
            return true; // nothing left to do if the offer has already been published
447
        }
448
449
        if ($this->workflowStatus !== WorkflowStatus::DRAFT()) {
450
            throw new Exception('You can not publish an offer that is not draft');
451
        }
452
453
        return false;
454
    }
455
456
    /**
457
     * Approve the offer when it's waiting for validation.
458
     */
459
    public function approve()
460
    {
461
        $this->guardApprove() ?: $this->apply($this->createApprovedEvent());
462
    }
463
464
    /**
465
     * @return bool
466
     * @throws Exception
467
     */
468 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...
469
    {
470
        if ($this->workflowStatus === WorkflowStatus::APPROVED()) {
471
            return true; // nothing left to do if the offer has already been approved
472
        }
473
474
        if ($this->workflowStatus !== WorkflowStatus::READY_FOR_VALIDATION()) {
475
            throw new Exception('You can not approve an offer that is not ready for validation');
476
        }
477
478
        return false;
479
    }
480
481
    /**
482
     * Reject an offer that is waiting for validation with a given reason.
483
     * @param StringLiteral $reason
484
     */
485
    public function reject(StringLiteral $reason)
486
    {
487
        $this->guardRejection($reason) ?: $this->apply($this->createRejectedEvent($reason));
488
    }
489
490
    public function flagAsDuplicate()
491
    {
492
        $reason = new StringLiteral(self::DUPLICATE_REASON);
493
        $this->guardRejection($reason) ?: $this->apply($this->createFlaggedAsDuplicate());
494
    }
495
496
    public function flagAsInappropriate()
497
    {
498
        $reason = new StringLiteral(self::INAPPROPRIATE_REASON);
499
        $this->guardRejection($reason) ?: $this->apply($this->createFlaggedAsInappropriate());
500
    }
501
502
    /**
503
     * @param StringLiteral $reason
504
     * @return bool
505
     *  false when the offer can still be rejected, true when the offer is already rejected for the same reason
506
     * @throws Exception
507
     */
508
    private function guardRejection(StringLiteral $reason)
509
    {
510
        if ($this->workflowStatus === WorkflowStatus::REJECTED()) {
511
            if ($this->rejectedReason && $reason->sameValueAs($this->rejectedReason)) {
512
                return true; // nothing left to do if the offer has already been rejected for the same reason
513
            } else {
514
                throw new Exception('The offer has already been rejected for another reason: ' . $this->rejectedReason);
515
            }
516
        }
517
518
        if ($this->workflowStatus !== WorkflowStatus::READY_FOR_VALIDATION()) {
519
            throw new Exception('You can not reject an offer that is not ready for validation');
520
        }
521
522
        return false;
523
    }
524
525
    /**
526
     * @param Title $title
527
     * @param Language $language
528
     * @return bool
529
     */
530 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...
531
    {
532
        $languageCode = $language->getCode();
533
534
        return !isset($this->titles[$languageCode]) ||
535
            !$title->sameValueAs($this->titles[$languageCode]);
536
    }
537
538
    /**
539
     * @param Description $description
540
     * @param Language $language
541
     * @return bool
542
     */
543 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...
544
    {
545
        $languageCode = $language->getCode();
546
547
        return !isset($this->descriptions[$languageCode]) ||
548
            !$description->sameValueAs($this->descriptions[$languageCode]);
549
    }
550
551
    /**
552
     * Overwrites or resets the main image and all media objects
553
     * by importing a new collection of images from UDB2.
554
     *
555
     * @param ImageCollection $images
556
     */
557
    public function importImagesFromUDB2(ImageCollection $images)
558
    {
559
        $this->apply($this->createImagesImportedFromUDB2($images));
560
    }
561
562
    /**
563
     * Overwrites or resets the main image and all media objects
564
     * by updating with a new collection of images from UDB2.
565
     *
566
     * @param ImageCollection $images
567
     */
568
    public function updateImagesFromUDB2(ImageCollection $images)
569
    {
570
        $this->apply($this->createImagesUpdatedFromUDB2($images));
571
    }
572
573
    /**
574
     * @param AbstractPublished $published
575
     */
576
    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...
577
    {
578
        $this->workflowStatus = WorkflowStatus::READY_FOR_VALIDATION();
579
    }
580
581
    /**
582
     * @param AbstractApproved $approved
583
     */
584
    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...
585
    {
586
        $this->workflowStatus = WorkflowStatus::APPROVED();
587
    }
588
589
    /**
590
     * @param AbstractRejected $rejected
591
     */
592
    protected function applyRejected(AbstractRejected $rejected)
593
    {
594
        $this->rejectedReason = $rejected->getReason();
595
        $this->workflowStatus = WorkflowStatus::REJECTED();
596
    }
597
598
    /**
599
     * @param AbstractFlaggedAsDuplicate $flaggedAsDuplicate
600
     */
601
    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...
602
    {
603
        $this->rejectedReason = new StringLiteral(self::DUPLICATE_REASON);
604
        $this->workflowStatus = WorkflowStatus::REJECTED();
605
    }
606
607
    /**
608
     * @param AbstractFlaggedAsInappropriate $flaggedAsInappropriate
609
     */
610
    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...
611
    {
612
        $this->rejectedReason = new StringLiteral(self::INAPPROPRIATE_REASON);
613
        $this->workflowStatus = WorkflowStatus::REJECTED();
614
    }
615
616
    protected function applyImageAdded(AbstractImageAdded $imageAdded)
617
    {
618
        $this->images = $this->images->with($imageAdded->getImage());
619
    }
620
621
    protected function applyImageRemoved(AbstractImageRemoved $imageRemoved)
622
    {
623
        $this->images = $this->images->without($imageRemoved->getImage());
624
    }
625
626
    protected function applyMainImageSelected(AbstractMainImageSelected $mainImageSelected)
627
    {
628
        $this->images = $this->images->withMain($mainImageSelected->getImage());
629
    }
630
631
    protected function applyOrganizerUpdated(AbstractOrganizerUpdated $organizerUpdated)
632
    {
633
        $this->organizerId = $organizerUpdated->getOrganizerId();
634
    }
635
636
    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...
637
    {
638
        $this->organizerId = null;
639
    }
640
641
    /**
642
     * @param AbstractImagesImportedFromUDB2 $imagesImportedFromUDB2
643
     */
644
    protected function applyImagesImportedFromUDB2(AbstractImagesImportedFromUDB2 $imagesImportedFromUDB2)
645
    {
646
        $this->applyUdb2ImagesEvent($imagesImportedFromUDB2);
647
    }
648
649
    /**
650
     * @param AbstractImagesUpdatedFromUDB2 $imagesUpdatedFromUDB2
651
     */
652
    protected function applyImagesUpdatedFromUDB2(AbstractImagesUpdatedFromUDB2 $imagesUpdatedFromUDB2)
653
    {
654
        $this->applyUdb2ImagesEvent($imagesUpdatedFromUDB2);
655
    }
656
657
    /**
658
     * This indirect apply method can be called internally to deal with images coming from UDB2.
659
     * Imports from UDB2 only contain the native Dutch content.
660
     * @see https://github.com/cultuurnet/udb3-udb2-bridge/blob/db0a7ab2444f55bb3faae3d59b82b39aaeba253b/test/Media/ImageCollectionFactoryTest.php#L79-L103
661
     * Because of this we have to make sure translated images are left in place.
662
     *
663
     * @param AbstractImagesEvent $imagesEvent
664
     */
665
    protected function applyUdb2ImagesEvent(AbstractImagesEvent $imagesEvent)
666
    {
667
        $newMainImage = $imagesEvent->getImages()->getMain();
668
        $dutchImagesList = $imagesEvent->getImages()->toArray();
669
        $translatedImagesList = array_filter(
670
            $this->images->toArray(),
671
            function (Image $image) {
672
                return $image->getLanguage()->getCode() !== 'nl';
673
            }
674
        );
675
676
        $imagesList = array_merge($dutchImagesList, $translatedImagesList);
677
        $images = ImageCollection::fromArray($imagesList);
678
679
        $this->images = isset($newMainImage) ? $images->withMain($newMainImage) : $images;
680
    }
681
682
    /**
683
     * @param Label $label
684
     * @return AbstractLabelAdded
685
     */
686
    abstract protected function createLabelAddedEvent(Label $label);
687
688
    /**
689
     * @param Label $label
690
     * @return AbstractLabelRemoved
691
     */
692
    abstract protected function createLabelRemovedEvent(Label $label);
693
694
    /**
695
     * @param Language $language
696
     * @param StringLiteral $title
697
     * @return AbstractTitleTranslated
698
     */
699
    abstract protected function createTitleTranslatedEvent(Language $language, StringLiteral $title);
700
701
    /**
702
     * @param Language $language
703
     * @param StringLiteral $description
704
     * @return AbstractDescriptionTranslated
705
     */
706
    abstract protected function createDescriptionTranslatedEvent(Language $language, StringLiteral $description);
707
708
    /**
709
     * @param Image $image
710
     * @return AbstractImageAdded
711
     */
712
    abstract protected function createImageAddedEvent(Image $image);
713
714
    /**
715
     * @param Image $image
716
     * @return AbstractImageRemoved
717
     */
718
    abstract protected function createImageRemovedEvent(Image $image);
719
720
    /**
721
     * @param AbstractUpdateImage $updateImageCommand
722
     * @return AbstractImageUpdated
723
     */
724
    abstract protected function createImageUpdatedEvent(
725
        AbstractUpdateImage $updateImageCommand
726
    );
727
728
    /**
729
     * @param Image $image
730
     * @return AbstractMainImageSelected
731
     */
732
    abstract protected function createMainImageSelectedEvent(Image $image);
733
734
    /**
735
     * @return AbstractOfferDeleted
736
     */
737
    abstract protected function createOfferDeletedEvent();
738
739
    /**
740
     * @param Title $title
741
     * @return AbstractTitleUpdated
742
     */
743
    abstract protected function createTitleUpdatedEvent(Title $title);
744
745
    /**
746
     * @param string $description
747
     * @return AbstractDescriptionUpdated
748
     */
749
    abstract protected function createDescriptionUpdatedEvent($description);
750
751
    /**
752
     * @param Calendar $calendar
753
     * @return AbstractCalendarUpdated
754
     */
755
    abstract protected function createCalendarUpdatedEvent(Calendar $calendar);
756
757
    /**
758
     * @param string $typicalAgeRange
759
     * @return AbstractTypicalAgeRangeUpdated
760
     */
761
    abstract protected function createTypicalAgeRangeUpdatedEvent($typicalAgeRange);
762
763
    /**
764
     * @return AbstractTypicalAgeRangeDeleted
765
     */
766
    abstract protected function createTypicalAgeRangeDeletedEvent();
767
768
    /**
769
     * @param string $organizerId
770
     * @return AbstractOrganizerUpdated
771
     */
772
    abstract protected function createOrganizerUpdatedEvent($organizerId);
773
774
    /**
775
     * @param string $organizerId
776
     * @return AbstractOrganizerDeleted
777
     */
778
    abstract protected function createOrganizerDeletedEvent($organizerId);
779
780
    /**
781
     * @param ContactPoint $contactPoint
782
     * @return AbstractContactPointUpdated
783
     */
784
    abstract protected function createContactPointUpdatedEvent(ContactPoint $contactPoint);
785
786
    /**
787
     * @param BookingInfo $bookingInfo
788
     * @return AbstractBookingInfoUpdated
789
     */
790
    abstract protected function createBookingInfoUpdatedEvent(BookingInfo $bookingInfo);
791
792
    /**
793
     * @param PriceInfo $priceInfo
794
     * @return AbstractPriceInfoUpdated
795
     */
796
    abstract protected function createPriceInfoUpdatedEvent(PriceInfo $priceInfo);
797
798
    /**
799
     * @param \DateTimeInterface $publicationDate
800
     * @return AbstractPublished
801
     */
802
    abstract protected function createPublishedEvent(\DateTimeInterface $publicationDate);
803
804
    /**
805
     * @return AbstractApproved
806
     */
807
    abstract protected function createApprovedEvent();
808
809
    /**
810
     * @param StringLiteral $reason
811
     * @return AbstractRejected
812
     */
813
    abstract protected function createRejectedEvent(StringLiteral $reason);
814
815
    /**
816
     * @return AbstractFlaggedAsDuplicate
817
     */
818
    abstract protected function createFlaggedAsDuplicate();
819
820
    /**
821
     * @return AbstractFlaggedAsInappropriate
822
     */
823
    abstract protected function createFlaggedAsInappropriate();
824
825
    /**
826
     * @param ImageCollection $images
827
     * @return AbstractImagesImportedFromUDB2
828
     */
829
    abstract protected function createImagesImportedFromUDB2(ImageCollection $images);
830
831
    /**
832
     * @param ImageCollection $images
833
     * @return AbstractImagesUpdatedFromUDB2
834
     */
835
    abstract protected function createImagesUpdatedFromUDB2(ImageCollection $images);
836
837
    /**
838
     * @param EventType $type
839
     * @return AbstractTypeUpdated
840
     */
841
    abstract protected function createTypeUpdatedEvent(EventType $type);
842
843
    /**
844
     * @param Theme $theme
845
     * @return AbstractThemeUpdated
846
     */
847
    abstract protected function createThemeUpdatedEvent(Theme $theme);
848
}
849