1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* SectionService class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\SignalSlot; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\SectionService as SectionServiceInterface; |
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\SectionCreateStruct; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct; |
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\Section; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
17
|
|
|
use eZ\Publish\Core\SignalSlot\Signal\SectionService\AssignSectionToSubtreeSignal; |
18
|
|
|
use eZ\Publish\Core\SignalSlot\Signal\SectionService\CreateSectionSignal; |
19
|
|
|
use eZ\Publish\Core\SignalSlot\Signal\SectionService\UpdateSectionSignal; |
20
|
|
|
use eZ\Publish\Core\SignalSlot\Signal\SectionService\AssignSectionSignal; |
21
|
|
|
use eZ\Publish\Core\SignalSlot\Signal\SectionService\DeleteSectionSignal; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* SectionService class. |
25
|
|
|
*/ |
26
|
|
|
class SectionService implements SectionServiceInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Aggregated service. |
30
|
|
|
* |
31
|
|
|
* @var \eZ\Publish\API\Repository\SectionService |
32
|
|
|
*/ |
33
|
|
|
protected $service; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* SignalDispatcher. |
37
|
|
|
* |
38
|
|
|
* @var \eZ\Publish\Core\SignalSlot\SignalDispatcher |
39
|
|
|
*/ |
40
|
|
|
protected $signalDispatcher; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor. |
44
|
|
|
* |
45
|
|
|
* Construct service object from aggregated service and signal |
46
|
|
|
* dispatcher |
47
|
|
|
* |
48
|
|
|
* @param \eZ\Publish\API\Repository\SectionService $service |
49
|
|
|
* @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher |
50
|
|
|
*/ |
51
|
|
|
public function __construct(SectionServiceInterface $service, SignalDispatcher $signalDispatcher) |
52
|
|
|
{ |
53
|
|
|
$this->service = $service; |
54
|
|
|
$this->signalDispatcher = $signalDispatcher; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Creates the a new Section in the content repository. |
59
|
|
|
* |
60
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create a section |
61
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the new identifier in $sectionCreateStruct already exists |
62
|
|
|
* |
63
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\SectionCreateStruct $sectionCreateStruct |
64
|
|
|
* |
65
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Section The newly create section |
66
|
|
|
*/ |
67
|
|
|
public function createSection(SectionCreateStruct $sectionCreateStruct) |
68
|
|
|
{ |
69
|
|
|
$returnValue = $this->service->createSection($sectionCreateStruct); |
70
|
|
|
$this->signalDispatcher->emit( |
71
|
|
|
new CreateSectionSignal( |
72
|
|
|
array( |
73
|
|
|
'sectionId' => $returnValue->id, |
74
|
|
|
) |
75
|
|
|
) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
return $returnValue; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Updates the given in the content repository. |
83
|
|
|
* |
84
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create a section |
85
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the new identifier already exists (if set in the update struct) |
86
|
|
|
* |
87
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Section $section |
88
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct $sectionUpdateStruct |
89
|
|
|
* |
90
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Section |
91
|
|
|
*/ |
92
|
|
|
public function updateSection(Section $section, SectionUpdateStruct $sectionUpdateStruct) |
93
|
|
|
{ |
94
|
|
|
$returnValue = $this->service->updateSection($section, $sectionUpdateStruct); |
95
|
|
|
$this->signalDispatcher->emit( |
96
|
|
|
new UpdateSectionSignal( |
97
|
|
|
array( |
98
|
|
|
'sectionId' => $section->id, |
99
|
|
|
) |
100
|
|
|
) |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
return $returnValue; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Loads a Section from its id ($sectionId). |
108
|
|
|
* |
109
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if section could not be found |
110
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read a section |
111
|
|
|
* |
112
|
|
|
* @param mixed $sectionId |
113
|
|
|
* |
114
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Section |
115
|
|
|
*/ |
116
|
|
|
public function loadSection($sectionId) |
117
|
|
|
{ |
118
|
|
|
return $this->service->loadSection($sectionId); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Loads all sections. |
123
|
|
|
* |
124
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read a section |
125
|
|
|
* |
126
|
|
|
* @return array of {@link \eZ\Publish\API\Repository\Values\Content\Section} |
127
|
|
|
*/ |
128
|
|
|
public function loadSections() |
129
|
|
|
{ |
130
|
|
|
return $this->service->loadSections(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Loads a Section from its identifier ($sectionIdentifier). |
135
|
|
|
* |
136
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if section could not be found |
137
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read a section |
138
|
|
|
* |
139
|
|
|
* @param string $sectionIdentifier |
140
|
|
|
* |
141
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Section |
142
|
|
|
*/ |
143
|
|
|
public function loadSectionByIdentifier($sectionIdentifier) |
144
|
|
|
{ |
145
|
|
|
return $this->service->loadSectionByIdentifier($sectionIdentifier); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Counts the contents which $section is assigned to. |
150
|
|
|
* |
151
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Section $section |
152
|
|
|
* |
153
|
|
|
* @return int |
154
|
|
|
* |
155
|
|
|
* @deprecated since 6.0 |
156
|
|
|
*/ |
157
|
|
|
public function countAssignedContents(Section $section) |
158
|
|
|
{ |
159
|
|
|
return $this->service->countAssignedContents($section); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Returns true if the given section is assigned to contents, or used in role policies, or in role assignments. |
164
|
|
|
* |
165
|
|
|
* This does not check user permissions. |
166
|
|
|
* |
167
|
|
|
* @since 6.0 |
168
|
|
|
* |
169
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Section $section |
170
|
|
|
* |
171
|
|
|
* @return bool |
172
|
|
|
*/ |
173
|
|
|
public function isSectionUsed(Section $section) |
174
|
|
|
{ |
175
|
|
|
return $this->service->isSectionUsed($section); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Assigns the content to the given section |
180
|
|
|
* this method overrides the current assigned section. |
181
|
|
|
* |
182
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If user does not have access to view provided object |
183
|
|
|
* |
184
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
185
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Section $section |
186
|
|
|
*/ |
187
|
|
|
public function assignSection(ContentInfo $contentInfo, Section $section) |
188
|
|
|
{ |
189
|
|
|
$returnValue = $this->service->assignSection($contentInfo, $section); |
190
|
|
|
$this->signalDispatcher->emit( |
191
|
|
|
new AssignSectionSignal( |
192
|
|
|
array( |
193
|
|
|
'contentId' => $contentInfo->id, |
194
|
|
|
'sectionId' => $section->id, |
195
|
|
|
) |
196
|
|
|
) |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
return $returnValue; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Assigns the subtree to the given section. |
204
|
|
|
* |
205
|
|
|
* This method overrides the current assigned section. |
206
|
|
|
* |
207
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
208
|
|
|
* |
209
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location $location |
210
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Section $section |
211
|
|
|
*/ |
212
|
|
|
public function assignSectionToSubtree(Location $location, Section $section): void |
213
|
|
|
{ |
214
|
|
|
$this->service->assignSectionToSubtree($location, $section); |
215
|
|
|
|
216
|
|
|
$this->signalDispatcher->emit( |
217
|
|
|
new AssignSectionToSubtreeSignal( |
218
|
|
|
[ |
219
|
|
|
'locationId' => $location->id, |
220
|
|
|
'sectionId' => $section->id, |
221
|
|
|
] |
222
|
|
|
) |
223
|
|
|
); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Deletes $section from content repository. |
228
|
|
|
* |
229
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified section is not found |
230
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to delete a section |
231
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if section can not be deleted |
232
|
|
|
* because it is still assigned to some contents. |
233
|
|
|
* |
234
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Section $section |
235
|
|
|
*/ |
236
|
|
|
public function deleteSection(Section $section) |
237
|
|
|
{ |
238
|
|
|
$returnValue = $this->service->deleteSection($section); |
239
|
|
|
$this->signalDispatcher->emit( |
240
|
|
|
new DeleteSectionSignal( |
241
|
|
|
array( |
242
|
|
|
'sectionId' => $section->id, |
243
|
|
|
) |
244
|
|
|
) |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
return $returnValue; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Instantiates a new SectionCreateStruct. |
252
|
|
|
* |
253
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\SectionCreateStruct |
254
|
|
|
*/ |
255
|
|
|
public function newSectionCreateStruct() |
256
|
|
|
{ |
257
|
|
|
return $this->service->newSectionCreateStruct(); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Instantiates a new SectionUpdateStruct. |
262
|
|
|
* |
263
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct |
264
|
|
|
*/ |
265
|
|
|
public function newSectionUpdateStruct() |
266
|
|
|
{ |
267
|
|
|
return $this->service->newSectionUpdateStruct(); |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.