1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Place; |
4
|
|
|
|
5
|
|
|
use Broadway\Repository\RepositoryInterface; |
6
|
|
|
use CultuurNet\UDB3\CommandHandling\Udb3CommandHandler; |
7
|
|
|
use CultuurNet\UDB3\Place\Commands\AddImage; |
8
|
|
|
use CultuurNet\UDB3\Place\Commands\RemoveImage; |
9
|
|
|
use CultuurNet\UDB3\Place\Commands\DeleteOrganizer; |
10
|
|
|
use CultuurNet\UDB3\Place\Commands\DeletePlace; |
11
|
|
|
use CultuurNet\UDB3\Place\Commands\DeleteTypicalAgeRange; |
12
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateBookingInfo; |
13
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateContactPoint; |
14
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateDescription; |
15
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateFacilities; |
16
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateImage; |
17
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateMajorInfo; |
18
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateOrganizer; |
19
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateTypicalAgeRange; |
20
|
|
|
use Psr\Log\LoggerAwareInterface; |
21
|
|
|
use Psr\Log\LoggerAwareTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Commandhandler for places. |
25
|
|
|
*/ |
26
|
|
|
class CommandHandler extends Udb3CommandHandler implements LoggerAwareInterface |
27
|
|
|
{ |
28
|
|
|
use LoggerAwareTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var RepositoryInterface |
32
|
|
|
*/ |
33
|
|
|
protected $placeRepository; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param RepositoryInterface $placeRepository |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
RepositoryInterface $placeRepository |
40
|
|
|
) { |
41
|
|
|
$this->placeRepository = $placeRepository; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Handle the update of description on a place. |
46
|
|
|
*/ |
47
|
|
|
public function handleUpdateDescription(UpdateDescription $updateDescription) |
48
|
|
|
{ |
49
|
|
|
|
50
|
|
|
/** @var Place $place */ |
51
|
|
|
$place = $this->placeRepository->load($updateDescription->getId()); |
52
|
|
|
|
53
|
|
|
$place->updateDescription( |
54
|
|
|
$updateDescription->getDescription() |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$this->placeRepository->save($place); |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Handle the update of typical age range on a place. |
63
|
|
|
*/ |
64
|
|
|
public function handleUpdateTypicalAgeRange(UpdateTypicalAgeRange $updateTypicalAgeRange) |
65
|
|
|
{ |
66
|
|
|
|
67
|
|
|
/** @var Place $place */ |
68
|
|
|
$place = $this->placeRepository->load($updateTypicalAgeRange->getId()); |
69
|
|
|
|
70
|
|
|
$place->updateTypicalAgeRange( |
71
|
|
|
$updateTypicalAgeRange->getTypicalAgeRange() |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$this->placeRepository->save($place); |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Handle the deletion of typical age range on a place. |
80
|
|
|
*/ |
81
|
|
|
public function handleDeleteTypicalAgeRange(DeleteTypicalAgeRange $deleteTypicalAgeRange) |
82
|
|
|
{ |
83
|
|
|
|
84
|
|
|
/** @var Place $place */ |
85
|
|
|
$place = $this->placeRepository->load($deleteTypicalAgeRange->getId()); |
86
|
|
|
|
87
|
|
|
$place->deleteTypicalAgeRange(); |
88
|
|
|
|
89
|
|
|
$this->placeRepository->save($place); |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Handle an update command to update organizer of a place. |
95
|
|
|
*/ |
96
|
|
|
public function handleUpdateOrganizer(UpdateOrganizer $updateOrganizer) |
97
|
|
|
{ |
98
|
|
|
/** @var Place $place */ |
99
|
|
|
$place = $this->placeRepository->load($updateOrganizer->getId()); |
100
|
|
|
|
101
|
|
|
$place->updateOrganizer( |
102
|
|
|
$updateOrganizer->getOrganizerId() |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$this->placeRepository->save($place); |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Handle an update command to delete the organizer. |
111
|
|
|
*/ |
112
|
|
|
public function handleDeleteOrganizer(DeleteOrganizer $deleteOrganizer) |
113
|
|
|
{ |
114
|
|
|
|
115
|
|
|
/** @var Place $place */ |
116
|
|
|
$place = $this->placeRepository->load($deleteOrganizer->getId()); |
117
|
|
|
|
118
|
|
|
$place->deleteOrganizer( |
119
|
|
|
$deleteOrganizer->getOrganizerId() |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
$this->placeRepository->save($place); |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Handle an update command to updated the contact point. |
128
|
|
|
*/ |
129
|
|
|
public function handleUpdateContactPoint(UpdateContactPoint $updateContactPoint) |
130
|
|
|
{ |
131
|
|
|
|
132
|
|
|
/** @var Place $place */ |
133
|
|
|
$place = $this->placeRepository->load($updateContactPoint->getId()); |
134
|
|
|
|
135
|
|
|
$place->updateContactPoint( |
136
|
|
|
$updateContactPoint->getContactPoint() |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
$this->placeRepository->save($place); |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Handle the update of facilities for a place. |
145
|
|
|
*/ |
146
|
|
|
public function handleUpdateFacilities(UpdateFacilities $updateFacilities) |
147
|
|
|
{ |
148
|
|
|
|
149
|
|
|
/** @var Place $place */ |
150
|
|
|
$place = $this->placeRepository->load($updateFacilities->getId()); |
151
|
|
|
|
152
|
|
|
$place->updateFacilities( |
153
|
|
|
$updateFacilities->getFacilities() |
154
|
|
|
); |
155
|
|
|
|
156
|
|
|
$this->placeRepository->save($place); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Handle an update command to updated the booking info. |
161
|
|
|
*/ |
162
|
|
|
public function handleUpdateBookingInfo(UpdateBookingInfo $updateBookingInfo) |
163
|
|
|
{ |
164
|
|
|
|
165
|
|
|
/** @var Place $place */ |
166
|
|
|
$place = $this->placeRepository->load($updateBookingInfo->getId()); |
167
|
|
|
|
168
|
|
|
$place->updateBookingInfo( |
169
|
|
|
$updateBookingInfo->getBookingInfo() |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
$this->placeRepository->save($place); |
173
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Handle an add image command. |
179
|
|
|
* @param AddImage $addImage |
180
|
|
|
*/ |
181
|
|
|
public function handleAddImage(AddImage $addImage) |
182
|
|
|
{ |
183
|
|
|
|
184
|
|
|
/** @var Place $place */ |
185
|
|
|
$place = $this->placeRepository->load($addImage->getId()); |
186
|
|
|
|
187
|
|
|
$place->addImage( |
188
|
|
|
$addImage->getImage() |
189
|
|
|
); |
190
|
|
|
|
191
|
|
|
$this->placeRepository->save($place); |
192
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Handle an update image command. |
197
|
|
|
* @param UpdateImage $updateImage |
198
|
|
|
*/ |
199
|
|
|
public function handleUpdateImage(UpdateImage $updateImage) |
200
|
|
|
{ |
201
|
|
|
/** @var Place $place */ |
202
|
|
|
$place = $this->placeRepository->load($updateImage->getItemId()); |
203
|
|
|
|
204
|
|
|
$place->updateImage($updateImage); |
205
|
|
|
|
206
|
|
|
$this->placeRepository->save($place); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Handle a remove image command. |
211
|
|
|
* @param RemoveImage $removeImage |
212
|
|
|
*/ |
213
|
|
|
public function handleRemoveImage(RemoveImage $removeImage) |
214
|
|
|
{ |
215
|
|
|
/** @var Place $place */ |
216
|
|
|
$place = $this->placeRepository->load($removeImage->getItemId()); |
217
|
|
|
|
218
|
|
|
$place->removeImage($removeImage->getImage()); |
219
|
|
|
|
220
|
|
|
$this->placeRepository->save($place); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Handle an update the major info command. |
225
|
|
|
*/ |
226
|
|
View Code Duplication |
public function handleUpdateMajorInfo(UpdateMajorInfo $updateMajorInfo) |
|
|
|
|
227
|
|
|
{ |
228
|
|
|
|
229
|
|
|
/** @var Place $place */ |
230
|
|
|
$place = $this->placeRepository->load($updateMajorInfo->getId()); |
231
|
|
|
|
232
|
|
|
$place->updateMajorInfo( |
233
|
|
|
$updateMajorInfo->getTitle(), |
234
|
|
|
$updateMajorInfo->getEventType(), |
235
|
|
|
$updateMajorInfo->getAddress(), |
236
|
|
|
$updateMajorInfo->getCalendar(), |
237
|
|
|
$updateMajorInfo->getTheme() |
|
|
|
|
238
|
|
|
); |
239
|
|
|
|
240
|
|
|
$this->placeRepository->save($place); |
241
|
|
|
|
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Handle a delete place command. |
246
|
|
|
*/ |
247
|
|
|
public function handleDeletePlace(DeletePlace $deletePlace) |
248
|
|
|
{ |
249
|
|
|
|
250
|
|
|
/** @var Place $place */ |
251
|
|
|
$place = $this->placeRepository->load($deletePlace->getId()); |
252
|
|
|
$place->deletePlace(); |
253
|
|
|
|
254
|
|
|
$this->placeRepository->save($place); |
255
|
|
|
|
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.