Completed
Pull Request — master (#272)
by Luc
05:19
created

Place::importFromUDB2Event()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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