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