1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains CultuurNet\UDB3\OfferEditingTrait. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace CultuurNet\UDB3; |
9
|
|
|
|
10
|
|
|
use CultuurNet\UDB3\Media\Image; |
11
|
|
|
use CultuurNet\UDB3\Media\MediaObject; |
12
|
|
|
use ValueObjects\String\String; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Trait that contains all major editing methods for Offers. |
16
|
|
|
*/ |
17
|
|
|
trait OfferEditingTrait |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Get the namespaced classname of the command to create. |
22
|
|
|
* @param type $className |
23
|
|
|
* Name of the class |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
private function getCommandClass($className) |
27
|
|
|
{ |
28
|
|
|
$reflection = new \ReflectionObject($this); |
29
|
|
|
return $reflection->getNamespaceName() . '\\Commands\\' . $className; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function updateDescription($id, $description) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
$this->guardId($id); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$commandClass = $this->getCommandClass('UpdateDescription'); |
|
|
|
|
41
|
|
|
|
42
|
|
|
return $this->commandBus->dispatch( |
|
|
|
|
43
|
|
|
new $commandClass($id, $description) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function updateTypicalAgeRange($id, $ageRange) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
|
53
|
|
|
$this->guardId($id); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$commandClass = $this->getCommandClass('UpdateTypicalAgeRange'); |
|
|
|
|
56
|
|
|
|
57
|
|
|
return $this->commandBus->dispatch( |
58
|
|
|
new $commandClass($id, $ageRange) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function deleteTypicalAgeRange($id) |
66
|
|
|
{ |
67
|
|
|
|
68
|
|
|
$this->guardId($id); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$commandClass = $this->getCommandClass('DeleteTypicalAgeRange'); |
|
|
|
|
71
|
|
|
|
72
|
|
|
return $this->commandBus->dispatch( |
73
|
|
|
new $commandClass($id) |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function updateOrganizer($id, $organizerId) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
|
84
|
|
|
$this->guardId($id); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$commandClass = $this->getCommandClass('UpdateOrganizer'); |
|
|
|
|
87
|
|
|
|
88
|
|
|
return $this->commandBus->dispatch( |
89
|
|
|
new $commandClass($id, $organizerId) |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
public function deleteOrganizer($id, $organizerId) |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
$this->guardId($id); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$commandClass = $this->getCommandClass('DeleteOrganizer'); |
|
|
|
|
102
|
|
|
|
103
|
|
|
return $this->commandBus->dispatch( |
104
|
|
|
new $commandClass($id, $organizerId) |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
|
View Code Duplication |
public function updateContactPoint($id, ContactPoint $contactPoint) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
|
114
|
|
|
$this->guardId($id); |
|
|
|
|
115
|
|
|
|
116
|
|
|
$commandClass = $this->getCommandClass('UpdateContactPoint'); |
|
|
|
|
117
|
|
|
|
118
|
|
|
return $this->commandBus->dispatch( |
119
|
|
|
new $commandClass($id, $contactPoint) |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritdoc} |
126
|
|
|
*/ |
127
|
|
View Code Duplication |
public function updateBookingInfo($id, BookingInfo $bookingInfo) |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
|
130
|
|
|
$this->guardId($id); |
|
|
|
|
131
|
|
|
|
132
|
|
|
$commandClass = $this->getCommandClass('UpdateBookingInfo'); |
|
|
|
|
133
|
|
|
|
134
|
|
|
return $this->commandBus->dispatch( |
135
|
|
|
new $commandClass($id, $bookingInfo) |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* {@inheritdoc} |
142
|
|
|
*/ |
143
|
|
View Code Duplication |
public function addImage($id, Image $image) |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
$this->guardId($id); |
|
|
|
|
146
|
|
|
|
147
|
|
|
$commandClass = $this->getCommandClass('AddImage'); |
|
|
|
|
148
|
|
|
|
149
|
|
|
return $this->commandBus->dispatch( |
150
|
|
|
new $commandClass($id, $image) |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* {@inheritdoc} |
156
|
|
|
*/ |
157
|
|
View Code Duplication |
public function updateImage( |
|
|
|
|
158
|
|
|
$id, |
159
|
|
|
Image $image, |
160
|
|
|
String $description, |
161
|
|
|
String $copyrightHolder |
162
|
|
|
) { |
163
|
|
|
$this->guardId($id); |
|
|
|
|
164
|
|
|
|
165
|
|
|
$commandClass = $this->getCommandClass('UpdateImage'); |
|
|
|
|
166
|
|
|
|
167
|
|
|
return $this->commandBus->dispatch( |
168
|
|
|
new $commandClass( |
169
|
|
|
$id, |
170
|
|
|
$image->getMediaObjectId(), |
171
|
|
|
$description, |
172
|
|
|
$copyrightHolder |
173
|
|
|
) |
174
|
|
|
); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param $id |
179
|
|
|
* Id of the offer to remove the image from. |
180
|
|
|
* |
181
|
|
|
* @param Image $image |
182
|
|
|
* The image that should be removed. |
183
|
|
|
* |
184
|
|
|
* @return mixed |
185
|
|
|
*/ |
186
|
|
|
public function removeImage($id, Image $image) |
187
|
|
|
{ |
188
|
|
|
$this->guardId($id); |
|
|
|
|
189
|
|
|
|
190
|
|
|
$commandClass = $this->getCommandClass('RemoveImage'); |
|
|
|
|
191
|
|
|
|
192
|
|
|
return $this->commandBus->dispatch( |
193
|
|
|
new $commandClass($id, $image) |
194
|
|
|
); |
195
|
|
|
|
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
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.