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