Completed
Push — 7.0_deprecation_removal ( e8d685...a29025 )
by André
11:11
created

loadParentLocationsForDraftContent()   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
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * LocationService 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\LocationService as LocationServiceInterface;
12
use eZ\Publish\API\Repository\Values\Content\Location;
13
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
15
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct;
16
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
17
use eZ\Publish\Core\SignalSlot\Signal\LocationService\CopySubtreeSignal;
18
use eZ\Publish\Core\SignalSlot\Signal\LocationService\CreateLocationSignal;
19
use eZ\Publish\Core\SignalSlot\Signal\LocationService\UpdateLocationSignal;
20
use eZ\Publish\Core\SignalSlot\Signal\LocationService\SwapLocationSignal;
21
use eZ\Publish\Core\SignalSlot\Signal\LocationService\HideLocationSignal;
22
use eZ\Publish\Core\SignalSlot\Signal\LocationService\UnhideLocationSignal;
23
use eZ\Publish\Core\SignalSlot\Signal\LocationService\MoveSubtreeSignal;
24
use eZ\Publish\Core\SignalSlot\Signal\LocationService\DeleteLocationSignal;
25
26
/**
27
 * LocationService class.
28
 */
29
class LocationService implements LocationServiceInterface
30
{
31
    /**
32
     * Aggregated service.
33
     *
34
     * @var \eZ\Publish\API\Repository\LocationService
35
     */
36
    protected $service;
37
38
    /**
39
     * SignalDispatcher.
40
     *
41
     * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher
42
     */
43
    protected $signalDispatcher;
44
45
    /**
46
     * Constructor.
47
     *
48
     * Construct service object from aggregated service and signal
49
     * dispatcher
50
     *
51
     * @param \eZ\Publish\API\Repository\LocationService $service
52
     * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
53
     */
54
    public function __construct(LocationServiceInterface $service, SignalDispatcher $signalDispatcher)
55
    {
56
        $this->service = $service;
57
        $this->signalDispatcher = $signalDispatcher;
58
    }
59
60
    /**
61
     * Copies the subtree starting from $subtree as a new subtree of $targetLocation.
62
     *
63
     * Only the items on which the user has read access are copied.
64
     *
65
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed copy the subtree to the given parent location
66
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree
67
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the target location is a sub location of the given location
68
     *
69
     * @param \eZ\Publish\API\Repository\Values\Content\Location $subtree - the subtree denoted by the location to copy
70
     * @param \eZ\Publish\API\Repository\Values\Content\Location $targetParentLocation - the target parent location for the copy operation
71
     *
72
     * @return \eZ\Publish\API\Repository\Values\Content\Location The newly created location of the copied subtree
73
     */
74
    public function copySubtree(Location $subtree, Location $targetParentLocation)
75
    {
76
        $returnValue = $this->service->copySubtree($subtree, $targetParentLocation);
77
        $this->signalDispatcher->emit(
78
            new CopySubtreeSignal(
79
                array(
80
                    'subtreeId' => $subtree->id,
81
                    'targetParentLocationId' => $targetParentLocation->id,
82
                    'targetNewSubtreeId' => $returnValue->id,
83
                )
84
            )
85
        );
86
87
        return $returnValue;
88
    }
89
90
    /**
91
     * Loads a location object from its $locationId.
92
     *
93
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location
94
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found
95
     *
96
     * @param mixed $locationId
97
     *
98
     * @return \eZ\Publish\API\Repository\Values\Content\Location
99
     */
100
    public function loadLocation($locationId)
101
    {
102
        return $this->service->loadLocation($locationId);
103
    }
104
105
    /**
106
     * Loads a location object from its $remoteId.
107
     *
108
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location
109
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found
110
     *
111
     * @param string $remoteId
112
     *
113
     * @return \eZ\Publish\API\Repository\Values\Content\Location
114
     */
115
    public function loadLocationByRemoteId($remoteId)
116
    {
117
        return $this->service->loadLocationByRemoteId($remoteId);
118
    }
119
120
    /**
121
     * Loads the locations for the given content object.
122
     *
123
     * If a $rootLocation is given, only locations that belong to this location are returned.
124
     * The location list is also filtered by permissions on reading locations.
125
     *
126
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if there is no published version yet
127
     *
128
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
129
     * @param \eZ\Publish\API\Repository\Values\Content\Location $rootLocation
130
     *
131
     * @return \eZ\Publish\API\Repository\Values\Content\Location[] An array of {@link Location}
132
     */
133
    public function loadLocations(ContentInfo $contentInfo, Location $rootLocation = null)
134
    {
135
        return $this->service->loadLocations($contentInfo, $rootLocation);
136
    }
137
138
    /**
139
     * Loads children which are readable by the current user of a location object sorted by sortField and sortOrder.
140
     *
141
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
142
     * @param int $offset the start offset for paging
143
     * @param int $limit the number of locations returned
144
     *
145
     * @return \eZ\Publish\API\Repository\Values\Content\LocationList
146
     */
147
    public function loadLocationChildren(Location $location, $offset = 0, $limit = 25)
148
    {
149
        return $this->service->loadLocationChildren($location, $offset, $limit);
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155
    public function loadParentLocationsForDraftContent(VersionInfo $versionInfo)
156
    {
157
        return $this->service->loadParentLocationsForDraftContent($versionInfo);
158
    }
159
160
    /**
161
     * Returns the number of children which are readable by the current user of a location object.
162
     *
163
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
164
     *
165
     * @return int
166
     */
167
    public function getLocationChildCount(Location $location)
168
    {
169
        return $this->service->getLocationChildCount($location);
170
    }
171
172
    /**
173
     * Creates the new $location in the content repository for the given content.
174
     *
175
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create this location
176
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the content is already below the specified parent
177
     *                                        or the parent is a sub location of the location of the content
178
     *                                        or if set the remoteId exists already
179
     *
180
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
181
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
182
     *
183
     * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created Location
184
     */
185
    public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct)
186
    {
187
        $returnValue = $this->service->createLocation($contentInfo, $locationCreateStruct);
188
        $this->signalDispatcher->emit(
189
            new CreateLocationSignal(
190
                array(
191
                    'contentId' => $contentInfo->id,
192
                    'locationId' => $returnValue->id,
193
                    'parentLocationId' => $returnValue->parentLocationId,
194
                )
195
            )
196
        );
197
198
        return $returnValue;
199
    }
200
201
    /**
202
     * Updates $location in the content repository.
203
     *
204
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
205
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
206
     *
207
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
208
     * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
209
     *
210
     * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
211
     */
212
    public function updateLocation(Location $location, LocationUpdateStruct $locationUpdateStruct)
213
    {
214
        $returnValue = $this->service->updateLocation($location, $locationUpdateStruct);
215
        $this->signalDispatcher->emit(
216
            new UpdateLocationSignal(
217
                array(
218
                    'contentId' => $location->contentId,
219
                    'locationId' => $location->id,
220
                    'parentLocationId' => $location->parentLocationId,
221
                )
222
            )
223
        );
224
225
        return $returnValue;
226
    }
227
228
    /**
229
     * Swaps the contents held by $location1 and $location2.
230
     *
231
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to swap content
232
     *
233
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location1
234
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location2
235
     */
236
    public function swapLocation(Location $location1, Location $location2)
237
    {
238
        $returnValue = $this->service->swapLocation($location1, $location2);
239
        $this->signalDispatcher->emit(
240
            new SwapLocationSignal(
241
                array(
242
                    'location1Id' => $location1->id,
243
                    'content1Id' => $location1->contentId,
244
                    'parentLocation1Id' => $location1->parentLocationId,
245
                    'location2Id' => $location2->id,
246
                    'content2Id' => $location2->contentId,
247
                    'parentLocation2Id' => $location2->parentLocationId,
248
                )
249
            )
250
        );
251
252
        return $returnValue;
253
    }
254
255
    /**
256
     * Hides the $location and marks invisible all descendants of $location.
257
     *
258
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to hide this location
259
     *
260
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
261
     *
262
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
263
     */
264 View Code Duplication
    public function hideLocation(Location $location)
265
    {
266
        $returnValue = $this->service->hideLocation($location);
267
        $this->signalDispatcher->emit(
268
            new HideLocationSignal(
269
                array(
270
                    'locationId' => $location->id,
271
                    'contentId' => $location->contentId,
272
                    'currentVersionNo' => $returnValue->getContentInfo()->currentVersionNo,
273
                    'parentLocationId' => $returnValue->parentLocationId,
274
                )
275
            )
276
        );
277
278
        return $returnValue;
279
    }
280
281
    /**
282
     * Unhides the $location.
283
     *
284
     * This method and marks visible all descendants of $locations
285
     * until a hidden location is found.
286
     *
287
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to unhide this location
288
     *
289
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
290
     *
291
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
292
     */
293 View Code Duplication
    public function unhideLocation(Location $location)
294
    {
295
        $returnValue = $this->service->unhideLocation($location);
296
        $this->signalDispatcher->emit(
297
            new UnhideLocationSignal(
298
                array(
299
                    'locationId' => $location->id,
300
                    'contentId' => $location->contentId,
301
                    'currentVersionNo' => $returnValue->getContentInfo()->currentVersionNo,
302
                    'parentLocationId' => $returnValue->parentLocationId,
303
                )
304
            )
305
        );
306
307
        return $returnValue;
308
    }
309
310
    /**
311
     * Moves the subtree to $newParentLocation.
312
     *
313
     * If a user has the permission to move the location to a target location
314
     * he can do it regardless of an existing descendant on which the user has no permission.
315
     *
316
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to move this location to the target
317
     *
318
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
319
     * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation
320
     */
321
    public function moveSubtree(Location $location, Location $newParentLocation)
322
    {
323
        $returnValue = $this->service->moveSubtree($location, $newParentLocation);
324
        $this->signalDispatcher->emit(
325
            new MoveSubtreeSignal(
326
                array(
327
                    'locationId' => $location->id,
328
                    'newParentLocationId' => $newParentLocation->id,
329
                    'oldParentLocationId' => $location->parentLocationId,
330
                )
331
            )
332
        );
333
334
        return $returnValue;
335
    }
336
337
    /**
338
     * Deletes $location and all its descendants.
339
     *
340
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant
341
     *
342
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
343
     */
344
    public function deleteLocation(Location $location)
345
    {
346
        $this->service->deleteLocation($location);
347
        $this->signalDispatcher->emit(
348
            new DeleteLocationSignal(
349
                array(
350
                    'contentId' => $location->contentId,
351
                    'locationId' => $location->id,
352
                    'parentLocationId' => $location->parentLocationId,
353
                )
354
            )
355
        );
356
    }
357
358
    /**
359
     * Instantiates a new location create class.
360
     *
361
     * @param mixed $parentLocationId the parent under which the new location should be created
362
     *
363
     * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
364
     */
365
    public function newLocationCreateStruct($parentLocationId)
366
    {
367
        return $this->service->newLocationCreateStruct($parentLocationId);
368
    }
369
370
    /**
371
     * Instantiates a new location update class.
372
     *
373
     * @return \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct
374
     */
375
    public function newLocationUpdateStruct()
376
    {
377
        return $this->service->newLocationUpdateStruct();
378
    }
379
}
380