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\Event\ReadModel\DocumentRepositoryInterface; |
12
|
|
|
use CultuurNet\UDB3\Label; |
13
|
|
|
use CultuurNet\UDB3\Label\LabelServiceInterface; |
14
|
|
|
use CultuurNet\UDB3\Label\ValueObjects\LabelName; |
15
|
|
|
use CultuurNet\UDB3\Language; |
16
|
|
|
use CultuurNet\UDB3\Media\Image; |
17
|
|
|
use CultuurNet\UDB3\Offer\Commands\OfferCommandFactoryInterface; |
18
|
|
|
use CultuurNet\UDB3\PriceInfo\PriceInfo; |
19
|
|
|
use ValueObjects\StringLiteral\StringLiteral; |
20
|
|
|
|
21
|
|
|
class DefaultOfferEditingService implements OfferEditingServiceInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var CommandBusInterface |
25
|
|
|
*/ |
26
|
|
|
protected $commandBus; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var UuidGeneratorInterface |
30
|
|
|
*/ |
31
|
|
|
protected $uuidGenerator; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var DocumentRepositoryInterface |
35
|
|
|
*/ |
36
|
|
|
protected $readRepository; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var OfferCommandFactoryInterface |
40
|
|
|
*/ |
41
|
|
|
protected $commandFactory; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var LabelServiceInterface |
45
|
|
|
*/ |
46
|
|
|
private $labelService; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var \DateTimeImmutable|null |
50
|
|
|
*/ |
51
|
|
|
protected $publicationDate; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param CommandBusInterface $commandBus |
55
|
|
|
* @param UuidGeneratorInterface $uuidGenerator |
56
|
|
|
* @param DocumentRepositoryInterface $readRepository |
57
|
|
|
* @param OfferCommandFactoryInterface $commandFactory |
58
|
|
|
* @param LabelServiceInterface $labelService |
59
|
|
|
*/ |
60
|
|
|
public function __construct( |
61
|
|
|
CommandBusInterface $commandBus, |
62
|
|
|
UuidGeneratorInterface $uuidGenerator, |
63
|
|
|
DocumentRepositoryInterface $readRepository, |
64
|
|
|
OfferCommandFactoryInterface $commandFactory, |
65
|
|
|
LabelServiceInterface $labelService |
66
|
|
|
) { |
67
|
|
|
$this->commandBus = $commandBus; |
68
|
|
|
$this->uuidGenerator = $uuidGenerator; |
69
|
|
|
$this->readRepository = $readRepository; |
70
|
|
|
$this->commandFactory = $commandFactory; |
71
|
|
|
$this->labelService = $labelService; |
72
|
|
|
$this->publicationDate = null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param \DateTimeImmutable $publicationDate |
77
|
|
|
* @return static |
78
|
|
|
*/ |
79
|
|
|
public function withFixedPublicationDateForNewOffers( |
80
|
|
|
\DateTimeImmutable $publicationDate |
81
|
|
|
) { |
82
|
|
|
$c = clone $this; |
83
|
|
|
$c->publicationDate = $publicationDate; |
84
|
|
|
return $c; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param $id |
89
|
|
|
* @param Label $label |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function addLabel($id, Label $label) |
93
|
|
|
{ |
94
|
|
|
$this->guardId($id); |
95
|
|
|
|
96
|
|
|
$this->labelService->createLabelAggregateIfNew( |
97
|
|
|
new LabelName((string) $label), |
98
|
|
|
$label->isVisible() |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
return $this->commandBus->dispatch( |
102
|
|
|
$this->commandFactory->createAddLabelCommand( |
103
|
|
|
$id, |
104
|
|
|
$label |
105
|
|
|
) |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param $id |
111
|
|
|
* @param Label $label |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function removeLabel($id, Label $label) |
115
|
|
|
{ |
116
|
|
|
$this->guardId($id); |
117
|
|
|
|
118
|
|
|
return $this->commandBus->dispatch( |
119
|
|
|
$this->commandFactory->createRemoveLabelCommand( |
120
|
|
|
$id, |
121
|
|
|
$label |
122
|
|
|
) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param $id |
128
|
|
|
* @param Language $language |
129
|
|
|
* @param StringLiteral $title |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
public function translateTitle($id, Language $language, StringLiteral $title) |
133
|
|
|
{ |
134
|
|
|
$this->guardId($id); |
135
|
|
|
|
136
|
|
|
return $this->commandBus->dispatch( |
137
|
|
|
$this->commandFactory->createTranslateTitleCommand( |
138
|
|
|
$id, |
139
|
|
|
$language, |
140
|
|
|
$title |
141
|
|
|
) |
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param $id |
147
|
|
|
* @param Language $language |
148
|
|
|
* @param Description $description |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
|
|
public function updateDescription($id, Language $language, Description $description) |
152
|
|
|
{ |
153
|
|
|
$this->guardId($id); |
154
|
|
|
|
155
|
|
|
return $this->commandBus->dispatch( |
156
|
|
|
$this->commandFactory->createUpdateDescriptionCommand( |
157
|
|
|
$id, |
158
|
|
|
$language, |
159
|
|
|
$description |
160
|
|
|
) |
161
|
|
|
); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @inheritdoc |
166
|
|
|
*/ |
167
|
|
|
public function updateCalendar($id, Calendar $calendar) |
168
|
|
|
{ |
169
|
|
|
$this->guardId($id); |
170
|
|
|
|
171
|
|
|
return $this->commandBus->dispatch( |
172
|
|
|
$this->commandFactory->createUpdateCalendarCommand( |
173
|
|
|
$id, |
174
|
|
|
$calendar |
175
|
|
|
) |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $id |
181
|
|
|
* @param Image $image |
182
|
|
|
* @return string |
183
|
|
|
*/ |
184
|
|
|
public function addImage($id, Image $image) |
185
|
|
|
{ |
186
|
|
|
$this->guardId($id); |
187
|
|
|
|
188
|
|
|
return $this->commandBus->dispatch( |
189
|
|
|
$this->commandFactory->createAddImageCommand($id, $image) |
190
|
|
|
); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string $id |
195
|
|
|
* @param Image $image |
196
|
|
|
* @param StringLiteral $description |
197
|
|
|
* @param StringLiteral $copyrightHolder |
198
|
|
|
* @return string |
199
|
|
|
*/ |
200
|
|
|
public function updateImage( |
201
|
|
|
$id, |
202
|
|
|
Image $image, |
203
|
|
|
StringLiteral $description, |
204
|
|
|
StringLiteral $copyrightHolder |
205
|
|
|
) { |
206
|
|
|
$this->guardId($id); |
207
|
|
|
|
208
|
|
|
return $this->commandBus->dispatch( |
209
|
|
|
$this->commandFactory->createUpdateImageCommand( |
210
|
|
|
$id, |
211
|
|
|
$image->getMediaObjectId(), |
212
|
|
|
$description, |
213
|
|
|
$copyrightHolder |
214
|
|
|
) |
215
|
|
|
); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param $id |
220
|
|
|
* Id of the offer to remove the image from. |
221
|
|
|
* |
222
|
|
|
* @param Image $image |
223
|
|
|
* The image that should be removed. |
224
|
|
|
* |
225
|
|
|
* @return string |
226
|
|
|
*/ |
227
|
|
|
public function removeImage($id, Image $image) |
228
|
|
|
{ |
229
|
|
|
$this->guardId($id); |
230
|
|
|
|
231
|
|
|
return $this->commandBus->dispatch( |
232
|
|
|
$this->commandFactory->createRemoveImageCommand($id, $image) |
233
|
|
|
); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @param $id |
238
|
|
|
* @param Image $image |
239
|
|
|
* @return string |
240
|
|
|
*/ |
241
|
|
|
public function selectMainImage($id, Image $image) |
242
|
|
|
{ |
243
|
|
|
$this->guardId($id); |
244
|
|
|
|
245
|
|
|
return $this->commandBus->dispatch( |
246
|
|
|
$this->commandFactory->createSelectMainImageCommand($id, $image) |
247
|
|
|
); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @param string $id |
252
|
|
|
* @param AgeRange $ageRange |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
public function updateTypicalAgeRange($id, AgeRange $ageRange) |
256
|
|
|
{ |
257
|
|
|
$this->guardId($id); |
258
|
|
|
|
259
|
|
|
return $this->commandBus->dispatch( |
260
|
|
|
$this->commandFactory->createUpdateTypicalAgeRangeCommand($id, $ageRange) |
261
|
|
|
); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @param string $id |
266
|
|
|
* @return string |
267
|
|
|
*/ |
268
|
|
|
public function deleteTypicalAgeRange($id) |
269
|
|
|
{ |
270
|
|
|
$this->guardId($id); |
271
|
|
|
|
272
|
|
|
return $this->commandBus->dispatch( |
273
|
|
|
$this->commandFactory->createDeleteTypicalAgeRangeCommand($id) |
274
|
|
|
); |
275
|
|
|
|
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param string $id |
280
|
|
|
* @param string $organizerId |
281
|
|
|
* @return string |
282
|
|
|
*/ |
283
|
|
|
public function updateOrganizer($id, $organizerId) |
284
|
|
|
{ |
285
|
|
|
$this->guardId($id); |
286
|
|
|
|
287
|
|
|
return $this->commandBus->dispatch( |
288
|
|
|
$this->commandFactory->createUpdateOrganizerCommand($id, $organizerId) |
289
|
|
|
); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @param string $id |
294
|
|
|
* @param string $organizerId |
295
|
|
|
* @return string |
296
|
|
|
*/ |
297
|
|
|
public function deleteOrganizer($id, $organizerId) |
298
|
|
|
{ |
299
|
|
|
$this->guardId($id); |
300
|
|
|
|
301
|
|
|
return $this->commandBus->dispatch( |
302
|
|
|
$this->commandFactory->createDeleteOrganizerCommand($id, $organizerId) |
303
|
|
|
); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param string $id |
308
|
|
|
* @param ContactPoint $contactPoint |
309
|
|
|
* @return string |
310
|
|
|
*/ |
311
|
|
|
public function updateContactPoint($id, ContactPoint $contactPoint) |
312
|
|
|
{ |
313
|
|
|
$this->guardId($id); |
314
|
|
|
|
315
|
|
|
return $this->commandBus->dispatch( |
316
|
|
|
$this->commandFactory->createUpdateContactPointCommand($id, $contactPoint) |
317
|
|
|
); |
318
|
|
|
|
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @param string $id |
323
|
|
|
* @param BookingInfo $bookingInfo |
324
|
|
|
* @return string |
325
|
|
|
*/ |
326
|
|
|
public function updateBookingInfo($id, BookingInfo $bookingInfo) |
327
|
|
|
{ |
328
|
|
|
$this->guardId($id); |
329
|
|
|
|
330
|
|
|
return $this->commandBus->dispatch( |
331
|
|
|
$this->commandFactory->createUpdateBookingInfoCommand($id, $bookingInfo) |
332
|
|
|
); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @param $id |
337
|
|
|
* @param PriceInfo $priceInfo |
338
|
|
|
*/ |
339
|
|
|
public function updatePriceInfo($id, PriceInfo $priceInfo) |
340
|
|
|
{ |
341
|
|
|
$this->guardId($id); |
342
|
|
|
|
343
|
|
|
return $this->commandBus->dispatch( |
344
|
|
|
$this->commandFactory->createUpdatePriceInfoCommand($id, $priceInfo) |
345
|
|
|
); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @param string $id |
350
|
|
|
* @return string |
351
|
|
|
*/ |
352
|
|
|
public function delete($id) |
353
|
|
|
{ |
354
|
|
|
return $this->commandBus->dispatch( |
355
|
|
|
$this->commandFactory->createDeleteOfferCommand($id) |
356
|
|
|
); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* @param string $id |
361
|
|
|
*/ |
362
|
|
|
public function guardId($id) |
363
|
|
|
{ |
364
|
|
|
$this->readRepository->get($id); |
365
|
|
|
} |
366
|
|
|
} |
367
|
|
|
|