1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Event; |
4
|
|
|
|
5
|
|
|
use Broadway\CommandHandling\CommandBusInterface; |
6
|
|
|
use Broadway\Repository\AggregateNotFoundException; |
7
|
|
|
use Broadway\Repository\RepositoryInterface; |
8
|
|
|
use Broadway\UuidGenerator\UuidGeneratorInterface; |
9
|
|
|
use CultuurNet\UDB3\CalendarInterface; |
10
|
|
|
use CultuurNet\UDB3\Event\Commands\UpdateAudience; |
11
|
|
|
use CultuurNet\UDB3\Event\Commands\UpdateMajorInfo; |
12
|
|
|
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface; |
13
|
|
|
use CultuurNet\UDB3\Event\ValueObjects\Audience; |
14
|
|
|
use CultuurNet\UDB3\InvalidTranslationLanguageException; |
15
|
|
|
use CultuurNet\UDB3\Label\LabelServiceInterface; |
16
|
|
|
use CultuurNet\UDB3\Language; |
17
|
|
|
use CultuurNet\UDB3\LanguageCanBeTranslatedToSpecification; |
18
|
|
|
use CultuurNet\UDB3\Location\Location; |
19
|
|
|
use CultuurNet\UDB3\Offer\Commands\OfferCommandFactoryInterface; |
20
|
|
|
use CultuurNet\UDB3\Offer\DefaultOfferEditingService; |
21
|
|
|
use CultuurNet\UDB3\PlaceService; |
22
|
|
|
use CultuurNet\UDB3\Title; |
23
|
|
|
|
24
|
|
|
class DefaultEventEditingService extends DefaultOfferEditingService implements EventEditingServiceInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var EventServiceInterface |
28
|
|
|
*/ |
29
|
|
|
protected $eventService; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var PlaceService |
33
|
|
|
*/ |
34
|
|
|
protected $places; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var RepositoryInterface |
38
|
|
|
*/ |
39
|
|
|
protected $writeRepository; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param EventServiceInterface $eventService |
43
|
|
|
* @param CommandBusInterface $commandBus |
44
|
|
|
* @param UuidGeneratorInterface $uuidGenerator |
45
|
|
|
* @param DocumentRepositoryInterface $readRepository |
46
|
|
|
* @param PlaceService $placeService |
47
|
|
|
* @param OfferCommandFactoryInterface $commandFactory |
48
|
|
|
* @param RepositoryInterface $writeRepository |
49
|
|
|
* @param LabelServiceInterface $labelService |
50
|
|
|
*/ |
51
|
|
|
public function __construct( |
52
|
|
|
EventServiceInterface $eventService, |
53
|
|
|
CommandBusInterface $commandBus, |
54
|
|
|
UuidGeneratorInterface $uuidGenerator, |
55
|
|
|
DocumentRepositoryInterface $readRepository, |
56
|
|
|
PlaceService $placeService, |
57
|
|
|
OfferCommandFactoryInterface $commandFactory, |
58
|
|
|
RepositoryInterface $writeRepository, |
59
|
|
|
LabelServiceInterface $labelService |
60
|
|
|
) { |
61
|
|
|
parent::__construct( |
62
|
|
|
$commandBus, |
63
|
|
|
$uuidGenerator, |
64
|
|
|
$readRepository, |
65
|
|
|
$commandFactory, |
66
|
|
|
$labelService |
67
|
|
|
); |
68
|
|
|
$this->eventService = $eventService; |
69
|
|
|
$this->places = $placeService; |
70
|
|
|
$this->writeRepository = $writeRepository; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function guardTranslationLanguage(Language $language) |
74
|
|
|
{ |
75
|
|
|
if (!LanguageCanBeTranslatedToSpecification::isSatisfiedBy($language)) { |
76
|
|
|
throw new InvalidTranslationLanguageException($language); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function createEvent( |
|
|
|
|
84
|
|
|
Title $title, |
85
|
|
|
EventType $eventType, |
86
|
|
|
Location $location, |
87
|
|
|
CalendarInterface $calendar, |
88
|
|
|
$theme = null |
89
|
|
|
) { |
90
|
|
|
$eventId = $this->uuidGenerator->generate(); |
91
|
|
|
|
92
|
|
|
$event = Event::create( |
93
|
|
|
$eventId, |
94
|
|
|
$title, |
95
|
|
|
$eventType, |
96
|
|
|
$location, |
97
|
|
|
$calendar, |
98
|
|
|
$theme, |
99
|
|
|
$this->publicationDate |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$this->writeRepository->save($event); |
103
|
|
|
|
104
|
|
|
return $eventId; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritdoc |
109
|
|
|
*/ |
110
|
|
|
public function copyEvent($originalEventId, CalendarInterface $calendar) |
111
|
|
|
{ |
112
|
|
|
if (!is_string($originalEventId)) { |
113
|
|
|
throw new \InvalidArgumentException( |
114
|
|
|
'Expected originalEventId to be a string, received ' . gettype($originalEventId) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
try { |
119
|
|
|
$this->writeRepository->load($originalEventId); |
120
|
|
|
} catch (AggregateNotFoundException $exception) { |
121
|
|
|
throw new \InvalidArgumentException( |
122
|
|
|
'No original event found to copy with id ' . $originalEventId |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$eventId = $this->uuidGenerator->generate(); |
127
|
|
|
|
128
|
|
|
$event = Event::copyEvent($eventId, $originalEventId, $calendar); |
129
|
|
|
|
130
|
|
|
$this->writeRepository->save($event); |
131
|
|
|
|
132
|
|
|
return $eventId; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* {@inheritdoc} |
137
|
|
|
*/ |
138
|
|
View Code Duplication |
public function updateMajorInfo($eventId, Title $title, EventType $eventType, Location $location, CalendarInterface $calendar, $theme = null) |
|
|
|
|
139
|
|
|
{ |
140
|
|
|
$this->guardId($eventId); |
141
|
|
|
|
142
|
|
|
return $this->commandBus->dispatch( |
143
|
|
|
new UpdateMajorInfo($eventId, $title, $eventType, $location, $calendar, $theme) |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @inheritdoc |
149
|
|
|
*/ |
150
|
|
|
public function updateAudience($eventId, Audience $audience) |
151
|
|
|
{ |
152
|
|
|
return $this->commandBus->dispatch( |
153
|
|
|
new UpdateAudience($eventId, $audience) |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* {@inheritdoc} |
159
|
|
|
*/ |
160
|
|
|
public function deleteEvent($eventId) |
161
|
|
|
{ |
162
|
|
|
return $this->delete($eventId); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
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.