eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::create PHP Method

create() public method

Creates a new location in given $parentNode.
public create ( eZ\Publish\SPI\Persistence\Content\Location\CreateStruct $createStruct, array $parentNode ) : eZ\Publish\SPI\Persistence\Content\Location
$createStruct eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
$parentNode array
return eZ\Publish\SPI\Persistence\Content\Location
    public function create(CreateStruct $createStruct, array $parentNode)
    {
        $location = new Location();
        /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
        $query = $this->handler->createInsertQuery();
        $query->insertInto($this->handler->quoteTable('ezcontentobject_tree'))->set($this->handler->quoteColumn('contentobject_id'), $query->bindValue($location->contentId = $createStruct->contentId, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('contentobject_is_published'), $query->bindValue(1, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('contentobject_version'), $query->bindValue($createStruct->contentVersion, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('depth'), $query->bindValue($location->depth = $parentNode['depth'] + 1, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('is_hidden'), $query->bindValue($location->hidden = $createStruct->hidden, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('is_invisible'), $query->bindValue($location->invisible = $createStruct->invisible, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('modified_subnode'), $query->bindValue(time(), null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('node_id'), $this->handler->getAutoIncrementValue('ezcontentobject_tree', 'node_id'))->set($this->handler->quoteColumn('parent_node_id'), $query->bindValue($location->parentId = $parentNode['node_id'], null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('path_identification_string'), $query->bindValue($location->pathIdentificationString = $createStruct->pathIdentificationString, null, \PDO::PARAM_STR))->set($this->handler->quoteColumn('path_string'), $query->bindValue('dummy'))->set($this->handler->quoteColumn('priority'), $query->bindValue($location->priority = $createStruct->priority, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('remote_id'), $query->bindValue($location->remoteId = $createStruct->remoteId, null, \PDO::PARAM_STR))->set($this->handler->quoteColumn('sort_field'), $query->bindValue($location->sortField = $createStruct->sortField, null, \PDO::PARAM_INT))->set($this->handler->quoteColumn('sort_order'), $query->bindValue($location->sortOrder = $createStruct->sortOrder, null, \PDO::PARAM_INT));
        $query->prepare()->execute();
        $location->id = $this->handler->lastInsertId($this->handler->getSequenceName('ezcontentobject_tree', 'node_id'));
        $mainLocationId = $createStruct->mainLocationId === true ? $location->id : $createStruct->mainLocationId;
        $location->pathString = $parentNode['path_string'] . $location->id . '/';
        /** @var $query \eZ\Publish\Core\Persistence\Database\UpdateQuery */
        $query = $this->handler->createUpdateQuery();
        $query->update($this->handler->quoteTable('ezcontentobject_tree'))->set($this->handler->quoteColumn('path_string'), $query->bindValue($location->pathString))->set($this->handler->quoteColumn('main_node_id'), $query->bindValue($mainLocationId, null, \PDO::PARAM_INT))->where($query->expr->eq($this->handler->quoteColumn('node_id'), $query->bindValue($location->id, null, \PDO::PARAM_INT)));
        $query->prepare()->execute();
        return $location;
    }