Completed
Pull Request — master (#264)
by Kristof
05:22
created

Event::createRejectedEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Event;
4
5
use CultuurNet\UDB3\BookingInfo;
6
use CultuurNet\UDB3\CalendarInterface;
7
use CultuurNet\UDB3\Cdb\EventItemFactory;
8
use CultuurNet\UDB3\Cdb\UpdateableWithCdbXmlInterface;
9
use CultuurNet\UDB3\ContactPoint;
10
use CultuurNet\UDB3\Event\Events\AudienceUpdated;
11
use CultuurNet\UDB3\Event\Events\BookingInfoUpdated;
12
use CultuurNet\UDB3\Event\Events\ContactPointUpdated;
13
use CultuurNet\UDB3\Event\Events\DescriptionTranslated;
14
use CultuurNet\UDB3\Event\Events\DescriptionUpdated;
15
use CultuurNet\UDB3\Event\Events\EventCdbXMLInterface;
16
use CultuurNet\UDB3\Event\Events\EventCopied;
17
use CultuurNet\UDB3\Event\Events\EventCreated;
18
use CultuurNet\UDB3\Event\Events\EventDeleted;
19
use CultuurNet\UDB3\Event\Events\EventImportedFromUDB2;
20
use CultuurNet\UDB3\Event\Events\EventUpdatedFromUDB2;
21
use CultuurNet\UDB3\Event\Events\ImageAdded;
22
use CultuurNet\UDB3\Event\Events\ImageRemoved;
23
use CultuurNet\UDB3\Event\Events\Image\ImagesImportedFromUDB2;
24
use CultuurNet\UDB3\Event\Events\Image\ImagesUpdatedFromUDB2;
25
use CultuurNet\UDB3\Event\Events\ImageUpdated;
26
use CultuurNet\UDB3\Event\Events\LabelAdded;
27
use CultuurNet\UDB3\Event\Events\LabelRemoved;
28
use CultuurNet\UDB3\Event\Events\MainImageSelected;
29
use CultuurNet\UDB3\Event\Events\MajorInfoUpdated;
30
use CultuurNet\UDB3\Event\Events\Moderation\Approved;
31
use CultuurNet\UDB3\Event\Events\Moderation\FlaggedAsDuplicate;
32
use CultuurNet\UDB3\Event\Events\Moderation\FlaggedAsInappropriate;
33
use CultuurNet\UDB3\Event\Events\Moderation\Published;
34
use CultuurNet\UDB3\Event\Events\Moderation\Rejected;
35
use CultuurNet\UDB3\Event\Events\OrganizerDeleted;
36
use CultuurNet\UDB3\Event\Events\OrganizerUpdated;
37
use CultuurNet\UDB3\Event\Events\PriceInfoUpdated;
38
use CultuurNet\UDB3\Event\Events\TitleTranslated;
39
use CultuurNet\UDB3\Event\Events\TypicalAgeRangeDeleted;
40
use CultuurNet\UDB3\Event\Events\TypicalAgeRangeUpdated;
41
use CultuurNet\UDB3\Event\ValueObjects\Audience;
42
use CultuurNet\UDB3\Label;
43
use CultuurNet\UDB3\LabelCollection;
44
use CultuurNet\UDB3\Language;
45
use CultuurNet\UDB3\Location\Location;
46
use CultuurNet\UDB3\Media\ImageCollection;
47
use CultuurNet\UDB3\Media\Image;
48
use CultuurNet\UDB3\Offer\Commands\Image\AbstractUpdateImage;
49
use CultuurNet\UDB3\Offer\Offer;
50
use CultuurNet\UDB3\Offer\WorkflowStatus;
51
use CultuurNet\UDB3\PriceInfo\PriceInfo;
52
use CultuurNet\UDB3\Theme;
53
use CultuurNet\UDB3\Title;
54
use ValueObjects\Identity\UUID;
55
use ValueObjects\String\String as StringLiteral;
56
57
class Event extends Offer implements UpdateableWithCdbXmlInterface
58
{
59
    protected $eventId;
60
61
    /**
62
     * @var Audience
63
     */
64
    private $audience;
65
66
    const MAIN_LANGUAGE_CODE = 'nl';
67
68
    public function __construct()
69
    {
70
        parent::__construct();
71
    }
72
73
    /**
74
     * Factory method to create a new event.
75
     *
76
     * @param $eventId
77
     * @param Title $title
78
     * @param EventType $eventType
79
     * @param Location $location
80
     * @param CalendarInterface $calendar
81
     * @param Theme|null $theme
82
     * @param \DateTimeImmutable|null $publicationDate
83
     * @return Event
84
     */
85 View Code Duplication
    public static function create(
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...
86
        $eventId,
87
        Title $title,
88
        EventType $eventType,
89
        Location $location,
90
        CalendarInterface $calendar,
91
        Theme $theme = null,
92
        \DateTimeImmutable $publicationDate = null
93
    ) {
94
        $event = new self();
95
96
        $event->apply(
97
            new EventCreated(
98
                $eventId,
99
                $title,
100
                $eventType,
101
                $location,
102
                $calendar,
103
                $theme,
104
                $publicationDate
105
            )
106
        );
107
108
        return $event;
109
    }
110
111
    /**
112
     * @param string $newEventId
113
     * @param CalendarInterface $calendar
114
     *
115
     * @return Event
116
     */
117
    public function copy($newEventId, CalendarInterface $calendar)
118
    {
119
        /** @var Event $copy */
120
        $copy = parent::copyWithoutHistory();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (copyWithoutHistory() instead of copy()). Are you sure this is correct? If so, you might want to change this to $this->copyWithoutHistory().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
121
122
        $copy->apply(
123
            new EventCopied(
124
                $newEventId,
125
                $this->eventId,
126
                $calendar
127
            )
128
        );
129
130
        return $copy;
131
    }
132
133
    /**
134
     * @param string $eventId
135
     * @param string $cdbXml
136
     * @param string $cdbXmlNamespaceUri
137
     * @return Event
138
     */
139
    public static function importFromUDB2(
140
        $eventId,
141
        $cdbXml,
142
        $cdbXmlNamespaceUri
143
    ) {
144
        $event = new self();
145
        $event->apply(
146
            new EventImportedFromUDB2(
147
                $eventId,
148
                $cdbXml,
149
                $cdbXmlNamespaceUri
150
            )
151
        );
152
153
        return $event;
154
    }
155
156
    /**
157
     * @param ImageCollection $images
158
     */
159
    public function updateImagesFromUDB2(ImageCollection $images)
160
    {
161
        $this->apply(new ImagesUpdatedFromUDB2($this->eventId, $images));
162
    }
163
164
    /**
165
     * @param ImageCollection $images
166
     */
167
    public function importImagesFromUDB2(ImageCollection $images)
168
    {
169
        $this->apply(new ImagesImportedFromUDB2($this->eventId, $images));
170
    }
171
172
    /**
173
     * {@inheritdoc}
174
     */
175
    public function getAggregateRootId()
176
    {
177
        return $this->eventId;
178
    }
179
180
    /**
181
     * @return UUID[]
182
     */
183
    public function getMediaObjects()
184
    {
185
        return $this->mediaObjects;
186
    }
187
188
    protected function applyEventCreated(EventCreated $eventCreated)
189
    {
190
        $this->eventId = $eventCreated->getEventId();
191
        $this->workflowStatus = WorkflowStatus::DRAFT();
192
    }
193
194
    /**
195
     * @param EventCopied $eventCopied
196
     */
197
    protected function applyEventCopied(EventCopied $eventCopied)
198
    {
199
        $this->eventId = $eventCopied->getItemId();
200
        $this->workflowStatus = WorkflowStatus::DRAFT();
201
        $this->labels = new LabelCollection();
202
    }
203
204
    protected function applyEventImportedFromUDB2(
205
        EventImportedFromUDB2 $eventImported
206
    ) {
207
        $this->eventId = $eventImported->getEventId();
208
        $this->setUDB2Data($eventImported);
209
    }
210
211
    /**
212
     * @param EventUpdatedFromUDB2 $eventUpdated
213
     */
214
    protected function applyEventUpdatedFromUDB2(
215
        EventUpdatedFromUDB2 $eventUpdated
216
    ) {
217
        $this->setUDB2Data($eventUpdated);
218
    }
219
220
    /**
221
     * @param EventCdbXMLInterface $eventCdbXML
222
     */
223
    protected function setUDB2Data(
224
        EventCdbXMLInterface $eventCdbXML
225
    ) {
226
        $udb2Event = EventItemFactory::createEventFromCdbXml(
227
            $eventCdbXML->getCdbXmlNamespaceUri(),
228
            $eventCdbXML->getCdbXml()
229
        );
230
231
        $this->importWorkflowStatus($udb2Event);
232
        $this->labels = LabelCollection::fromKeywords($udb2Event->getKeywords(true));
233
    }
234
235
    /**
236
     * Update the major info.
237
     *
238
     * @param Title $title
239
     * @param EventType $eventType
240
     * @param Location $location
241
     * @param CalendarInterface $calendar
242
     * @param Theme|null $theme
243
     */
244
    public function updateMajorInfo(
245
        Title $title,
246
        EventType $eventType,
247
        Location $location,
248
        CalendarInterface $calendar,
249
        Theme $theme = null
250
    ) {
251
        $this->apply(new MajorInfoUpdated($this->eventId, $title, $eventType, $location, $calendar, $theme));
252
    }
253
254
    /**
255
     * @param Audience $audience
256
     */
257
    public function updateAudience(
258
        Audience $audience
259
    ) {
260
        if (is_null($this->audience) || !$this->audience->equals($audience)) {
261
            $this->apply(new AudienceUpdated(
262
                $this->eventId,
263
                $audience
264
            ));
265
        }
266
    }
267
268
    /**
269
     * @param AudienceUpdated $audienceUpdated
270
     */
271
    public function applyAudienceUpdated(AudienceUpdated $audienceUpdated)
272
    {
273
        $this->audience= $audienceUpdated->getAudience();
274
    }
275
276
    /**
277
     * @inheritDoc
278
     * @return ImagesImportedFromUDB2
279
     */
280
    protected function createImagesImportedFromUDB2(ImageCollection $images)
281
    {
282
        return new ImagesImportedFromUDB2($this->eventId, $images);
283
    }
284
285
    /**
286
     * @inheritDoc
287
     * @return ImagesUpdatedFromUDB2
288
     */
289
    protected function createImagesUpdatedFromUDB2(ImageCollection $images)
290
    {
291
        return new ImagesUpdatedFromUDB2($this->eventId, $images);
292
    }
293
294
    /**
295
     * @inheritdoc
296
     */
297
    public function updateWithCdbXml($cdbXml, $cdbXmlNamespaceUri)
298
    {
299
        $this->apply(
300
            new EventUpdatedFromUDB2(
301
                $this->eventId,
302
                $cdbXml,
303
                $cdbXmlNamespaceUri
304
            )
305
        );
306
    }
307
308
    /**
309
     * @param Label $label
310
     * @return LabelAdded
311
     */
312
    protected function createLabelAddedEvent(Label $label)
313
    {
314
        return new LabelAdded($this->eventId, $label);
315
    }
316
317
    /**
318
     * @param Label $label
319
     * @return LabelRemoved
320
     */
321
    protected function createLabelRemovedEvent(Label $label)
322
    {
323
        return new LabelRemoved($this->eventId, $label);
324
    }
325
326
    /**
327
     * @param Image $image
328
     * @return ImageAdded
329
     */
330
    protected function createImageAddedEvent(Image $image)
331
    {
332
        return new ImageAdded($this->eventId, $image);
333
    }
334
335
    /**
336
     * @param Image $image
337
     * @return ImageRemoved
338
     */
339
    protected function createImageRemovedEvent(Image $image)
340
    {
341
        return new ImageRemoved($this->eventId, $image);
342
    }
343
344
    /**
345
     * @param AbstractUpdateImage $updateImageCommand
346
     * @return ImageUpdated
347
     */
348
    protected function createImageUpdatedEvent(
349
        AbstractUpdateImage $updateImageCommand
350
    ) {
351
        return new ImageUpdated(
352
            $this->eventId,
353
            $updateImageCommand->getMediaObjectId(),
354
            $updateImageCommand->getDescription(),
355
            $updateImageCommand->getCopyrightHolder()
356
        );
357
    }
358
359
    /**
360
     * @param Image $image
361
     * @return MainImageSelected
362
     */
363
    protected function createMainImageSelectedEvent(Image $image)
364
    {
365
        return new MainImageSelected($this->eventId, $image);
366
    }
367
368
    /**
369
     * @param Language $language
370
     * @param StringLiteral $title
371
     * @return TitleTranslated
372
     */
373
    protected function createTitleTranslatedEvent(Language $language, StringLiteral $title)
374
    {
375
        return new TitleTranslated($this->eventId, $language, $title);
376
    }
377
378
    /**
379
     * @param Language $language
380
     * @param StringLiteral $description
381
     * @return DescriptionTranslated
382
     */
383
    protected function createDescriptionTranslatedEvent(Language $language, StringLiteral $description)
384
    {
385
        return new DescriptionTranslated($this->eventId, $language, $description);
386
    }
387
388
    /**
389
     * @param string $description
390
     * @return DescriptionUpdated
391
     */
392
    protected function createDescriptionUpdatedEvent($description)
393
    {
394
        return new DescriptionUpdated($this->eventId, $description);
395
    }
396
397
    /**
398
     * @param string $typicalAgeRange
399
     * @return TypicalAgeRangeUpdated
400
     */
401
    protected function createTypicalAgeRangeUpdatedEvent($typicalAgeRange)
402
    {
403
        return new TypicalAgeRangeUpdated($this->eventId, $typicalAgeRange);
404
    }
405
406
    /**
407
     * @return TypicalAgeRangeDeleted
408
     */
409
    protected function createTypicalAgeRangeDeletedEvent()
410
    {
411
        return new TypicalAgeRangeDeleted($this->eventId);
412
    }
413
414
    /**
415
     * @param string $organizerId
416
     * @return OrganizerUpdated
417
     */
418
    protected function createOrganizerUpdatedEvent($organizerId)
419
    {
420
        return new OrganizerUpdated($this->eventId, $organizerId);
421
    }
422
423
    /**
424
     * @param string $organizerId
425
     * @return OrganizerDeleted
426
     */
427
    protected function createOrganizerDeletedEvent($organizerId)
428
    {
429
        return new OrganizerDeleted($this->eventId, $organizerId);
430
    }
431
432
    /**
433
     * @param ContactPoint $contactPoint
434
     * @return ContactPointUpdated
435
     */
436
    protected function createContactPointUpdatedEvent(ContactPoint $contactPoint)
437
    {
438
        return new ContactPointUpdated($this->eventId, $contactPoint);
439
    }
440
441
    /**
442
     * @param BookingInfo $bookingInfo
443
     * @return BookingInfoUpdated
444
     */
445
    protected function createBookingInfoUpdatedEvent(BookingInfo $bookingInfo)
446
    {
447
        return new BookingInfoUpdated($this->eventId, $bookingInfo);
448
    }
449
450
    /**
451
     * @param PriceInfo $priceInfo
452
     * @return PriceInfoUpdated
453
     */
454
    protected function createPriceInfoUpdatedEvent(PriceInfo $priceInfo)
455
    {
456
        return new PriceInfoUpdated($this->eventId, $priceInfo);
457
    }
458
459
    /**
460
     * @return EventDeleted
461
     */
462
    protected function createOfferDeletedEvent()
463
    {
464
        return new EventDeleted($this->eventId);
465
    }
466
467
    /**
468
     * @inheritdoc
469
     */
470
    protected function createPublishedEvent(\DateTimeInterface $publicationDate)
471
    {
472
        return new Published($this->eventId, $publicationDate);
473
    }
474
475
    /**
476
     * @inheritdoc
477
     */
478
    protected function createApprovedEvent()
479
    {
480
        return new Approved($this->eventId);
481
    }
482
483
    /**
484
     * @inheritdoc
485
     */
486
    protected function createRejectedEvent(StringLiteral $reason)
487
    {
488
        return new Rejected($this->eventId, $reason);
489
    }
490
491
    /**
492
     * @inheritDoc
493
     */
494
    protected function createFlaggedAsDuplicate()
495
    {
496
        return new FlaggedAsDuplicate($this->eventId);
497
    }
498
499
    /**
500
     * @inheritDoc
501
     */
502
    protected function createFlaggedAsInappropriate()
503
    {
504
        return new FlaggedAsInappropriate($this->eventId);
505
    }
506
}
507