Completed
Push — 6.13 ( b9a79e )
by
unknown
25:06 queued 12:25
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 View Code Duplication
    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
                )
194
            )
195
        );
196
197
        return $returnValue;
198
    }
199
200
    /**
201
     * Updates $location in the content repository.
202
     *
203
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
204
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
205
     *
206
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
207
     * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
208
     *
209
     * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
210
     */
211
    public function updateLocation(Location $location, LocationUpdateStruct $locationUpdateStruct)
212
    {
213
        $returnValue = $this->service->updateLocation($location, $locationUpdateStruct);
214
        $this->signalDispatcher->emit(
215
            new UpdateLocationSignal(
216
                array(
217
                    'contentId' => $location->contentId,
218
                    'locationId' => $location->id,
219
                )
220
            )
221
        );
222
223
        return $returnValue;
224
    }
225
226
    /**
227
     * Swaps the contents held by $location1 and $location2.
228
     *
229
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to swap content
230
     *
231
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location1
232
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location2
233
     */
234 View Code Duplication
    public function swapLocation(Location $location1, Location $location2)
235
    {
236
        $returnValue = $this->service->swapLocation($location1, $location2);
237
        $this->signalDispatcher->emit(
238
            new SwapLocationSignal(
239
                array(
240
                    'location1Id' => $location1->id,
241
                    'content1Id' => $location1->contentId,
242
                    'location2Id' => $location2->id,
243
                    'content2Id' => $location2->contentId,
244
                )
245
            )
246
        );
247
248
        return $returnValue;
249
    }
250
251
    /**
252
     * Hides the $location and marks invisible all descendants of $location.
253
     *
254
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to hide this location
255
     *
256
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
257
     *
258
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
259
     */
260 View Code Duplication
    public function hideLocation(Location $location)
261
    {
262
        $returnValue = $this->service->hideLocation($location);
263
        $this->signalDispatcher->emit(
264
            new HideLocationSignal(
265
                array(
266
                    'locationId' => $location->id,
267
                    'contentId' => $location->contentId,
268
                    'currentVersionNo' => $returnValue->getContentInfo()->currentVersionNo,
269
                )
270
            )
271
        );
272
273
        return $returnValue;
274
    }
275
276
    /**
277
     * Unhides the $location.
278
     *
279
     * This method and marks visible all descendants of $locations
280
     * until a hidden location is found.
281
     *
282
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to unhide this location
283
     *
284
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
285
     *
286
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
287
     */
288 View Code Duplication
    public function unhideLocation(Location $location)
289
    {
290
        $returnValue = $this->service->unhideLocation($location);
291
        $this->signalDispatcher->emit(
292
            new UnhideLocationSignal(
293
                array(
294
                    'locationId' => $location->id,
295
                    'contentId' => $location->contentId,
296
                    'currentVersionNo' => $returnValue->getContentInfo()->currentVersionNo,
297
                )
298
            )
299
        );
300
301
        return $returnValue;
302
    }
303
304
    /**
305
     * Moves the subtree to $newParentLocation.
306
     *
307
     * If a user has the permission to move the location to a target location
308
     * he can do it regardless of an existing descendant on which the user has no permission.
309
     *
310
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to move this location to the target
311
     *
312
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
313
     * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation
314
     */
315 View Code Duplication
    public function moveSubtree(Location $location, Location $newParentLocation)
316
    {
317
        $returnValue = $this->service->moveSubtree($location, $newParentLocation);
318
        $this->signalDispatcher->emit(
319
            new MoveSubtreeSignal(
320
                array(
321
                    'locationId' => $location->id,
322
                    'newParentLocationId' => $newParentLocation->id,
323
                )
324
            )
325
        );
326
327
        return $returnValue;
328
    }
329
330
    /**
331
     * Deletes $location and all its descendants.
332
     *
333
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant
334
     *
335
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
336
     */
337
    public function deleteLocation(Location $location)
338
    {
339
        $this->service->deleteLocation($location);
340
        $this->signalDispatcher->emit(
341
            new DeleteLocationSignal(
342
                array(
343
                    'contentId' => $location->contentId,
344
                    'locationId' => $location->id,
345
                    'parentLocationId' => $location->parentLocationId,
346
                )
347
            )
348
        );
349
    }
350
351
    /**
352
     * Instantiates a new location create class.
353
     *
354
     * @param mixed $parentLocationId the parent under which the new location should be created
355
     *
356
     * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
357
     */
358
    public function newLocationCreateStruct($parentLocationId)
359
    {
360
        return $this->service->newLocationCreateStruct($parentLocationId);
361
    }
362
363
    /**
364
     * Instantiates a new location update class.
365
     *
366
     * @return \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct
367
     */
368
    public function newLocationUpdateStruct()
369
    {
370
        return $this->service->newLocationUpdateStruct();
371
    }
372
}
373