The following code copies an existing object and gives it one location in the node tree. It was taken from the copy view of the content module (kernel/content/copy.php).
The used variables are:
$db = eZDB::instance();
$db->begin();
$newObject = $object->copy( $allVersions );
$curVersion        = $newObject->attribute( 'current_version' );
$curVersionObject  = $newObject->attribute( 'current' );
$newObjAssignments = $curVersionObject->attribute( 'node_assignments' );
unset( $curVersionObject );
// remove old node assignments
foreach( $newObjAssignments as $assignment )
{
    $assignment->purge();
}
// and create a new one
$nodeAssignment = eZNodeAssignment::create( array(
                                                 'contentobject_id' => $newObject->attribute( 'id' ),
                                                 'contentobject_version' => $curVersion,
                                                 'parent_node' => $newParentNodeID,
                                                 'is_main' => 1
                                                 ) );
$nodeAssignment->store();
// publish the newly created object
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $newObject->attribute( 'id' ),
                                                          'version'   => $curVersion ) );
// Update "is_invisible" attribute for the newly created node.
$newNode = $newObject->attribute( 'main_node' );
eZContentObjectTreeNode::updateNodeVisibility( $newNode, $newParentNode );
$db->commit();    Article provided by eZpedia
All text is available under the terms of the GNU Free Documentation License
Powered by eZ Publish 6.0.2stable
Hosted by USA eZ Publish Community Partner : Brookins Consulting