Lex 007
|
Friday 11 March 2005 2:46:46 am
I made it. Code based on the action.php provided in eZ Publish. Too bad I didn't get any answer from this Forum once again ... Alex
// *****************************************************************************************************
//
// FUNCTION addLocation : add node location for an object
// $objectID : object ID of the object we want to move
// $newNodeID : node ID of the new location we want to add for this object
//
// *****************************************************************************************************
function addLocation($objectID,$newNodeID) {
$object =& eZContentObject::fetch( $objectID );
$nodeID = $object->attribute("main_node_id");
$version =& $object->currentVersion();
$class =& $object->contentClass();
$existingNode =& eZContentObjectTreeNode::fetch( $nodeID );
$selectedNodeIDArray = array($newNodeID);
$assignedNodes =& $version->nodeAssignments();
$assignedIDArray = array();
$setMainNode = false;
$hasMainNode = false;
foreach ( $assignedNodes as $assignedNode )
{
$assignedNodeID = $assignedNode->attribute( 'parent_node' );
if ( $assignedNode->attribute( 'is_main' ) )
$hasMainNode = true;
$assignedIDArray[] = $assignedNodeID;
}
if ( !$hasMainNode )
$setMainNode = true;
$mainNodeID = $existingNode->attribute( 'main_node_id' );
$objectName = $object->attribute( 'name' );
foreach ( $selectedNodeIDArray as $selectedNodeID )
{
if ( !in_array( $selectedNodeID, $assignedIDArray ) )
{
$isPermitted = true;
$parentNode =& eZContentObjectTreeNode::fetch( $selectedNodeID );
$parentNodeObject =& $parentNode->attribute( 'object' );
$canCreate = $parentNode->checkAccess( 'create', $class->attribute( 'id' ), $parentNodeObject->attribute( 'contentclass_id' ) ) == 1;
if ( $isPermitted )
{
$isMain = 0;
if ( $setMainNode )
$isMain = 1;
$setMainNode = false;
$nodeAssignment =& $version->assignToNode( $selectedNodeID, $isMain );
$newNode =& $parentNode->addChild( $object->attribute( 'id' ), 0, true );
$newNode->setAttribute( 'sort_field', $nodeAssignment->attribute( 'sort_field' ) );
$newNode->setAttribute( 'sort_order', $nodeAssignment->attribute( 'sort_order' ) );
$newNode->setAttribute( 'contentobject_version', $version->attribute( 'version' ) );
$newNode->setAttribute( 'contentobject_is_published', 1 );
$newNode->setAttribute( 'main_node_id', $mainNodeID );
$newNode->setName( $objectName );
$newNode->updateSubTreePath();
$newNode->store();
eZContentObjectTreeNode::updateNodeVisibility( $newNode, $parentNode, false );
}
}
}
include_once( 'kernel/content/ezcontentoperationcollection.php' );
eZContentOperationCollection::clearObjectViewCache( $objectID, true );
eZContentObject::expireTemplateBlockCacheIfNeeded();
} // END function addLocation
|
Milad P
|
Tuesday 25 July 2006 8:10:27 am
I worked well, but how do i remove a location correctly from a user? With my current code i can remove locations but i can't add same user to the group again.
$thenode =& eZContentObjectTreeNode::fetch( $nodeID );
$thenode->remove();
|