1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Place; |
4
|
|
|
|
5
|
|
|
use Broadway\CommandHandling\CommandBusInterface; |
6
|
|
|
use Broadway\Repository\RepositoryInterface; |
7
|
|
|
use Broadway\UuidGenerator\UuidGeneratorInterface; |
8
|
|
|
use CultuurNet\UDB3\Address\Address; |
9
|
|
|
use CultuurNet\UDB3\CalendarInterface; |
10
|
|
|
use CultuurNet\UDB3\Event\EventType; |
11
|
|
|
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface; |
12
|
|
|
use CultuurNet\UDB3\Label\LabelServiceInterface; |
13
|
|
|
use CultuurNet\UDB3\Language; |
14
|
|
|
use CultuurNet\UDB3\Offer\Commands\OfferCommandFactoryInterface; |
15
|
|
|
use CultuurNet\UDB3\Offer\DefaultOfferEditingService; |
16
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateAddress; |
17
|
|
|
use CultuurNet\UDB3\Place\Commands\UpdateMajorInfo; |
18
|
|
|
use CultuurNet\UDB3\Theme; |
19
|
|
|
use CultuurNet\UDB3\Title; |
20
|
|
|
|
21
|
|
|
class DefaultPlaceEditingService extends DefaultOfferEditingService implements PlaceEditingServiceInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var RepositoryInterface |
25
|
|
|
*/ |
26
|
|
|
protected $writeRepository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param CommandBusInterface $commandBus |
30
|
|
|
* @param UuidGeneratorInterface $uuidGenerator |
31
|
|
|
* @param DocumentRepositoryInterface $readRepository |
32
|
|
|
* @param OfferCommandFactoryInterface $commandFactory |
33
|
|
|
* @param RepositoryInterface $writeRepository |
34
|
|
|
* @param LabelServiceInterface $labelService |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
37
|
|
|
CommandBusInterface $commandBus, |
38
|
|
|
UuidGeneratorInterface $uuidGenerator, |
39
|
|
|
DocumentRepositoryInterface $readRepository, |
40
|
|
|
OfferCommandFactoryInterface $commandFactory, |
41
|
|
|
RepositoryInterface $writeRepository, |
42
|
|
|
LabelServiceInterface $labelService |
43
|
|
|
) { |
44
|
|
|
parent::__construct( |
45
|
|
|
$commandBus, |
46
|
|
|
$uuidGenerator, |
47
|
|
|
$readRepository, |
48
|
|
|
$commandFactory, |
49
|
|
|
$labelService, |
50
|
|
|
new PlaceTypeResolver(), |
51
|
|
|
new PlaceThemeResolver() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->writeRepository = $writeRepository; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function createPlace( |
|
|
|
|
61
|
|
|
Language $mainLanguage, |
62
|
|
|
Title $title, |
63
|
|
|
EventType $eventType, |
64
|
|
|
Address $address, |
65
|
|
|
CalendarInterface $calendar, |
66
|
|
|
Theme $theme = null |
67
|
|
|
) { |
68
|
|
|
$id = $this->uuidGenerator->generate(); |
69
|
|
|
|
70
|
|
|
$place = Place::createPlace( |
71
|
|
|
$id, |
72
|
|
|
$mainLanguage, |
73
|
|
|
$title, |
74
|
|
|
$eventType, |
75
|
|
|
$address, |
76
|
|
|
$calendar, |
77
|
|
|
$theme, |
78
|
|
|
$this->publicationDate |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this->writeRepository->save($place); |
82
|
|
|
|
83
|
|
|
return $id; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritdoc |
88
|
|
|
*/ |
89
|
|
View Code Duplication |
public function createApprovedPlace( |
|
|
|
|
90
|
|
|
Language $mainLanguage, |
91
|
|
|
Title $title, |
92
|
|
|
EventType $eventType, |
93
|
|
|
Address $address, |
94
|
|
|
CalendarInterface $calendar, |
95
|
|
|
Theme $theme = null |
96
|
|
|
) { |
97
|
|
|
$id = $this->uuidGenerator->generate(); |
98
|
|
|
|
99
|
|
|
$place = Place::createPlace( |
100
|
|
|
$id, |
101
|
|
|
$mainLanguage, |
102
|
|
|
$title, |
103
|
|
|
$eventType, |
104
|
|
|
$address, |
105
|
|
|
$calendar, |
106
|
|
|
$theme |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$publicationDate = $this->publicationDate ? $this->publicationDate : new \DateTimeImmutable(); |
110
|
|
|
$place->publish($publicationDate); |
111
|
|
|
$place->approve(); |
112
|
|
|
|
113
|
|
|
$this->writeRepository->save($place); |
114
|
|
|
|
115
|
|
|
return $id; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
View Code Duplication |
public function updateMajorInfo($id, Title $title, EventType $eventType, Address $address, CalendarInterface $calendar, Theme $theme = null) |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
$this->guardId($id); |
124
|
|
|
|
125
|
|
|
return $this->commandBus->dispatch( |
126
|
|
|
new UpdateMajorInfo($id, $title, $eventType, $address, $calendar, $theme) |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @inheritdoc |
132
|
|
|
*/ |
133
|
|
|
public function updateAddress($id, Address $address, Language $language) |
134
|
|
|
{ |
135
|
|
|
$this->guardId($id); |
136
|
|
|
|
137
|
|
|
return $this->commandBus->dispatch( |
138
|
|
|
new UpdateAddress($id, $address, $language) |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* {@inheritdoc} |
145
|
|
|
*/ |
146
|
|
|
public function deletePlace($id) |
147
|
|
|
{ |
148
|
|
|
return $this->delete($id); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
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.