1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Offer; |
4
|
|
|
|
5
|
|
|
use Broadway\CommandHandling\CommandBusInterface; |
6
|
|
|
use Broadway\UuidGenerator\UuidGeneratorInterface; |
7
|
|
|
use CultuurNet\UDB3\BookingInfo; |
8
|
|
|
use CultuurNet\UDB3\Calendar; |
9
|
|
|
use CultuurNet\UDB3\ContactPoint; |
10
|
|
|
use CultuurNet\UDB3\Description; |
11
|
|
|
use CultuurNet\UDB3\EntityNotFoundException; |
12
|
|
|
use CultuurNet\UDB3\Event\ReadModel\DocumentGoneException; |
13
|
|
|
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface; |
14
|
|
|
use CultuurNet\UDB3\Label; |
15
|
|
|
use CultuurNet\UDB3\Label\LabelServiceInterface; |
16
|
|
|
use CultuurNet\UDB3\Label\ValueObjects\LabelName; |
17
|
|
|
use CultuurNet\UDB3\Language; |
18
|
|
|
use CultuurNet\UDB3\Media\Image; |
19
|
|
|
use CultuurNet\UDB3\Offer\Commands\OfferCommandFactoryInterface; |
20
|
|
|
use CultuurNet\UDB3\PriceInfo\PriceInfo; |
21
|
|
|
use ValueObjects\StringLiteral\StringLiteral; |
22
|
|
|
|
23
|
|
|
class DefaultOfferEditingService implements OfferEditingServiceInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var CommandBusInterface |
27
|
|
|
*/ |
28
|
|
|
protected $commandBus; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var UuidGeneratorInterface |
32
|
|
|
*/ |
33
|
|
|
protected $uuidGenerator; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var DocumentRepositoryInterface |
37
|
|
|
*/ |
38
|
|
|
protected $readRepository; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var OfferCommandFactoryInterface |
42
|
|
|
*/ |
43
|
|
|
protected $commandFactory; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var LabelServiceInterface |
47
|
|
|
*/ |
48
|
|
|
private $labelService; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var \DateTimeImmutable|null |
52
|
|
|
*/ |
53
|
|
|
protected $publicationDate; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var TypeResolverInterface |
57
|
|
|
*/ |
58
|
|
|
protected $typeResolver; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var ThemeResolverInterface |
62
|
|
|
*/ |
63
|
|
|
protected $themeResolver; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param CommandBusInterface $commandBus |
67
|
|
|
* @param UuidGeneratorInterface $uuidGenerator |
68
|
|
|
* @param DocumentRepositoryInterface $readRepository |
69
|
|
|
* @param OfferCommandFactoryInterface $commandFactory |
70
|
|
|
* @param LabelServiceInterface $labelService |
71
|
|
|
* @param TypeResolverInterface $typeResolver |
72
|
|
|
* @param ThemeResolverInterface $themeResolver |
73
|
|
|
*/ |
74
|
|
|
public function __construct( |
75
|
|
|
CommandBusInterface $commandBus, |
76
|
|
|
UuidGeneratorInterface $uuidGenerator, |
77
|
|
|
DocumentRepositoryInterface $readRepository, |
78
|
|
|
OfferCommandFactoryInterface $commandFactory, |
79
|
|
|
LabelServiceInterface $labelService, |
80
|
|
|
TypeResolverInterface $typeResolver, |
81
|
|
|
ThemeResolverInterface $themeResolver |
82
|
|
|
) { |
83
|
|
|
$this->commandBus = $commandBus; |
84
|
|
|
$this->uuidGenerator = $uuidGenerator; |
85
|
|
|
$this->readRepository = $readRepository; |
86
|
|
|
$this->commandFactory = $commandFactory; |
87
|
|
|
$this->labelService = $labelService; |
88
|
|
|
$this->typeResolver = $typeResolver; |
89
|
|
|
$this->themeResolver = $themeResolver; |
90
|
|
|
$this->publicationDate = null; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param \DateTimeImmutable $publicationDate |
95
|
|
|
* @return static |
96
|
|
|
*/ |
97
|
|
|
public function withFixedPublicationDateForNewOffers( |
98
|
|
|
\DateTimeImmutable $publicationDate |
99
|
|
|
) { |
100
|
|
|
$c = clone $this; |
101
|
|
|
$c->publicationDate = $publicationDate; |
102
|
|
|
return $c; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param $id |
107
|
|
|
* @param Label $label |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function addLabel($id, Label $label) |
111
|
|
|
{ |
112
|
|
|
$this->guardId($id); |
113
|
|
|
|
114
|
|
|
$this->labelService->createLabelAggregateIfNew( |
115
|
|
|
new LabelName((string) $label), |
116
|
|
|
$label->isVisible() |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
return $this->commandBus->dispatch( |
120
|
|
|
$this->commandFactory->createAddLabelCommand( |
121
|
|
|
$id, |
122
|
|
|
$label |
123
|
|
|
) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param $id |
129
|
|
|
* @param Label $label |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function removeLabel($id, Label $label) |
133
|
|
|
{ |
134
|
|
|
$this->guardId($id); |
135
|
|
|
|
136
|
|
|
return $this->commandBus->dispatch( |
137
|
|
|
$this->commandFactory->createRemoveLabelCommand( |
138
|
|
|
$id, |
139
|
|
|
$label |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param string $id |
146
|
|
|
* @param StringLiteral $typeId |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
|
|
public function updateType($id, StringLiteral $typeId) |
150
|
|
|
{ |
151
|
|
|
$this->guardId($id); |
152
|
|
|
$type = $this->typeResolver->byId($typeId); |
153
|
|
|
|
154
|
|
|
return $this->commandBus->dispatch( |
155
|
|
|
$this->commandFactory->createUpdateTypeCommand($id, $type) |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param string $id |
161
|
|
|
* @param StringLiteral $themeId |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
public function updateTheme($id, StringLiteral $themeId) |
165
|
|
|
{ |
166
|
|
|
$this->guardId($id); |
167
|
|
|
$theme = $this->themeResolver->byId($themeId); |
168
|
|
|
|
169
|
|
|
return $this->commandBus->dispatch( |
170
|
|
|
$this->commandFactory->createUpdateThemeCommand($id, $theme) |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param string $id |
176
|
|
|
* @param array $facilities |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
public function updateFacilities($id, array $facilities) |
180
|
|
|
{ |
181
|
|
|
$this->guardId($id); |
182
|
|
|
|
183
|
|
|
return $this->commandBus->dispatch( |
184
|
|
|
$this->commandFactory->createUpdateFacilitiesCommand($id, $facilities) |
185
|
|
|
); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param $id |
190
|
|
|
* @param Language $language |
191
|
|
|
* @param StringLiteral $title |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
public function updateTitle($id, Language $language, StringLiteral $title) |
195
|
|
|
{ |
196
|
|
|
$this->guardId($id); |
197
|
|
|
|
198
|
|
|
return $this->commandBus->dispatch( |
199
|
|
|
$this->commandFactory->createUpdateTitleCommand( |
200
|
|
|
$id, |
201
|
|
|
$language, |
202
|
|
|
$title |
203
|
|
|
) |
204
|
|
|
); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param $id |
209
|
|
|
* @param Language $language |
210
|
|
|
* @param Description $description |
211
|
|
|
* @return string |
212
|
|
|
*/ |
213
|
|
|
public function updateDescription($id, Language $language, Description $description) |
214
|
|
|
{ |
215
|
|
|
$this->guardId($id); |
216
|
|
|
|
217
|
|
|
return $this->commandBus->dispatch( |
218
|
|
|
$this->commandFactory->createUpdateDescriptionCommand( |
219
|
|
|
$id, |
220
|
|
|
$language, |
221
|
|
|
$description |
222
|
|
|
) |
223
|
|
|
); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @inheritdoc |
228
|
|
|
*/ |
229
|
|
|
public function updateCalendar($id, Calendar $calendar) |
230
|
|
|
{ |
231
|
|
|
$this->guardId($id); |
232
|
|
|
|
233
|
|
|
return $this->commandBus->dispatch( |
234
|
|
|
$this->commandFactory->createUpdateCalendarCommand( |
235
|
|
|
$id, |
236
|
|
|
$calendar |
237
|
|
|
) |
238
|
|
|
); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @param string $id |
243
|
|
|
* @param Image $image |
244
|
|
|
* @return string |
245
|
|
|
*/ |
246
|
|
|
public function addImage($id, Image $image) |
247
|
|
|
{ |
248
|
|
|
$this->guardId($id); |
249
|
|
|
|
250
|
|
|
return $this->commandBus->dispatch( |
251
|
|
|
$this->commandFactory->createAddImageCommand($id, $image) |
252
|
|
|
); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @param string $id |
257
|
|
|
* @param Image $image |
258
|
|
|
* @param StringLiteral $description |
259
|
|
|
* @param StringLiteral $copyrightHolder |
260
|
|
|
* @return string |
261
|
|
|
*/ |
262
|
|
|
public function updateImage( |
263
|
|
|
$id, |
264
|
|
|
Image $image, |
265
|
|
|
StringLiteral $description, |
266
|
|
|
StringLiteral $copyrightHolder |
267
|
|
|
) { |
268
|
|
|
$this->guardId($id); |
269
|
|
|
|
270
|
|
|
return $this->commandBus->dispatch( |
271
|
|
|
$this->commandFactory->createUpdateImageCommand( |
272
|
|
|
$id, |
273
|
|
|
$image->getMediaObjectId(), |
274
|
|
|
$description, |
275
|
|
|
$copyrightHolder |
276
|
|
|
) |
277
|
|
|
); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @param $id |
282
|
|
|
* Id of the offer to remove the image from. |
283
|
|
|
* |
284
|
|
|
* @param Image $image |
285
|
|
|
* The image that should be removed. |
286
|
|
|
* |
287
|
|
|
* @return string |
288
|
|
|
*/ |
289
|
|
|
public function removeImage($id, Image $image) |
290
|
|
|
{ |
291
|
|
|
$this->guardId($id); |
292
|
|
|
|
293
|
|
|
return $this->commandBus->dispatch( |
294
|
|
|
$this->commandFactory->createRemoveImageCommand($id, $image) |
295
|
|
|
); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @param $id |
300
|
|
|
* @param Image $image |
301
|
|
|
* @return string |
302
|
|
|
*/ |
303
|
|
|
public function selectMainImage($id, Image $image) |
304
|
|
|
{ |
305
|
|
|
$this->guardId($id); |
306
|
|
|
|
307
|
|
|
return $this->commandBus->dispatch( |
308
|
|
|
$this->commandFactory->createSelectMainImageCommand($id, $image) |
309
|
|
|
); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @param string $id |
314
|
|
|
* @param AgeRange $ageRange |
315
|
|
|
* @return string |
316
|
|
|
*/ |
317
|
|
|
public function updateTypicalAgeRange($id, AgeRange $ageRange) |
318
|
|
|
{ |
319
|
|
|
$this->guardId($id); |
320
|
|
|
|
321
|
|
|
return $this->commandBus->dispatch( |
322
|
|
|
$this->commandFactory->createUpdateTypicalAgeRangeCommand($id, $ageRange) |
323
|
|
|
); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @param string $id |
328
|
|
|
* @return string |
329
|
|
|
*/ |
330
|
|
|
public function deleteTypicalAgeRange($id) |
331
|
|
|
{ |
332
|
|
|
$this->guardId($id); |
333
|
|
|
|
334
|
|
|
return $this->commandBus->dispatch( |
335
|
|
|
$this->commandFactory->createDeleteTypicalAgeRangeCommand($id) |
336
|
|
|
); |
337
|
|
|
|
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @param string $id |
342
|
|
|
* @param string $organizerId |
343
|
|
|
* @return string |
344
|
|
|
*/ |
345
|
|
|
public function updateOrganizer($id, $organizerId) |
346
|
|
|
{ |
347
|
|
|
$this->guardId($id); |
348
|
|
|
|
349
|
|
|
return $this->commandBus->dispatch( |
350
|
|
|
$this->commandFactory->createUpdateOrganizerCommand($id, $organizerId) |
351
|
|
|
); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @param string $id |
356
|
|
|
* @param string $organizerId |
357
|
|
|
* @return string |
358
|
|
|
*/ |
359
|
|
|
public function deleteOrganizer($id, $organizerId) |
360
|
|
|
{ |
361
|
|
|
$this->guardId($id); |
362
|
|
|
|
363
|
|
|
return $this->commandBus->dispatch( |
364
|
|
|
$this->commandFactory->createDeleteOrganizerCommand($id, $organizerId) |
365
|
|
|
); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @param string $id |
370
|
|
|
* @param ContactPoint $contactPoint |
371
|
|
|
* @return string |
372
|
|
|
*/ |
373
|
|
|
public function updateContactPoint($id, ContactPoint $contactPoint) |
374
|
|
|
{ |
375
|
|
|
$this->guardId($id); |
376
|
|
|
|
377
|
|
|
return $this->commandBus->dispatch( |
378
|
|
|
$this->commandFactory->createUpdateContactPointCommand($id, $contactPoint) |
379
|
|
|
); |
380
|
|
|
|
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @param string $id |
385
|
|
|
* @param BookingInfo $bookingInfo |
386
|
|
|
* @return string |
387
|
|
|
*/ |
388
|
|
|
public function updateBookingInfo($id, BookingInfo $bookingInfo) |
389
|
|
|
{ |
390
|
|
|
$this->guardId($id); |
391
|
|
|
|
392
|
|
|
return $this->commandBus->dispatch( |
393
|
|
|
$this->commandFactory->createUpdateBookingInfoCommand($id, $bookingInfo) |
394
|
|
|
); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @param $id |
399
|
|
|
* @param PriceInfo $priceInfo |
400
|
|
|
*/ |
401
|
|
|
public function updatePriceInfo($id, PriceInfo $priceInfo) |
402
|
|
|
{ |
403
|
|
|
$this->guardId($id); |
404
|
|
|
|
405
|
|
|
return $this->commandBus->dispatch( |
406
|
|
|
$this->commandFactory->createUpdatePriceInfoCommand($id, $priceInfo) |
407
|
|
|
); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* @param string $id |
412
|
|
|
* @return string |
413
|
|
|
*/ |
414
|
|
|
public function delete($id) |
415
|
|
|
{ |
416
|
|
|
return $this->commandBus->dispatch( |
417
|
|
|
$this->commandFactory->createDeleteOfferCommand($id) |
418
|
|
|
); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @param string $id |
423
|
|
|
* |
424
|
|
|
* @throws EntityNotFoundException|DocumentGoneException |
425
|
|
|
*/ |
426
|
|
|
public function guardId($id) |
427
|
|
|
{ |
428
|
|
|
$offer = $this->readRepository->get($id); |
429
|
|
|
|
430
|
|
|
if (is_null($offer)) { |
431
|
|
|
throw new EntityNotFoundException( |
432
|
|
|
sprintf('Offer with id: %s not found.', $id) |
433
|
|
|
); |
434
|
|
|
} |
435
|
|
|
} |
436
|
|
|
} |
437
|
|
|
|