Wednesday 26 May 2004 1:16:53 am
Here's a code snippet to change an object's node assignment
// get max version
$maxVersion =& $object->getVersionCount();
$version =& $object->version( $maxVersion );
$nodeAssignments = $version->nodeAssignments();
// remove wrong nodeassignments
foreach ($nodeAssignments as $assignment)
{
$parentObject = $assignment->getParentNode();
if ($parentObject->attribute('main_node_id') == 12)
{
$version->removeAssignment(12);
}
else
{
if ($assignment->attribute( 'is_main' ) == '1')
{
$nodeId = $assignment->getParentNode();
$version->removeAssignment($nodeId);
$version->assignToNode($nodeId, 0);
}
}
}
$version->removeAssignment(546);
$version->assignToNode(546, 1, 12);
$version->store();
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $objectId, 'version' => $maxVersion ) );
Where 12 and 546 are node ids. This was used to move users from one group to another or to add them to a second group.
As far as I remember you have to remove the main node before assigning another node (which you want to be the new main node), otherwise there will be some trouble with two main nodes.
Hope this helps, Silke
|