Completed
Pull Request — master (#285)
by Luc
06:49
created

Place::createDescriptionUpdatedEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Place;
4
5
use CultuurNet\Geocoding\Coordinate\Coordinates;
6
use CultuurNet\UDB3\Address\Address;
7
use CultuurNet\UDB3\BookingInfo;
8
use CultuurNet\UDB3\CalendarInterface;
9
use CultuurNet\UDB3\Cdb\ActorItemFactory;
10
use CultuurNet\UDB3\Cdb\UpdateableWithCdbXmlInterface;
11
use CultuurNet\UDB3\ContactPoint;
12
use CultuurNet\UDB3\Event\EventType;
13
use CultuurNet\UDB3\Label;
14
use CultuurNet\UDB3\LabelCollection;
15
use CultuurNet\UDB3\Media\ImageCollection;
16
use CultuurNet\UDB3\Offer\Commands\Image\AbstractUpdateImage;
17
use CultuurNet\UDB3\Language;
18
use CultuurNet\UDB3\Offer\Offer;
19
use CultuurNet\UDB3\Media\Image;
20
use CultuurNet\UDB3\Offer\WorkflowStatus;
21
use CultuurNet\UDB3\Place\Events\BookingInfoUpdated;
22
use CultuurNet\UDB3\Place\Events\ContactPointUpdated;
23
use CultuurNet\UDB3\Place\Events\DescriptionTranslated;
24
use CultuurNet\UDB3\Place\Events\DescriptionUpdated;
25
use CultuurNet\UDB3\Place\Events\FacilitiesUpdated;
26
use CultuurNet\UDB3\Place\Events\GeoCoordinatesUpdated;
27
use CultuurNet\UDB3\Place\Events\Image\ImagesImportedFromUDB2;
28
use CultuurNet\UDB3\Place\Events\Image\ImagesUpdatedFromUDB2;
29
use CultuurNet\UDB3\Place\Events\ImageAdded;
30
use CultuurNet\UDB3\Place\Events\ImageRemoved;
31
use CultuurNet\UDB3\Place\Events\ImageUpdated;
32
use CultuurNet\UDB3\Place\Events\MainImageSelected;
33
use CultuurNet\UDB3\Place\Events\LabelAdded;
34
use CultuurNet\UDB3\Place\Events\LabelRemoved;
35
use CultuurNet\UDB3\Place\Events\MajorInfoUpdated;
36
use CultuurNet\UDB3\Place\Events\Moderation\Approved;
37
use CultuurNet\UDB3\Place\Events\Moderation\FlaggedAsDuplicate;
38
use CultuurNet\UDB3\Place\Events\Moderation\FlaggedAsInappropriate;
39
use CultuurNet\UDB3\Place\Events\Moderation\Published;
40
use CultuurNet\UDB3\Place\Events\Moderation\Rejected;
41
use CultuurNet\UDB3\Place\Events\OrganizerDeleted;
42
use CultuurNet\UDB3\Place\Events\OrganizerUpdated;
43
use CultuurNet\UDB3\Place\Events\PlaceCreated;
44
use CultuurNet\UDB3\Place\Events\PlaceDeleted;
45
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2;
46
use CultuurNet\UDB3\Place\Events\PlaceUpdatedFromUDB2;
47
use CultuurNet\UDB3\Place\Events\PriceInfoUpdated;
48
use CultuurNet\UDB3\Place\Events\TitleTranslated;
49
use CultuurNet\UDB3\Place\Events\TypicalAgeRangeDeleted;
50
use CultuurNet\UDB3\Place\Events\TypicalAgeRangeUpdated;
51
use CultuurNet\UDB3\PriceInfo\PriceInfo;
52
use CultuurNet\UDB3\Theme;
53
use CultuurNet\UDB3\Title;
54
use DateTimeImmutable;
55
use ValueObjects\StringLiteral\StringLiteral;
56
57
class Place extends Offer implements UpdateableWithCdbXmlInterface
58
{
59
    /**
60
     * The actor id.
61
     *
62
     * @var string
63
     */
64
    protected $actorId;
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getAggregateRootId()
70
    {
71
        return $this->actorId;
72
    }
73
74
    /**
75
     * Factory method to create a new Place.
76
     *
77
     * @todo Refactor this method so it can be called create. Currently the
78
     * normal behavior for create is taken by the legacy udb2 logic.
79
     * The PlaceImportedFromUDB2 could be a superclass of Place.
80
     *
81
     * @param string $id
82
     * @param Title $title
83
     * @param EventType $eventType
84
     * @param Address $address
85
     * @param CalendarInterface $calendar
86
     * @param Theme|null $theme
87
     * @param DateTimeImmutable|null $publicationDate
88
     *
89
     * @return self
90
     */
91 View Code Duplication
    public static function createPlace(
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...
92
        $id,
93
        Title $title,
94
        EventType $eventType,
95
        Address $address,
96
        CalendarInterface $calendar,
97
        Theme $theme = null,
98
        DateTimeImmutable $publicationDate = null
99
    ) {
100
        $place = new self();
101
        $place->apply(new PlaceCreated(
102
            $id,
103
            $title,
104
            $eventType,
105
            $address,
106
            $calendar,
107
            $theme,
108
            $publicationDate
109
        ));
110
111
        return $place;
112
    }
113
114
    /**
115
     * Apply the place created event.
116
     * @param PlaceCreated $placeCreated
117
     */
118
    protected function applyPlaceCreated(PlaceCreated $placeCreated)
119
    {
120
        $this->actorId = $placeCreated->getPlaceId();
121
        $this->workflowStatus = WorkflowStatus::DRAFT();
122
    }
123
124
    /**
125
     * Update the facilities.
126
     *
127
     * @param array $facilities
128
     */
129
    public function updateFacilities(array $facilities)
130
    {
131
        $this->apply(new FacilitiesUpdated($this->actorId, $facilities));
132
    }
133
134
    /**
135
     * Update the major info.
136
     *
137
     * @param Title $title
138
     * @param EventType $eventType
139
     * @param Address $address
140
     * @param CalendarInterface $calendar
141
     * @param Theme $theme
142
     */
143
    public function updateMajorInfo(
144
        Title $title,
145
        EventType $eventType,
146
        Address $address,
147
        CalendarInterface $calendar,
148
        Theme $theme = null
149
    ) {
150
        $this->apply(new MajorInfoUpdated($this->actorId, $title, $eventType, $address, $calendar, $theme));
151
    }
152
153
    /**
154
     * @param Coordinates $coordinates
155
     */
156
    public function updateGeoCoordinates(
157
        Coordinates $coordinates
158
    ) {
159
        // Note: DON'T compare to previous coordinates and apply only on
160
        // changes. Various projectors expect GeoCoordinatesUpdated after
161
        // MajorInfoUpdated and PlaceUpdatedFromUDB2, even if the address
162
        // and thus the coordinates haven't actually changed.
163
        $this->apply(new GeoCoordinatesUpdated($this->actorId, $coordinates));
164
    }
165
166
    /**
167
     * Import from UDB2.
168
     *
169
     * @param string $actorId
170
     *   The actor id.
171
     * @param string $cdbXml
172
     *   The cdb xml.
173
     * @param string $cdbXmlNamespaceUri
174
     *   The cdb xml namespace uri.
175
     *
176
     * @return Place
177
     */
178
    public static function importFromUDB2Actor(
179
        $actorId,
180
        $cdbXml,
181
        $cdbXmlNamespaceUri
182
    ) {
183
        $place = new static();
184
        $place->apply(
185
            new PlaceImportedFromUDB2(
186
                $actorId,
187
                $cdbXml,
188
                $cdbXmlNamespaceUri
189
            )
190
        );
191
192
        return $place;
193
    }
194
195
    /**
196
     * @param PlaceImportedFromUDB2 $placeImported
197
     */
198 View Code Duplication
    public function applyPlaceImportedFromUDB2(
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...
199
        PlaceImportedFromUDB2 $placeImported
200
    ) {
201
        $this->actorId = $placeImported->getActorId();
202
203
        $udb2Actor = ActorItemFactory::createActorFromCdbXml(
204
            $placeImported->getCdbXmlNamespaceUri(),
205
            $placeImported->getCdbXml()
206
        );
207
208
        $this->importWorkflowStatus($udb2Actor);
209
        $this->labels = LabelCollection::fromKeywords($udb2Actor->getKeywords(true));
210
    }
211
212
    /**
213
     * @param PlaceUpdatedFromUDB2 $placeUpdatedFromUDB2
214
     */
215 View Code Duplication
    public function applyPlaceUpdatedFromUDB2(
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...
216
        PlaceUpdatedFromUDB2 $placeUpdatedFromUDB2
217
    ) {
218
        $udb2Actor = ActorItemFactory::createActorFromCdbXml(
219
            $placeUpdatedFromUDB2->getCdbXmlNamespaceUri(),
220
            $placeUpdatedFromUDB2->getCdbXml()
221
        );
222
223
        $this->importWorkflowStatus($udb2Actor);
224
        $this->labels = LabelCollection::fromKeywords($udb2Actor->getKeywords(true));
225
    }
226
227
    /**
228
     * @inheritdoc
229
     */
230
    public function updateWithCdbXml($cdbXml, $cdbXmlNamespaceUri)
231
    {
232
        ActorItemFactory::createActorFromCdbXml($cdbXmlNamespaceUri, $cdbXml);
233
234
        $this->apply(
235
            new PlaceUpdatedFromUDB2(
236
                $this->actorId,
237
                $cdbXml,
238
                $cdbXmlNamespaceUri
239
            )
240
        );
241
    }
242
243
    /**
244
     * @param Label $label
245
     * @return LabelAdded
246
     */
247
    protected function createLabelAddedEvent(Label $label)
248
    {
249
        return new LabelAdded($this->actorId, $label);
250
    }
251
252
    /**
253
     * @param Label $label
254
     * @return LabelRemoved
255
     */
256
    protected function createLabelRemovedEvent(Label $label)
257
    {
258
        return new LabelRemoved($this->actorId, $label);
259
    }
260
261
    protected function createImageAddedEvent(Image $image)
262
    {
263
        return new ImageAdded($this->actorId, $image);
264
    }
265
266
    protected function createImageRemovedEvent(Image $image)
267
    {
268
        return new ImageRemoved($this->actorId, $image);
269
    }
270
271
    protected function createImageUpdatedEvent(
272
        AbstractUpdateImage $updateImageCommand
273
    ) {
274
        return new ImageUpdated(
275
            $this->actorId,
276
            $updateImageCommand->getMediaObjectId(),
277
            $updateImageCommand->getDescription(),
278
            $updateImageCommand->getCopyrightHolder()
279
        );
280
    }
281
282
    protected function createMainImageSelectedEvent(Image $image)
283
    {
284
        return new MainImageSelected($this->actorId, $image);
285
    }
286
287
    /**
288
     * @param Language $language
289
     * @param StringLiteral $title
290
     * @return TitleTranslated
291
     */
292
    protected function createTitleTranslatedEvent(Language $language, StringLiteral $title)
293
    {
294
        return new TitleTranslated($this->actorId, $language, $title);
295
    }
296
297
    /**
298
     * @param Language $language
299
     * @param StringLiteral $description
300
     * @return DescriptionTranslated
301
     */
302
    protected function createDescriptionTranslatedEvent(Language $language, StringLiteral $description)
303
    {
304
        return new DescriptionTranslated($this->actorId, $language, $description);
305
    }
306
307
    /**
308
     * @param string $description
309
     * @return DescriptionUpdated
310
     */
311
    protected function createDescriptionUpdatedEvent($description)
312
    {
313
        return new DescriptionUpdated($this->actorId, $description);
314
    }
315
316
    /**
317
     * @param string $typicalAgeRange
318
     * @return TypicalAgeRangeUpdated
319
     */
320
    protected function createTypicalAgeRangeUpdatedEvent($typicalAgeRange)
321
    {
322
        return new TypicalAgeRangeUpdated($this->actorId, $typicalAgeRange);
323
    }
324
325
    /**
326
     * @return TypicalAgeRangeDeleted
327
     */
328
    protected function createTypicalAgeRangeDeletedEvent()
329
    {
330
        return new TypicalAgeRangeDeleted($this->actorId);
331
    }
332
333
    /**
334
     * @param string $organizerId
335
     * @return OrganizerUpdated
336
     */
337
    protected function createOrganizerUpdatedEvent($organizerId)
338
    {
339
        return new OrganizerUpdated($this->actorId, $organizerId);
340
    }
341
342
    /**
343
     * @param string $organizerId
344
     * @return OrganizerDeleted
345
     */
346
    protected function createOrganizerDeletedEvent($organizerId)
347
    {
348
        return new OrganizerDeleted($this->actorId, $organizerId);
349
    }
350
351
    /**
352
     * @param ContactPoint $contactPoint
353
     * @return ContactPointUpdated
354
     */
355
    protected function createContactPointUpdatedEvent(ContactPoint $contactPoint)
356
    {
357
        return new ContactPointUpdated($this->actorId, $contactPoint);
358
    }
359
360
    /**
361
     * @param BookingInfo $bookingInfo
362
     * @return BookingInfoUpdated
363
     */
364
    protected function createBookingInfoUpdatedEvent(BookingInfo $bookingInfo)
365
    {
366
        return new BookingInfoUpdated($this->actorId, $bookingInfo);
367
    }
368
369
    /**
370
     * @param PriceInfo $priceInfo
371
     * @return PriceInfoUpdated
372
     */
373
    protected function createPriceInfoUpdatedEvent(PriceInfo $priceInfo)
374
    {
375
        return new PriceInfoUpdated($this->actorId, $priceInfo);
376
    }
377
378
    /**
379
     * @return PlaceDeleted
380
     */
381
    protected function createOfferDeletedEvent()
382
    {
383
        return new PlaceDeleted($this->actorId);
384
    }
385
386
    /**
387
     * @inheritDoc
388
     */
389
    protected function createPublishedEvent(\DateTimeInterface $publicationDate)
390
    {
391
        return new Published($this->actorId, $publicationDate);
392
    }
393
394
    /**
395
     * @inheritDoc
396
     */
397
    protected function createApprovedEvent()
398
    {
399
        return new Approved($this->actorId);
400
    }
401
402
    /**
403
     * @inheritDoc
404
     */
405
    protected function createRejectedEvent(StringLiteral $reason)
406
    {
407
        return new Rejected($this->actorId, $reason);
408
    }
409
410
    /**
411
     * @inheritDoc
412
     */
413
    protected function createFlaggedAsDuplicate()
414
    {
415
        return new FlaggedAsDuplicate($this->actorId);
416
    }
417
418
    /**
419
     * @inheritDoc
420
     */
421
    protected function createFlaggedAsInappropriate()
422
    {
423
        return new FlaggedAsInappropriate($this->actorId);
424
    }
425
426
    /**
427
     * @inheritDoc
428
     * @return ImagesImportedFromUDB2
429
     */
430
    protected function createImagesImportedFromUDB2(ImageCollection $images)
431
    {
432
        return new ImagesImportedFromUDB2($this->actorId, $images);
433
    }
434
435
    /**
436
     * @inheritDoc
437
     * @return ImagesUpdatedFromUDB2
438
     */
439
    protected function createImagesUpdatedFromUDB2(ImageCollection $images)
440
    {
441
        return new ImagesUpdatedFromUDB2($this->actorId, $images);
442
    }
443
}
444