eZ\Publish\Core\Persistence\Legacy\Content\Mapper::createVersionInfoFromCreateStruct PHP Method

createVersionInfoFromCreateStruct() public method

Creates a new version for the given $struct and $versionNo.
public createVersionInfoFromCreateStruct ( eZ\Publish\SPI\Persistence\Content\CreateStruct $struct, mixed $versionNo ) : eZ\Publish\SPI\Persistence\Content\VersionInfo
$struct eZ\Publish\SPI\Persistence\Content\CreateStruct
$versionNo mixed
return eZ\Publish\SPI\Persistence\Content\VersionInfo
    public function createVersionInfoFromCreateStruct(CreateStruct $struct, $versionNo)
    {
        $versionInfo = new VersionInfo();
        $versionInfo->id = null;
        $versionInfo->contentInfo = $this->createContentInfoFromCreateStruct($struct, $versionNo);
        $versionInfo->versionNo = $versionNo;
        $versionInfo->creatorId = $struct->ownerId;
        $versionInfo->status = VersionInfo::STATUS_DRAFT;
        $versionInfo->initialLanguageCode = $this->languageHandler->load($struct->initialLanguageId)->languageCode;
        $versionInfo->creationDate = $struct->modified;
        $versionInfo->modificationDate = $struct->modified;
        $versionInfo->names = $struct->name;
        $languageIds = array();
        foreach ($struct->fields as $field) {
            if (!isset($languageIds[$field->languageCode])) {
                $languageIds[$field->languageCode] = $this->languageHandler->loadByLanguageCode($field->languageCode)->id;
            }
        }
        $versionInfo->languageIds = array_values($languageIds);
        return $versionInfo;
    }

Usage Example

コード例 #1
0
ファイル: Handler.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * Creates a new Content entity in the storage engine.
  *
  * The values contained inside the $content will form the basis of stored
  * entity.
  *
  * Will contain always a complete list of fields.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\CreateStruct $struct Content creation struct.
  * @param mixed $versionNo Used by self::copy() to maintain version numbers
  *
  * @return \eZ\Publish\SPI\Persistence\Content Content value object
  */
 protected function internalCreate(CreateStruct $struct, $versionNo = 1)
 {
     $content = new Content();
     $content->fields = $struct->fields;
     $content->versionInfo = $this->mapper->createVersionInfoFromCreateStruct($struct, $versionNo);
     $content->versionInfo->contentInfo->id = $this->contentGateway->insertContentObject($struct, $versionNo);
     $content->versionInfo->id = $this->contentGateway->insertVersion($content->versionInfo, $struct->fields);
     $contentType = $this->contentTypeHandler->load($struct->typeId);
     $this->fieldHandler->createNewFields($content, $contentType);
     // Create node assignments
     foreach ($struct->locations as $location) {
         $location->contentId = $content->versionInfo->contentInfo->id;
         $location->contentVersion = $content->versionInfo->versionNo;
         $this->locationGateway->createNodeAssignment($location, $location->parentId, LocationGateway::NODE_ASSIGNMENT_OP_CODE_CREATE);
     }
     // Create names
     foreach ($content->versionInfo->names as $language => $name) {
         $this->contentGateway->setName($content->versionInfo->contentInfo->id, $content->versionInfo->versionNo, $name, $language);
     }
     return $content;
 }