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