1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains \Cultuurnet\UDB3\Place\Place. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace CultuurNet\UDB3\Place; |
9
|
|
|
|
10
|
|
|
use Broadway\EventSourcing\EventSourcedAggregateRoot; |
11
|
|
|
use CultuurNet\UDB3\Address; |
12
|
|
|
use CultuurNet\UDB3\BookingInfo; |
13
|
|
|
use CultuurNet\UDB3\CalendarInterface; |
14
|
|
|
use CultuurNet\UDB3\Cdb\UpdateableWithCdbXmlInterface; |
15
|
|
|
use CultuurNet\UDB3\ContactPoint; |
16
|
|
|
use CultuurNet\UDB3\Event\EventType; |
17
|
|
|
use CultuurNet\UDB3\Media\Image; |
18
|
|
|
use CultuurNet\UDB3\Media\MediaObject; |
19
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateImage; |
20
|
|
|
use CultuurNet\UDB3\Place\Events\BookingInfoUpdated; |
21
|
|
|
use CultuurNet\UDB3\Place\Events\ContactPointUpdated; |
22
|
|
|
use CultuurNet\UDB3\Place\Events\DescriptionUpdated; |
23
|
|
|
use CultuurNet\UDB3\Place\Events\FacilitiesUpdated; |
24
|
|
|
use CultuurNet\UDB3\Place\Events\ImageAdded; |
25
|
|
|
use CultuurNet\UDB3\Place\Events\ImageDeleted; |
26
|
|
|
use CultuurNet\UDB3\Place\Events\ImageRemoved; |
27
|
|
|
use CultuurNet\UDB3\Place\Events\ImageUpdated; |
28
|
|
|
use CultuurNet\UDB3\Place\Events\MajorInfoUpdated; |
29
|
|
|
use CultuurNet\UDB3\Place\Events\OrganizerDeleted; |
30
|
|
|
use CultuurNet\UDB3\Place\Events\OrganizerUpdated; |
31
|
|
|
use CultuurNet\UDB3\Place\Events\PlaceCreated; |
32
|
|
|
use CultuurNet\UDB3\Place\Events\PlaceDeleted; |
33
|
|
|
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2; |
34
|
|
|
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2Event; |
35
|
|
|
use CultuurNet\UDB3\Place\Events\PlaceUpdatedFromUDB2; |
36
|
|
|
use CultuurNet\UDB3\Place\Events\TypicalAgeRangeDeleted; |
37
|
|
|
use CultuurNet\UDB3\Place\Events\TypicalAgeRangeUpdated; |
38
|
|
|
use CultuurNet\UDB3\Theme; |
39
|
|
|
use CultuurNet\UDB3\Title; |
40
|
|
|
use Symfony\Component\EventDispatcher\Event; |
41
|
|
|
use ValueObjects\String\String; |
42
|
|
|
|
43
|
|
|
class Place extends EventSourcedAggregateRoot implements UpdateableWithCdbXmlInterface |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* The actor id. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $actorId; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getAggregateRootId() |
56
|
|
|
{ |
57
|
|
|
return $this->actorId; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Factory method to create a new Place. |
62
|
|
|
* |
63
|
|
|
* @todo Refactor this method so it can be called create. Currently the |
64
|
|
|
* normal behavior for create is taken by the legacy udb2 logic. |
65
|
|
|
* The PlaceImportedFromUDB2 could be a superclass of Place. |
66
|
|
|
* |
67
|
|
|
* @param String $id |
68
|
|
|
* @param Title $title |
69
|
|
|
* @param EventType $eventType |
70
|
|
|
* @param Address $address |
71
|
|
|
* @param CalendarInterface $calendar |
72
|
|
|
* @param Theme/null $theme |
|
|
|
|
73
|
|
|
* |
74
|
|
|
* @return Event |
75
|
|
|
*/ |
76
|
|
|
public static function createPlace($id, Title $title, EventType $eventType, Address $address, CalendarInterface $calendar, Theme $theme = null) |
77
|
|
|
{ |
78
|
|
|
$place = new self(); |
79
|
|
|
$place->apply(new PlaceCreated($id, $title, $eventType, $address, $calendar, $theme)); |
80
|
|
|
|
81
|
|
|
return $place; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Apply the place created event. |
86
|
|
|
* @param PlaceCreate $placeCreated |
87
|
|
|
*/ |
88
|
|
|
protected function applyPlaceCreated(PlaceCreated $placeCreated) |
89
|
|
|
{ |
90
|
|
|
$this->actorId = $placeCreated->getPlaceId(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $description |
95
|
|
|
*/ |
96
|
|
|
public function updateDescription($description) |
97
|
|
|
{ |
98
|
|
|
$this->apply(new DescriptionUpdated($this->actorId, $description)); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param string $typicalAgeRange |
103
|
|
|
*/ |
104
|
|
|
public function updateTypicalAgeRange($typicalAgeRange) |
105
|
|
|
{ |
106
|
|
|
$this->apply(new TypicalAgeRangeUpdated($this->actorId, $typicalAgeRange)); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function deleteTypicalAgeRange() |
110
|
|
|
{ |
111
|
|
|
$this->apply(new TypicalAgeRangeDeleted($this->actorId)); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Handle an update command to update organizer. |
116
|
|
|
*/ |
117
|
|
|
public function updateOrganizer($organizerId) |
118
|
|
|
{ |
119
|
|
|
$this->apply(new OrganizerUpdated($this->actorId, $organizerId)); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Delete the given organizer. |
124
|
|
|
* |
125
|
|
|
* @param string $organizerId |
126
|
|
|
*/ |
127
|
|
|
public function deleteOrganizer($organizerId) |
128
|
|
|
{ |
129
|
|
|
$this->apply(new OrganizerDeleted($this->actorId, $organizerId)); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Updated the contact point. |
134
|
|
|
* |
135
|
|
|
* @param ContactPoint $contactPoint |
136
|
|
|
*/ |
137
|
|
|
public function updateContactPoint(ContactPoint $contactPoint) |
138
|
|
|
{ |
139
|
|
|
$this->apply(new ContactPointUpdated($this->actorId, $contactPoint)); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Updated the booking info. |
144
|
|
|
* |
145
|
|
|
* @param BookingInfo $bookingInfo |
146
|
|
|
*/ |
147
|
|
|
public function updateBookingInfo(BookingInfo $bookingInfo) |
148
|
|
|
{ |
149
|
|
|
$this->apply(new BookingInfoUpdated($this->actorId, $bookingInfo)); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Update the facilities. |
154
|
|
|
* |
155
|
|
|
* @param array $facilities |
156
|
|
|
*/ |
157
|
|
|
public function updateFacilities(array $facilities) |
158
|
|
|
{ |
159
|
|
|
$this->apply(new FacilitiesUpdated($this->actorId, $facilities)); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Add a new image. |
164
|
|
|
* |
165
|
|
|
* @param Image $image |
166
|
|
|
*/ |
167
|
|
|
public function addImage(Image $image) |
168
|
|
|
{ |
169
|
|
|
$this->apply(new ImageAdded($this->actorId, $image)); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param UpdateImage $updateImageCommand |
174
|
|
|
*/ |
175
|
|
|
public function updateImage(UpdateImage $updateImageCommand) |
176
|
|
|
{ |
177
|
|
|
$this->apply(new ImageUpdated( |
178
|
|
|
$updateImageCommand->getItemId(), |
179
|
|
|
$updateImageCommand->getMediaObjectId(), |
180
|
|
|
$updateImageCommand->getDescription(), |
181
|
|
|
$updateImageCommand->getCopyrightHolder() |
182
|
|
|
)); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Remove an image. |
187
|
|
|
* |
188
|
|
|
* @param Image $image |
189
|
|
|
*/ |
190
|
|
|
public function removeImage(Image $image) |
191
|
|
|
{ |
192
|
|
|
$this->apply(new ImageRemoved($this->actorId, $image)); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Update the major info. |
197
|
|
|
* |
198
|
|
|
* @param Title $title |
199
|
|
|
* @param EventType $eventType |
200
|
|
|
* @param Address $address |
201
|
|
|
* @param CalendarInterface $calendar |
202
|
|
|
* @param type $theme |
203
|
|
|
*/ |
204
|
|
|
public function updateMajorInfo(Title $title, EventType $eventType, Address $address, CalendarInterface $calendar, $theme = null) |
205
|
|
|
{ |
206
|
|
|
$this->apply(new MajorInfoUpdated($this->actorId, $title, $eventType, $address, $calendar, $theme)); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Delete this item. |
211
|
|
|
*/ |
212
|
|
|
public function deletePlace() |
213
|
|
|
{ |
214
|
|
|
$this->apply(new PlaceDeleted($this->actorId)); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Import from UDB2. |
219
|
|
|
* |
220
|
|
|
* @param string $actorId |
221
|
|
|
* The actor id. |
222
|
|
|
* @param string $cdbXml |
223
|
|
|
* The cdb xml. |
224
|
|
|
* @param string $cdbXmlNamespaceUri |
225
|
|
|
* The cdb xml namespace uri. |
226
|
|
|
* |
227
|
|
|
* @return Actor |
228
|
|
|
* The actor. |
229
|
|
|
*/ |
230
|
|
|
public static function importFromUDB2Actor( |
231
|
|
|
$actorId, |
232
|
|
|
$cdbXml, |
233
|
|
|
$cdbXmlNamespaceUri |
234
|
|
|
) { |
235
|
|
|
$place = new static(); |
236
|
|
|
$place->apply( |
237
|
|
|
new PlaceImportedFromUDB2( |
238
|
|
|
$actorId, |
239
|
|
|
$cdbXml, |
240
|
|
|
$cdbXmlNamespaceUri |
241
|
|
|
) |
242
|
|
|
); |
243
|
|
|
|
244
|
|
|
return $place; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Import from UDB2. |
249
|
|
|
* |
250
|
|
|
* @param string $placeId |
251
|
|
|
* The actor id. |
252
|
|
|
* @param string $cdbXml |
253
|
|
|
* The cdb xml. |
254
|
|
|
* @param string $cdbXmlNamespaceUri |
255
|
|
|
* The cdb xml namespace uri. |
256
|
|
|
* |
257
|
|
|
* @return Actor |
258
|
|
|
* The actor. |
259
|
|
|
*/ |
260
|
|
|
public static function importFromUDB2Event( |
261
|
|
|
$placeId, |
262
|
|
|
$cdbXml, |
263
|
|
|
$cdbXmlNamespaceUri |
264
|
|
|
) { |
265
|
|
|
$place = new static(); |
266
|
|
|
$place->apply( |
267
|
|
|
new PlaceImportedFromUDB2Event( |
268
|
|
|
$placeId, |
269
|
|
|
$cdbXml, |
270
|
|
|
$cdbXmlNamespaceUri |
271
|
|
|
) |
272
|
|
|
); |
273
|
|
|
|
274
|
|
|
return $place; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function applyPlaceImportedFromUDB2( |
278
|
|
|
PlaceImportedFromUDB2 $placeImported |
279
|
|
|
) { |
280
|
|
|
$this->actorId = $placeImported->getActorId(); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function applyPlaceImportedFromUDB2Event( |
284
|
|
|
PlaceImportedFromUDB2Event $placeImported |
285
|
|
|
) { |
286
|
|
|
$this->actorId = $placeImported->getActorId(); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @inheritdoc |
291
|
|
|
*/ |
292
|
|
|
public function updateWithCdbXml($cdbXml, $cdbXmlNamespaceUri) |
293
|
|
|
{ |
294
|
|
|
$this->apply( |
295
|
|
|
new PlaceUpdatedFromUDB2( |
296
|
|
|
$this->actorId, |
297
|
|
|
$cdbXml, |
298
|
|
|
$cdbXmlNamespaceUri |
299
|
|
|
) |
300
|
|
|
); |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.