eZ\Publish\Core\Repository\Helper\DomainMapper::isValidLocationSortOrder PHP Method

isValidLocationSortOrder() public method

Checks if given $sortOrder value is one of the defined sort order constants.
public isValidLocationSortOrder ( mixed $sortOrder ) : boolean
$sortOrder mixed
return boolean
    public function isValidLocationSortOrder($sortOrder)
    {
        switch ($sortOrder) {
            case APILocation::SORT_ORDER_DESC:
            case APILocation::SORT_ORDER_ASC:
                return true;
        }
        return false;
    }

Usage Example

 /**
  * Updates $location in the content repository.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
  */
 public function updateLocation(APILocation $location, LocationUpdateStruct $locationUpdateStruct)
 {
     if ($locationUpdateStruct->priority !== null && !is_int($locationUpdateStruct->priority)) {
         throw new InvalidArgumentValue('priority', $locationUpdateStruct->priority, 'LocationUpdateStruct');
     }
     if ($locationUpdateStruct->remoteId !== null && (!is_string($locationUpdateStruct->remoteId) || empty($locationUpdateStruct->remoteId))) {
         throw new InvalidArgumentValue('remoteId', $locationUpdateStruct->remoteId, 'LocationUpdateStruct');
     }
     if ($locationUpdateStruct->sortField !== null && !$this->domainMapper->isValidLocationSortField($locationUpdateStruct->sortField)) {
         throw new InvalidArgumentValue('sortField', $locationUpdateStruct->sortField, 'LocationUpdateStruct');
     }
     if ($locationUpdateStruct->sortOrder !== null && !$this->domainMapper->isValidLocationSortOrder($locationUpdateStruct->sortOrder)) {
         throw new InvalidArgumentValue('sortOrder', $locationUpdateStruct->sortOrder, 'LocationUpdateStruct');
     }
     $loadedLocation = $this->loadLocation($location->id);
     if ($locationUpdateStruct->remoteId !== null) {
         try {
             $existingLocation = $this->loadLocationByRemoteId($locationUpdateStruct->remoteId);
             if ($existingLocation !== null && $existingLocation->id !== $loadedLocation->id) {
                 throw new InvalidArgumentException('locationUpdateStruct', 'location with provided remote ID already exists');
             }
         } catch (APINotFoundException $e) {
         }
     }
     if (!$this->repository->canUser('content', 'edit', $loadedLocation->getContentInfo(), $loadedLocation)) {
         throw new UnauthorizedException('content', 'edit');
     }
     $updateStruct = new UpdateStruct();
     $updateStruct->priority = $locationUpdateStruct->priority !== null ? $locationUpdateStruct->priority : $loadedLocation->priority;
     $updateStruct->remoteId = $locationUpdateStruct->remoteId !== null ? trim($locationUpdateStruct->remoteId) : $loadedLocation->remoteId;
     $updateStruct->sortField = $locationUpdateStruct->sortField !== null ? $locationUpdateStruct->sortField : $loadedLocation->sortField;
     $updateStruct->sortOrder = $locationUpdateStruct->sortOrder !== null ? $locationUpdateStruct->sortOrder : $loadedLocation->sortOrder;
     $this->repository->beginTransaction();
     try {
         $this->persistenceHandler->locationHandler()->update($updateStruct, $loadedLocation->id);
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->loadLocation($loadedLocation->id);
 }
All Usage Examples Of eZ\Publish\Core\Repository\Helper\DomainMapper::isValidLocationSortOrder