Completed
Pull Request — master (#110)
by Kristof
07:14
created

Place::getAggregateRootId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\MediaObject;
18
use CultuurNet\UDB3\Place\Events\BookingInfoUpdated;
19
use CultuurNet\UDB3\Place\Events\ContactPointUpdated;
20
use CultuurNet\UDB3\Place\Events\DescriptionUpdated;
21
use CultuurNet\UDB3\Place\Events\FacilitiesUpdated;
22
use CultuurNet\UDB3\Place\Events\ImageAdded;
23
use CultuurNet\UDB3\Place\Events\ImageDeleted;
24
use CultuurNet\UDB3\Place\Events\ImageUpdated;
25
use CultuurNet\UDB3\Place\Events\MajorInfoUpdated;
26
use CultuurNet\UDB3\Place\Events\OrganizerDeleted;
27
use CultuurNet\UDB3\Place\Events\OrganizerUpdated;
28
use CultuurNet\UDB3\Place\Events\PlaceCreated;
29
use CultuurNet\UDB3\Place\Events\PlaceDeleted;
30
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2;
31
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2Event;
32
use CultuurNet\UDB3\Place\Events\PlaceUpdatedFromUDB2;
33
use CultuurNet\UDB3\Place\Events\TypicalAgeRangeDeleted;
34
use CultuurNet\UDB3\Place\Events\TypicalAgeRangeUpdated;
35
use CultuurNet\UDB3\Theme;
36
use CultuurNet\UDB3\Title;
37
use Symfony\Component\EventDispatcher\Event;
38
use ValueObjects\String\String;
39
40
class Place extends EventSourcedAggregateRoot implements UpdateableWithCdbXmlInterface
41
{
42
    /**
43
     * The actor id.
44
     *
45
     * @var string
46
     */
47
    protected $actorId;
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getAggregateRootId()
53
    {
54
        return $this->actorId;
55
    }
56
57
    /**
58
     * Factory method to create a new Place.
59
     *
60
     * @todo Refactor this method so it can be called create. Currently the
61
     * normal behavior for create is taken by the legacy udb2 logic.
62
     * The PlaceImportedFromUDB2 could be a superclass of Place.
63
     *
64
     * @param String $id
65
     * @param Title $title
66
     * @param EventType $eventType
67
     * @param Address $address
68
     * @param CalendarInterface $calendar
69
     * @param Theme/null $theme
0 ignored issues
show
Documentation introduced by
The doc-type Theme/null could not be parsed: Unknown type name "Theme/null" at position 0. (view supported doc-types)

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.

Loading history...
70
     *
71
     * @return Event
72
     */
73
    public static function createPlace($id, Title $title, EventType $eventType, Address $address, CalendarInterface $calendar, Theme $theme = null)
74
    {
75
        $place = new self();
76
        $place->apply(new PlaceCreated($id, $title, $eventType, $address, $calendar, $theme));
77
78
        return $place;
79
    }
80
81
    /**
82
     * Apply the place created event.
83
     * @param PlaceCreate $placeCreated
84
     */
85
    protected function applyPlaceCreated(PlaceCreated $placeCreated)
86
    {
87
        $this->actorId = $placeCreated->getPlaceId();
88
    }
89
90
    /**
91
     * @param string $description
92
     */
93
    public function updateDescription($description)
94
    {
95
        $this->apply(new DescriptionUpdated($this->actorId, $description));
96
    }
97
98
    /**
99
     * @param string $typicalAgeRange
100
     */
101
    public function updateTypicalAgeRange($typicalAgeRange)
102
    {
103
        $this->apply(new TypicalAgeRangeUpdated($this->actorId, $typicalAgeRange));
104
    }
105
106
    public function deleteTypicalAgeRange()
107
    {
108
        $this->apply(new TypicalAgeRangeDeleted($this->actorId));
109
    }
110
111
    /**
112
     * Handle an update command to update organizer.
113
     */
114
    public function updateOrganizer($organizerId)
115
    {
116
        $this->apply(new OrganizerUpdated($this->actorId, $organizerId));
117
    }
118
119
    /**
120
     * Delete the given organizer.
121
     *
122
     * @param string $organizerId
123
     */
124
    public function deleteOrganizer($organizerId)
125
    {
126
        $this->apply(new OrganizerDeleted($this->actorId, $organizerId));
127
    }
128
129
    /**
130
     * Updated the contact point.
131
     *
132
     * @param ContactPoint $contactPoint
133
     */
134
    public function updateContactPoint(ContactPoint $contactPoint)
135
    {
136
        $this->apply(new ContactPointUpdated($this->actorId, $contactPoint));
137
    }
138
139
    /**
140
     * Updated the booking info.
141
     *
142
     * @param BookingInfo $bookingInfo
143
     */
144
    public function updateBookingInfo(BookingInfo $bookingInfo)
145
    {
146
        $this->apply(new BookingInfoUpdated($this->actorId, $bookingInfo));
147
    }
148
149
    /**
150
     * Update the facilities.
151
     *
152
     * @param array $facilities
153
     */
154
    public function updateFacilities(array $facilities)
155
    {
156
        $this->apply(new FacilitiesUpdated($this->actorId, $facilities));
157
    }
158
159
    /**
160
     * Add a new image.
161
     *
162
     * @param MediaObject $mediaObject
163
     */
164
    public function addImage(MediaObject $mediaObject)
165
    {
166
        $this->apply(new ImageAdded($this->actorId, $mediaObject));
167
    }
168
169
    /**
170
     * Update an image.
171
     *
172
     * @param int $indexToUpdate
173
     * @param MediaObject $mediaObject
174
     */
175
    public function updateImage($indexToUpdate, MediaObject $mediaObject)
176
    {
177
        $this->apply(new ImageUpdated($this->actorId, $indexToUpdate, $mediaObject));
178
    }
179
180
    /**
181
     * Delet an image.
182
     *
183
     * @param int $indexToDelete
184
     * @param mixed int|string $internalId
185
     */
186
    public function deleteImage($indexToDelete, $internalId)
187
    {
188
        $this->apply(new ImageDeleted($this->actorId, $indexToDelete, $internalId));
189
    }
190
191
    /**
192
     * Update the major info.
193
     *
194
     * @param Title $title
195
     * @param EventType $eventType
196
     * @param Address $address
197
     * @param CalendarInterface $calendar
198
     * @param type $theme
199
     */
200
    public function updateMajorInfo(Title $title, EventType $eventType, Address $address, CalendarInterface $calendar, $theme = null)
201
    {
202
        $this->apply(new MajorInfoUpdated($this->actorId, $title, $eventType, $address, $calendar, $theme));
203
    }
204
205
    /**
206
     * Delete this item.
207
     */
208
    public function deletePlace()
209
    {
210
        $this->apply(new PlaceDeleted($this->actorId));
211
    }
212
213
    /**
214
     * Import from UDB2.
215
     *
216
     * @param string $actorId
217
     *   The actor id.
218
     * @param string $cdbXml
219
     *   The cdb xml.
220
     * @param string $cdbXmlNamespaceUri
221
     *   The cdb xml namespace uri.
222
     *
223
     * @return Actor
224
     *   The actor.
225
     */
226
    public static function importFromUDB2Actor(
227
        $actorId,
228
        $cdbXml,
229
        $cdbXmlNamespaceUri
230
    ) {
231
        $place = new static();
232
        $place->apply(
233
            new PlaceImportedFromUDB2(
234
                $actorId,
235
                $cdbXml,
236
                $cdbXmlNamespaceUri
237
            )
238
        );
239
240
        return $place;
241
    }
242
243
    /**
244
     * Import from UDB2.
245
     *
246
     * @param string $placeId
247
     *   The actor id.
248
     * @param string $cdbXml
249
     *   The cdb xml.
250
     * @param string $cdbXmlNamespaceUri
251
     *   The cdb xml namespace uri.
252
     *
253
     * @return Actor
254
     *   The actor.
255
     */
256
    public static function importFromUDB2Event(
257
        $placeId,
258
        $cdbXml,
259
        $cdbXmlNamespaceUri
260
    ) {
261
        $place = new static();
262
        $place->apply(
263
            new PlaceImportedFromUDB2Event(
264
                $placeId,
265
                $cdbXml,
266
                $cdbXmlNamespaceUri
267
            )
268
        );
269
270
        return $place;
271
    }
272
273
    public function applyPlaceImportedFromUDB2(
274
        PlaceImportedFromUDB2 $placeImported
275
    ) {
276
        $this->actorId = $placeImported->getActorId();
277
    }
278
279
    public function applyPlaceImportedFromUDB2Event(
280
        PlaceImportedFromUDB2Event $placeImported
281
    ) {
282
        $this->actorId = $placeImported->getActorId();
283
    }
284
285
    /**
286
     * @inheritdoc
287
     */
288
    public function updateWithCdbXml($cdbXml, $cdbXmlNamespaceUri)
289
    {
290
        $this->apply(
291
            new PlaceUpdatedFromUDB2(
292
                $this->actorId,
293
                $cdbXml,
294
                $cdbXmlNamespaceUri
295
            )
296
        );
297
    }
298
}
299