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\BookingInfoUpdated; |
11
|
|
|
use CultuurNet\UDB3\Event\Events\ContactPointUpdated; |
12
|
|
|
use CultuurNet\UDB3\Event\Events\DescriptionTranslated; |
13
|
|
|
use CultuurNet\UDB3\Event\Events\DescriptionUpdated; |
14
|
|
|
use CultuurNet\UDB3\Event\Events\EventCdbXMLInterface; |
15
|
|
|
use CultuurNet\UDB3\Event\Events\EventCreated; |
16
|
|
|
use CultuurNet\UDB3\Event\Events\EventCreatedFromCdbXml; |
17
|
|
|
use CultuurNet\UDB3\Event\Events\EventDeleted; |
18
|
|
|
use CultuurNet\UDB3\Event\Events\EventImportedFromUDB2; |
19
|
|
|
use CultuurNet\UDB3\Event\Events\EventUpdatedFromCdbXml; |
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\ImageUpdated; |
24
|
|
|
use CultuurNet\UDB3\Event\Events\LabelAdded; |
25
|
|
|
use CultuurNet\UDB3\Event\Events\LabelRemoved; |
26
|
|
|
use CultuurNet\UDB3\Event\Events\MainImageSelected; |
27
|
|
|
use CultuurNet\UDB3\Event\Events\MajorInfoUpdated; |
28
|
|
|
use CultuurNet\UDB3\Event\Events\Moderation\Approved; |
29
|
|
|
use CultuurNet\UDB3\Event\Events\Moderation\FlaggedAsDuplicate; |
30
|
|
|
use CultuurNet\UDB3\Event\Events\Moderation\FlaggedAsInappropriate; |
31
|
|
|
use CultuurNet\UDB3\Event\Events\Moderation\Published; |
32
|
|
|
use CultuurNet\UDB3\Event\Events\Moderation\Rejected; |
33
|
|
|
use CultuurNet\UDB3\Event\Events\OrganizerDeleted; |
34
|
|
|
use CultuurNet\UDB3\Event\Events\OrganizerUpdated; |
35
|
|
|
use CultuurNet\UDB3\Event\Events\PriceInfoUpdated; |
36
|
|
|
use CultuurNet\UDB3\Event\Events\TitleTranslated; |
37
|
|
|
use CultuurNet\UDB3\Event\Events\TypicalAgeRangeDeleted; |
38
|
|
|
use CultuurNet\UDB3\Event\Events\TypicalAgeRangeUpdated; |
39
|
|
|
use CultuurNet\UDB3\EventXmlString; |
40
|
|
|
use CultuurNet\UDB3\Label; |
41
|
|
|
use CultuurNet\UDB3\LabelCollection; |
42
|
|
|
use CultuurNet\UDB3\Language; |
43
|
|
|
use CultuurNet\UDB3\Location\Location; |
44
|
|
|
use CultuurNet\UDB3\Offer\Commands\Image\AbstractUpdateImage; |
45
|
|
|
use CultuurNet\UDB3\Offer\Offer; |
46
|
|
|
use CultuurNet\UDB3\Media\Image; |
47
|
|
|
use CultuurNet\UDB3\PriceInfo\PriceInfo; |
48
|
|
|
use CultuurNet\UDB3\Offer\WorkflowStatus; |
49
|
|
|
use CultuurNet\UDB3\Theme; |
50
|
|
|
use CultuurNet\UDB3\Title; |
51
|
|
|
use CultuurNet\UDB3\Translation; |
52
|
|
|
use ValueObjects\Identity\UUID; |
53
|
|
|
use ValueObjects\String\String as StringLiteral; |
54
|
|
|
|
55
|
|
|
class Event extends Offer implements UpdateableWithCdbXmlInterface |
56
|
|
|
{ |
57
|
|
|
protected $eventId; |
58
|
|
|
|
59
|
|
|
const MAIN_LANGUAGE_CODE = 'nl'; |
60
|
|
|
|
61
|
|
|
public function __construct() |
62
|
|
|
{ |
63
|
|
|
parent::__construct(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Factory method to create a new event. |
68
|
|
|
* |
69
|
|
|
* @param Title $title |
70
|
|
|
* @param EventType $eventType |
71
|
|
|
* @param Location $location |
72
|
|
|
* @param CalendarInterface $calendar |
73
|
|
|
* @param Theme|null $theme |
74
|
|
|
* @param \DateTimeImmutable|null $publicationDate |
75
|
|
|
* |
76
|
|
|
* @return Event |
77
|
|
|
*/ |
78
|
|
|
public static function create( |
79
|
|
|
$eventId, |
80
|
|
|
Title $title, |
81
|
|
|
EventType $eventType, |
82
|
|
|
Location $location, |
83
|
|
|
CalendarInterface $calendar, |
84
|
|
|
Theme $theme = null, |
85
|
|
|
\DateTimeImmutable $publicationDate = null |
86
|
|
|
) { |
87
|
|
|
if (!is_string($eventId)) { |
88
|
|
|
throw new \InvalidArgumentException( |
89
|
|
|
'Expected eventId to be a string, received ' . gettype($eventId) |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$event = new self(); |
94
|
|
|
|
95
|
|
|
$event->apply( |
96
|
|
|
new EventCreated( |
97
|
|
|
$eventId, |
98
|
|
|
$title, |
99
|
|
|
$eventType, |
100
|
|
|
$location, |
101
|
|
|
$calendar, |
102
|
|
|
$theme, |
103
|
|
|
$publicationDate |
104
|
|
|
) |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
return $event; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string $eventId |
112
|
|
|
* @param string $cdbXml |
113
|
|
|
* @param string $cdbXmlNamespaceUri |
114
|
|
|
* @return Event |
115
|
|
|
*/ |
116
|
|
|
public static function importFromUDB2( |
117
|
|
|
$eventId, |
118
|
|
|
$cdbXml, |
119
|
|
|
$cdbXmlNamespaceUri |
120
|
|
|
) { |
121
|
|
|
$event = new self(); |
122
|
|
|
$event->apply( |
123
|
|
|
new EventImportedFromUDB2( |
124
|
|
|
$eventId, |
125
|
|
|
$cdbXml, |
126
|
|
|
$cdbXmlNamespaceUri |
127
|
|
|
) |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
return $event; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param EventXmlString $xmlString |
135
|
|
|
* @param StringLiteral $eventId |
136
|
|
|
* @param StringLiteral $cdbXmlNamespaceUri |
137
|
|
|
* @return Event |
138
|
|
|
*/ |
139
|
|
|
public static function createFromCdbXml( |
140
|
|
|
StringLiteral $eventId, |
141
|
|
|
EventXmlString $xmlString, |
142
|
|
|
StringLiteral $cdbXmlNamespaceUri |
143
|
|
|
) { |
144
|
|
|
$event = new self(); |
145
|
|
|
$event->apply( |
146
|
|
|
new EventCreatedFromCdbXml( |
147
|
|
|
$eventId, |
148
|
|
|
$xmlString, |
149
|
|
|
$cdbXmlNamespaceUri |
150
|
|
|
) |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
return $event; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param StringLiteral $eventId |
158
|
|
|
* @param EventXmlString $xmlString |
159
|
|
|
* @param StringLiteral $cdbXmlNamespaceUri |
160
|
|
|
* @return Event |
161
|
|
|
*/ |
162
|
|
|
public function updateFromCdbXml( |
163
|
|
|
StringLiteral $eventId, |
164
|
|
|
EventXmlString $xmlString, |
165
|
|
|
StringLiteral $cdbXmlNamespaceUri |
166
|
|
|
) { |
167
|
|
|
$this->apply( |
168
|
|
|
new EventUpdatedFromCdbXml( |
169
|
|
|
$eventId, |
170
|
|
|
$xmlString, |
171
|
|
|
$cdbXmlNamespaceUri |
172
|
|
|
) |
173
|
|
|
); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* {@inheritdoc} |
178
|
|
|
*/ |
179
|
|
|
public function getAggregateRootId() |
180
|
|
|
{ |
181
|
|
|
return $this->eventId; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return UUID[] |
186
|
|
|
*/ |
187
|
|
|
public function getMediaObjects() |
188
|
|
|
{ |
189
|
|
|
return $this->mediaObjects; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
protected function applyEventCreated(EventCreated $eventCreated) |
193
|
|
|
{ |
194
|
|
|
$this->eventId = $eventCreated->getEventId(); |
195
|
|
|
$this->workflowStatus = WorkflowStatus::DRAFT(); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
protected function applyEventImportedFromUDB2( |
199
|
|
|
EventImportedFromUDB2 $eventImported |
200
|
|
|
) { |
201
|
|
|
$this->eventId = $eventImported->getEventId(); |
202
|
|
|
$this->setUDB2Data($eventImported); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param EventUpdatedFromUDB2 $eventUpdated |
207
|
|
|
*/ |
208
|
|
|
protected function applyEventUpdatedFromUDB2( |
209
|
|
|
EventUpdatedFromUDB2 $eventUpdated |
210
|
|
|
) { |
211
|
|
|
$this->setUDB2Data($eventUpdated); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param EventCdbXMLInterface $eventCdbXML |
216
|
|
|
*/ |
217
|
|
|
protected function setUDB2Data( |
218
|
|
|
EventCdbXMLInterface $eventCdbXML |
219
|
|
|
) { |
220
|
|
|
$udb2Event = EventItemFactory::createEventFromCdbXml( |
221
|
|
|
$eventCdbXML->getCdbXmlNamespaceUri(), |
222
|
|
|
$eventCdbXML->getCdbXml() |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
$this->importWorkflowStatus($udb2Event); |
226
|
|
|
$this->labels = LabelCollection::fromKeywords($udb2Event->getKeywords(true)); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Update the major info. |
231
|
|
|
* |
232
|
|
|
* @param Title $title |
233
|
|
|
* @param EventType $eventType |
234
|
|
|
* @param Location $location |
235
|
|
|
* @param CalendarInterface $calendar |
236
|
|
|
* @param type $theme |
237
|
|
|
*/ |
238
|
|
|
public function updateMajorInfo( |
239
|
|
|
Title $title, |
240
|
|
|
EventType $eventType, |
241
|
|
|
Location $location, |
242
|
|
|
CalendarInterface $calendar, |
243
|
|
|
$theme = null |
244
|
|
|
) { |
245
|
|
|
$this->apply(new MajorInfoUpdated($this->eventId, $title, $eventType, $location, $calendar, $theme)); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
protected function applyEventCreatedFromCdbXml( |
249
|
|
|
EventCreatedFromCdbXml $eventCreatedFromCdbXml |
250
|
|
|
) { |
251
|
|
|
$this->eventId = $eventCreatedFromCdbXml->getEventId()->toNative(); |
252
|
|
|
|
253
|
|
|
$udb2Event = EventItemFactory::createEventFromCdbXml( |
254
|
|
|
$eventCreatedFromCdbXml->getCdbXmlNamespaceUri(), |
255
|
|
|
$eventCreatedFromCdbXml->getEventXmlString()->toEventXmlString() |
256
|
|
|
); |
257
|
|
|
|
258
|
|
|
$this->labels = LabelCollection::fromKeywords($udb2Event->getKeywords(true)); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
protected function applyEventUpdatedFromCdbXml( |
262
|
|
|
EventUpdatedFromCdbXml $eventUpdatedFromCdbXml |
263
|
|
|
) { |
264
|
|
|
$this->eventId = $eventUpdatedFromCdbXml->getEventId()->toNative(); |
265
|
|
|
|
266
|
|
|
$udb2Event = EventItemFactory::createEventFromCdbXml( |
267
|
|
|
$eventUpdatedFromCdbXml->getCdbXmlNamespaceUri(), |
268
|
|
|
$eventUpdatedFromCdbXml->getEventXmlString()->toEventXmlString() |
269
|
|
|
); |
270
|
|
|
|
271
|
|
|
$this->labels = LabelCollection::fromKeywords($udb2Event->getKeywords(true)); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @inheritdoc |
276
|
|
|
*/ |
277
|
|
|
public function updateWithCdbXml($cdbXml, $cdbXmlNamespaceUri) |
278
|
|
|
{ |
279
|
|
|
$this->apply( |
280
|
|
|
new EventUpdatedFromUDB2( |
281
|
|
|
$this->eventId, |
282
|
|
|
$cdbXml, |
283
|
|
|
$cdbXmlNamespaceUri |
284
|
|
|
) |
285
|
|
|
); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @param Label $label |
290
|
|
|
* @return LabelAdded |
291
|
|
|
*/ |
292
|
|
|
protected function createLabelAddedEvent(Label $label) |
293
|
|
|
{ |
294
|
|
|
return new LabelAdded($this->eventId, $label); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @param Label $label |
299
|
|
|
* @return LabelRemoved |
300
|
|
|
*/ |
301
|
|
|
protected function createLabelRemovedEvent(Label $label) |
302
|
|
|
{ |
303
|
|
|
return new LabelRemoved($this->eventId, $label); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param Image $image |
308
|
|
|
* @return ImageAdded |
309
|
|
|
*/ |
310
|
|
|
protected function createImageAddedEvent(Image $image) |
311
|
|
|
{ |
312
|
|
|
return new ImageAdded($this->eventId, $image); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @param Image $image |
317
|
|
|
* @return ImageRemoved |
318
|
|
|
*/ |
319
|
|
|
protected function createImageRemovedEvent(Image $image) |
320
|
|
|
{ |
321
|
|
|
return new ImageRemoved($this->eventId, $image); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* @param AbstractUpdateImage $updateImageCommand |
326
|
|
|
* @return ImageUpdated |
327
|
|
|
*/ |
328
|
|
|
protected function createImageUpdatedEvent( |
329
|
|
|
AbstractUpdateImage $updateImageCommand |
330
|
|
|
) { |
331
|
|
|
return new ImageUpdated( |
332
|
|
|
$this->eventId, |
333
|
|
|
$updateImageCommand->getMediaObjectId(), |
334
|
|
|
$updateImageCommand->getDescription(), |
335
|
|
|
$updateImageCommand->getCopyrightHolder() |
336
|
|
|
); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* @param Image $image |
341
|
|
|
* @return MainImageSelected |
342
|
|
|
*/ |
343
|
|
|
protected function createMainImageSelectedEvent(Image $image) |
344
|
|
|
{ |
345
|
|
|
return new MainImageSelected($this->eventId, $image); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @param Language $language |
350
|
|
|
* @param StringLiteral $title |
351
|
|
|
* @return TitleTranslated |
352
|
|
|
*/ |
353
|
|
|
protected function createTitleTranslatedEvent(Language $language, StringLiteral $title) |
354
|
|
|
{ |
355
|
|
|
return new TitleTranslated($this->eventId, $language, $title); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @param Language $language |
360
|
|
|
* @param StringLiteral $description |
361
|
|
|
* @return DescriptionTranslated |
362
|
|
|
*/ |
363
|
|
|
protected function createDescriptionTranslatedEvent(Language $language, StringLiteral $description) |
364
|
|
|
{ |
365
|
|
|
return new DescriptionTranslated($this->eventId, $language, $description); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @param string $description |
370
|
|
|
* @return DescriptionUpdated |
371
|
|
|
*/ |
372
|
|
|
protected function createDescriptionUpdatedEvent($description) |
373
|
|
|
{ |
374
|
|
|
return new DescriptionUpdated($this->eventId, $description); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @param string $typicalAgeRange |
379
|
|
|
* @return TypicalAgeRangeUpdated |
380
|
|
|
*/ |
381
|
|
|
protected function createTypicalAgeRangeUpdatedEvent($typicalAgeRange) |
382
|
|
|
{ |
383
|
|
|
return new TypicalAgeRangeUpdated($this->eventId, $typicalAgeRange); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @return TypicalAgeRangeDeleted |
388
|
|
|
*/ |
389
|
|
|
protected function createTypicalAgeRangeDeletedEvent() |
390
|
|
|
{ |
391
|
|
|
return new TypicalAgeRangeDeleted($this->eventId); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @param string $organizerId |
396
|
|
|
* @return OrganizerUpdated |
397
|
|
|
*/ |
398
|
|
|
protected function createOrganizerUpdatedEvent($organizerId) |
399
|
|
|
{ |
400
|
|
|
return new OrganizerUpdated($this->eventId, $organizerId); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @param string $organizerId |
405
|
|
|
* @return OrganizerDeleted |
406
|
|
|
*/ |
407
|
|
|
protected function createOrganizerDeletedEvent($organizerId) |
408
|
|
|
{ |
409
|
|
|
return new OrganizerDeleted($this->eventId, $organizerId); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @param ContactPoint $contactPoint |
414
|
|
|
* @return ContactPointUpdated |
415
|
|
|
*/ |
416
|
|
|
protected function createContactPointUpdatedEvent(ContactPoint $contactPoint) |
417
|
|
|
{ |
418
|
|
|
return new ContactPointUpdated($this->eventId, $contactPoint); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @param BookingInfo $bookingInfo |
423
|
|
|
* @return BookingInfoUpdated |
424
|
|
|
*/ |
425
|
|
|
protected function createBookingInfoUpdatedEvent(BookingInfo $bookingInfo) |
426
|
|
|
{ |
427
|
|
|
return new BookingInfoUpdated($this->eventId, $bookingInfo); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @param PriceInfo $priceInfo |
432
|
|
|
* @return PriceInfoUpdated |
433
|
|
|
*/ |
434
|
|
|
protected function createPriceInfoUpdatedEvent(PriceInfo $priceInfo) |
435
|
|
|
{ |
436
|
|
|
return new PriceInfoUpdated($this->eventId, $priceInfo); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* @return EventDeleted |
441
|
|
|
*/ |
442
|
|
|
protected function createOfferDeletedEvent() |
443
|
|
|
{ |
444
|
|
|
return new EventDeleted($this->eventId); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* @inheritdoc |
449
|
|
|
*/ |
450
|
|
|
protected function createPublishedEvent(\DateTimeInterface $publicationDate) |
451
|
|
|
{ |
452
|
|
|
return new Published($this->eventId, $publicationDate); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* @inheritdoc |
457
|
|
|
*/ |
458
|
|
|
protected function createApprovedEvent() |
459
|
|
|
{ |
460
|
|
|
return new Approved($this->eventId); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* @inheritdoc |
465
|
|
|
*/ |
466
|
|
|
protected function createRejectedEvent(StringLiteral $reason) |
467
|
|
|
{ |
468
|
|
|
return new Rejected($this->eventId, $reason); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* @inheritDoc |
473
|
|
|
*/ |
474
|
|
|
protected function createFlaggedAsDuplicate() |
475
|
|
|
{ |
476
|
|
|
return new FlaggedAsDuplicate($this->eventId); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* @inheritDoc |
481
|
|
|
*/ |
482
|
|
|
protected function createFlaggedAsInappropriate() |
483
|
|
|
{ |
484
|
|
|
return new FlaggedAsInappropriate($this->eventId); |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
|