vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/SignalSlot/LocationService.php line 94

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace eZ\Publish\Core\SignalSlot;
  7. use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
  8. use eZ\Publish\API\Repository\Values\Content\Location;
  9. use eZ\Publish\API\Repository\Values\Content\ContentInfo;
  10. use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
  11. use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct;
  12. use eZ\Publish\API\Repository\Values\Content\VersionInfo;
  13. use eZ\Publish\Core\SignalSlot\Signal\LocationService\CopySubtreeSignal;
  14. use eZ\Publish\Core\SignalSlot\Signal\LocationService\CreateLocationSignal;
  15. use eZ\Publish\Core\SignalSlot\Signal\LocationService\UpdateLocationSignal;
  16. use eZ\Publish\Core\SignalSlot\Signal\LocationService\SwapLocationSignal;
  17. use eZ\Publish\Core\SignalSlot\Signal\LocationService\HideLocationSignal;
  18. use eZ\Publish\Core\SignalSlot\Signal\LocationService\UnhideLocationSignal;
  19. use eZ\Publish\Core\SignalSlot\Signal\LocationService\MoveSubtreeSignal;
  20. use eZ\Publish\Core\SignalSlot\Signal\LocationService\DeleteLocationSignal;
  21. use eZ\Publish\API\Repository\Values\ContentType\ContentType;
  22. /**
  23.  * LocationService class.
  24.  */
  25. class LocationService implements LocationServiceInterface
  26. {
  27.     /**
  28.      * Aggregated service.
  29.      *
  30.      * @var \eZ\Publish\API\Repository\LocationService
  31.      */
  32.     protected $service;
  33.     /**
  34.      * SignalDispatcher.
  35.      *
  36.      * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher
  37.      */
  38.     protected $signalDispatcher;
  39.     /**
  40.      * Constructor.
  41.      *
  42.      * Construct service object from aggregated service and signal
  43.      * dispatcher
  44.      *
  45.      * @param \eZ\Publish\API\Repository\LocationService $service
  46.      * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
  47.      */
  48.     public function __construct(LocationServiceInterface $serviceSignalDispatcher $signalDispatcher)
  49.     {
  50.         $this->service $service;
  51.         $this->signalDispatcher $signalDispatcher;
  52.     }
  53.     /**
  54.      * Copies the subtree starting from $subtree as a new subtree of $targetLocation.
  55.      *
  56.      * Only the items on which the user has read access are copied.
  57.      *
  58.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed copy the subtree to the given parent location
  59.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree
  60.      * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the target location is a sub location of the given location
  61.      *
  62.      * @param \eZ\Publish\API\Repository\Values\Content\Location $subtree - the subtree denoted by the location to copy
  63.      * @param \eZ\Publish\API\Repository\Values\Content\Location $targetParentLocation - the target parent location for the copy operation
  64.      *
  65.      * @return \eZ\Publish\API\Repository\Values\Content\Location The newly created location of the copied subtree
  66.      */
  67.     public function copySubtree(Location $subtreeLocation $targetParentLocation)
  68.     {
  69.         $returnValue $this->service->copySubtree($subtree$targetParentLocation);
  70.         $this->signalDispatcher->emit(
  71.             new CopySubtreeSignal(
  72.                 [
  73.                     'subtreeId' => $subtree->id,
  74.                     'targetParentLocationId' => $targetParentLocation->id,
  75.                     'targetNewSubtreeId' => $returnValue->id,
  76.                 ]
  77.             )
  78.         );
  79.         return $returnValue;
  80.     }
  81.     /**
  82.      * {@inheritdoc}
  83.      */
  84.     public function loadLocation($locationId, array $prioritizedLanguages nullbool $useAlwaysAvailable null)
  85.     {
  86.         return $this->service->loadLocation($locationId$prioritizedLanguages$useAlwaysAvailable);
  87.     }
  88.     /**
  89.      * {@inheritdoc}
  90.      */
  91.     public function loadLocationList(array $locationIds, array $prioritizedLanguages nullbool $useAlwaysAvailable null): iterable
  92.     {
  93.         return $this->service->loadLocationList($locationIds$prioritizedLanguages$useAlwaysAvailable);
  94.     }
  95.     /**
  96.      * {@inheritdoc}
  97.      */
  98.     public function loadLocationByRemoteId($remoteId, array $prioritizedLanguages nullbool $useAlwaysAvailable null)
  99.     {
  100.         return $this->service->loadLocationByRemoteId($remoteId$prioritizedLanguages$useAlwaysAvailable);
  101.     }
  102.     /**
  103.      * {@inheritdoc}
  104.      */
  105.     public function loadLocations(ContentInfo $contentInfoLocation $rootLocation null, array $prioritizedLanguages null)
  106.     {
  107.         return $this->service->loadLocations($contentInfo$rootLocation$prioritizedLanguages);
  108.     }
  109.     /**
  110.      * {@inheritdoc}
  111.      */
  112.     public function loadLocationChildren(Location $location$offset 0$limit 25, array $prioritizedLanguages null)
  113.     {
  114.         return $this->service->loadLocationChildren($location$offset$limit$prioritizedLanguages);
  115.     }
  116.     /**
  117.      * {@inheritdoc}
  118.      */
  119.     public function loadParentLocationsForDraftContent(VersionInfo $versionInfo, array $prioritizedLanguages null)
  120.     {
  121.         return $this->service->loadParentLocationsForDraftContent($versionInfo$prioritizedLanguages);
  122.     }
  123.     /**
  124.      * Returns the number of children which are readable by the current user of a location object.
  125.      *
  126.      * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  127.      *
  128.      * @return int
  129.      */
  130.     public function getLocationChildCount(Location $location)
  131.     {
  132.         return $this->service->getLocationChildCount($location);
  133.     }
  134.     /**
  135.      * Creates the new $location in the content repository for the given content.
  136.      *
  137.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create this location
  138.      * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the content is already below the specified parent
  139.      *                                        or the parent is a sub location of the location of the content
  140.      *                                        or if set the remoteId exists already
  141.      *
  142.      * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  143.      * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
  144.      *
  145.      * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created Location
  146.      */
  147.     public function createLocation(ContentInfo $contentInfoLocationCreateStruct $locationCreateStruct)
  148.     {
  149.         $returnValue $this->service->createLocation($contentInfo$locationCreateStruct);
  150.         $this->signalDispatcher->emit(
  151.             new CreateLocationSignal(
  152.                 [
  153.                     'contentId' => $contentInfo->id,
  154.                     'locationId' => $returnValue->id,
  155.                     'parentLocationId' => $returnValue->parentLocationId,
  156.                 ]
  157.             )
  158.         );
  159.         return $returnValue;
  160.     }
  161.     /**
  162.      * Updates $location in the content repository.
  163.      *
  164.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
  165.      * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
  166.      *
  167.      * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  168.      * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
  169.      *
  170.      * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
  171.      */
  172.     public function updateLocation(Location $locationLocationUpdateStruct $locationUpdateStruct)
  173.     {
  174.         $returnValue $this->service->updateLocation($location$locationUpdateStruct);
  175.         $this->signalDispatcher->emit(
  176.             new UpdateLocationSignal(
  177.                 [
  178.                     'contentId' => $location->contentId,
  179.                     'locationId' => $location->id,
  180.                     'parentLocationId' => $location->parentLocationId,
  181.                 ]
  182.             )
  183.         );
  184.         return $returnValue;
  185.     }
  186.     /**
  187.      * Swaps the contents held by $location1 and $location2.
  188.      *
  189.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to swap content
  190.      *
  191.      * @param \eZ\Publish\API\Repository\Values\Content\Location $location1
  192.      * @param \eZ\Publish\API\Repository\Values\Content\Location $location2
  193.      */
  194.     public function swapLocation(Location $location1Location $location2)
  195.     {
  196.         $returnValue $this->service->swapLocation($location1$location2);
  197.         $this->signalDispatcher->emit(
  198.             new SwapLocationSignal(
  199.                 [
  200.                     'location1Id' => $location1->id,
  201.                     'content1Id' => $location1->contentId,
  202.                     'parentLocation1Id' => $location1->parentLocationId,
  203.                     'location2Id' => $location2->id,
  204.                     'content2Id' => $location2->contentId,
  205.                     'parentLocation2Id' => $location2->parentLocationId,
  206.                 ]
  207.             )
  208.         );
  209.         return $returnValue;
  210.     }
  211.     /**
  212.      * Hides the $location and marks invisible all descendants of $location.
  213.      *
  214.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to hide this location
  215.      *
  216.      * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  217.      *
  218.      * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
  219.      */
  220.     public function hideLocation(Location $location)
  221.     {
  222.         $returnValue $this->service->hideLocation($location);
  223.         $this->signalDispatcher->emit(
  224.             new HideLocationSignal(
  225.                 [
  226.                     'locationId' => $location->id,
  227.                     'contentId' => $location->contentId,
  228.                     'currentVersionNo' => $returnValue->getContentInfo()->currentVersionNo,
  229.                     'parentLocationId' => $returnValue->parentLocationId,
  230.                 ]
  231.             )
  232.         );
  233.         return $returnValue;
  234.     }
  235.     /**
  236.      * Unhides the $location.
  237.      *
  238.      * This method and marks visible all descendants of $locations
  239.      * until a hidden location is found.
  240.      *
  241.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to unhide this location
  242.      *
  243.      * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  244.      *
  245.      * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
  246.      */
  247.     public function unhideLocation(Location $location)
  248.     {
  249.         $returnValue $this->service->unhideLocation($location);
  250.         $this->signalDispatcher->emit(
  251.             new UnhideLocationSignal(
  252.                 [
  253.                     'locationId' => $location->id,
  254.                     'contentId' => $location->contentId,
  255.                     'currentVersionNo' => $returnValue->getContentInfo()->currentVersionNo,
  256.                     'parentLocationId' => $returnValue->parentLocationId,
  257.                 ]
  258.             )
  259.         );
  260.         return $returnValue;
  261.     }
  262.     /**
  263.      * {@inheritdoc}
  264.      */
  265.     public function moveSubtree(Location $locationLocation $newParentLocation)
  266.     {
  267.         $returnValue $this->service->moveSubtree($location$newParentLocation);
  268.         $this->signalDispatcher->emit(
  269.             new MoveSubtreeSignal(
  270.                 [
  271.                     'locationId' => $location->id,
  272.                     'newParentLocationId' => $newParentLocation->id,
  273.                     'oldParentLocationId' => $location->parentLocationId,
  274.                 ]
  275.             )
  276.         );
  277.         return $returnValue;
  278.     }
  279.     /**
  280.      * Deletes $location and all its descendants.
  281.      *
  282.      * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant
  283.      *
  284.      * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  285.      */
  286.     public function deleteLocation(Location $location)
  287.     {
  288.         $this->service->deleteLocation($location);
  289.         $this->signalDispatcher->emit(
  290.             new DeleteLocationSignal(
  291.                 [
  292.                     'contentId' => $location->contentId,
  293.                     'locationId' => $location->id,
  294.                     'parentLocationId' => $location->parentLocationId,
  295.                 ]
  296.             )
  297.         );
  298.     }
  299.     /**
  300.      * Instantiates a new location create class.
  301.      *
  302.      * @param mixed $parentLocationId the parent under which the new location should be created
  303.      * @param eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType
  304.      *
  305.      * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
  306.      */
  307.     public function newLocationCreateStruct($parentLocationIdContentType $contentType null)
  308.     {
  309.         return $this->service->newLocationCreateStruct($parentLocationId$contentType);
  310.     }
  311.     /**
  312.      * Instantiates a new location update class.
  313.      *
  314.      * @return \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct
  315.      */
  316.     public function newLocationUpdateStruct()
  317.     {
  318.         return $this->service->newLocationUpdateStruct();
  319.     }
  320.     /**
  321.      * Get the total number of all existing Locations. Can be combined with loadAllLocations.
  322.      *
  323.      * @see loadAllLocations
  324.      *
  325.      * @return int Total number of Locations
  326.      */
  327.     public function getAllLocationsCount(): int
  328.     {
  329.         return $this->service->getAllLocationsCount();
  330.     }
  331.     /**
  332.      * Bulk-load all existing Locations, constrained by $limit and $offset to paginate results.
  333.      *
  334.      * @param int $limit
  335.      * @param int $offset
  336.      *
  337.      * @return \eZ\Publish\API\Repository\Values\Content\Location[]
  338.      */
  339.     public function loadAllLocations(int $offset 0int $limit 25): array
  340.     {
  341.         return $this->service->loadAllLocations($offset$limit);
  342.     }
  343. }