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

buildVersionInfoDomainObject() public method

Builds a VersionInfo domain object from value object returned from persistence.
public buildVersionInfoDomainObject ( eZ\Publish\SPI\Persistence\Content\VersionInfo $spiVersionInfo ) : VersionInfo
$spiVersionInfo eZ\Publish\SPI\Persistence\Content\VersionInfo
return eZ\Publish\Core\Repository\Values\Content\VersionInfo
    public function buildVersionInfoDomainObject(SPIVersionInfo $spiVersionInfo)
    {
        $languageCodes = array();
        foreach ($spiVersionInfo->languageIds as $languageId) {
            $languageCodes[] = $this->contentLanguageHandler->load($languageId)->languageCode;
        }
        // Map SPI statuses to API
        switch ($spiVersionInfo->status) {
            case SPIVersionInfo::STATUS_ARCHIVED:
                $status = APIVersionInfo::STATUS_ARCHIVED;
                break;
            case SPIVersionInfo::STATUS_PUBLISHED:
                $status = APIVersionInfo::STATUS_PUBLISHED;
                break;
            case SPIVersionInfo::STATUS_DRAFT:
            default:
                $status = APIVersionInfo::STATUS_DRAFT;
        }
        return new VersionInfo(array('id' => $spiVersionInfo->id, 'versionNo' => $spiVersionInfo->versionNo, 'modificationDate' => $this->getDateTime($spiVersionInfo->modificationDate), 'creatorId' => $spiVersionInfo->creatorId, 'creationDate' => $this->getDateTime($spiVersionInfo->creationDate), 'status' => $status, 'initialLanguageCode' => $spiVersionInfo->initialLanguageCode, 'languageCodes' => $languageCodes, 'names' => $spiVersionInfo->names, 'contentInfo' => $this->buildContentInfoDomainObject($spiVersionInfo->contentInfo)));
    }

Usage Example

 /**
  * Copies the content to a new location. If no version is given,
  * all versions are copied, otherwise only the given version.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location
  *
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to
  * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null)
 {
     if (!$this->repository->canUser('content', 'create', $contentInfo, $destinationLocationCreateStruct)) {
         throw new UnauthorizedException('content', 'create', array('parentLocationId' => $destinationLocationCreateStruct->parentLocationId, 'sectionId' => $contentInfo->sectionId));
     }
     $defaultObjectStates = $this->getDefaultObjectStates();
     $this->repository->beginTransaction();
     try {
         $spiContent = $this->persistenceHandler->contentHandler()->copy($contentInfo->id, $versionInfo ? $versionInfo->versionNo : null);
         foreach ($defaultObjectStates as $objectStateGroupId => $objectState) {
             $this->persistenceHandler->objectStateHandler()->setContentState($spiContent->versionInfo->contentInfo->id, $objectStateGroupId, $objectState->id);
         }
         $content = $this->internalPublishVersion($this->domainMapper->buildVersionInfoDomainObject($spiContent->versionInfo), $spiContent->versionInfo->creationDate);
         $this->repository->getLocationService()->createLocation($content->getVersionInfo()->getContentInfo(), $destinationLocationCreateStruct);
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->internalLoadContent($content->id);
 }