Пример #1
0
 function createObject($contentClassID, $parentNodeID = 2)
 {
     $class = eZContentClass::fetch($contentClassID);
     $parentNode = eZContentObjectTreeNode::fetch($parentNodeID);
     $parentContentObject = $parentNode->attribute('object');
     $sectionID = $parentContentObject->attribute('section_id');
     $object = $class->instantiate(false, $sectionID);
     //        $parentContentObject = $parentNode->attribute( 'contentobject' );
     $node = eZContentObjectTreeNode::addChildTo($object->attribute("id"), $parentNodeID, true);
     //        $object->setAttribute( "main_node_id", $node->attribute( 'node_id' ) );
     $node->setAttribute('main_node_id', $node->attribute('node_id'));
     $object->store();
     $node->store();
     return $object;
 }
    /**
     * Adds a new location (node) to the current object.
     *
     * Transaction unsafe. If you call several transaction unsafe methods you must enclose
     * the calls within a db transaction; thus within db->begin and db->commit.
     *
     * @param int $parentNodeID The id of the node to use as parent.
     * @param bool $asObject If true it will return the new child-node as an object, if not it returns the ID.
     *
     * @return eZContentObjectTreeNode|int
     */
    function addLocation( $parentNodeID, $asObject = false )
    {
        $node = eZContentObjectTreeNode::addChildTo( $this->ID, $parentNodeID, true, $this->CurrentVersion );

        $data = array( 'contentobject_id' => $this->ID,
                       'contentobject_version' => $this->attribute( 'current_version' ),
                       'parent_node' => $parentNodeID,
                       // parent_remote_id in node assignment holds remote id of the added location,
                       // not of the parent location or of the node assignment itself
                       'parent_remote_id' => $node->attribute( 'remote_id' ),
                       'is_main' => 0 );
        $nodeAssignment = eZNodeAssignment::create( $data );
        $nodeAssignment->setAttribute( 'op_code', eZNodeAssignment::OP_CODE_CREATE_NOP );
        $nodeAssignment->store();

        if ( $asObject )
        {
            return $node;
        }
        else
        {
            return $node->attribute( 'node_id' );
        }
    }