kernel/content/ezcontentoperationcollection.php
static public function addAssignment( $nodeID, $objectID, $selectedNodeIDArray )
    {
        $userClassIDArray = eZUser::contentClassIDs();

        $object = eZContentObject::fetch( $objectID );
        $class = $object->contentClass();

        $nodeAssignmentList = eZNodeAssignment::fetchForObject( $objectID, $object->attribute( 'current_version' ), 0, false );
        $assignedNodes = $object->assignedNodes();

        $parentNodeIDArray = array();

        foreach ( $assignedNodes as $assignedNode )
        {
            $append = false;
            foreach ( $nodeAssignmentList as $nodeAssignment )
            {
                if ( $nodeAssignment['parent_node'] == $assignedNode->attribute( 'parent_node_id' ) )
                {
                    $append = true;
                    break;
                }
            }
            if ( $append )
            {
                $parentNodeIDArray[] = $assignedNode->attribute( 'parent_node_id' );
            }
        }

        $db = eZDB::instance();
        $db->begin();
        $locationAdded = false;
        $node = eZContentObjectTreeNode::fetch( $nodeID );
        foreach ( $selectedNodeIDArray as $selectedNodeID )
        {
            if ( !in_array( $selectedNodeID, $parentNodeIDArray ) )
            {
                $parentNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
                $parentNodeObject = $parentNode->attribute( 'object' );

                $canCreate = ( ( $parentNode->checkAccess( 'create', $class->attribute( 'id' ), $parentNodeObject->attribute( 'contentclass_id' ) ) == 1 ) ||
                                ( $parentNode->canAddLocation() && $node->canRead() ) );

                if ( $canCreate )
                {
                    $insertedNode = $object->addLocation( $selectedNodeID, true );

                    // Now set is as published and fix main_node_id
                    $insertedNode->setAttribute( 'contentobject_is_published', 1 );
                    $insertedNode->setAttribute( 'main_node_id', $node->attribute( 'main_node_id' ) );
                    $insertedNode->setAttribute( 'contentobject_version', $node->attribute( 'contentobject_version' ) );
                    // Make sure the url alias is set updated.
                    $insertedNode->updateSubTreePath();
                    $insertedNode->sync();

                    $locationAdded = true;
                }
            }
        }
        if ( $locationAdded )
        {

            //call appropriate method from search engine
            eZSearch::addNodeAssignment( $nodeID, $objectID, $selectedNodeIDArray );

            // clear user policy cache if this was a user object
            if ( in_array( $object->attribute( 'contentclass_id' ), $userClassIDArray ) )
            {
                eZUser::purgeUserCacheByUserId( $object->attribute( 'id' ) );
            }


        }
        $db->commit();

        eZContentCacheManager::clearContentCacheIfNeeded( $objectID );

        if ( !eZSearch::getEngine() instanceof eZSearchEngine )
        {
            eZContentOperationCollection::registerSearchObject( $objectID );
        }

        return array( 'status' => true );
    }
static public function addAssignment( $nodeID, $objectID, $selectedNodeIDArray )
    {
        $userClassIDArray = eZUser::contentClassIDs();

        $object = eZContentObject::fetch( $objectID );
        $class = $object->contentClass();

        $nodeAssignmentList = eZNodeAssignment::fetchForObject( $objectID, $object->attribute( 'current_version' ), 0, false );
        $assignedNodes = $object->assignedNodes();

        $parentNodeIDArray = array();

        foreach ( $assignedNodes as $assignedNode )
        {
            $append = false;
            foreach ( $nodeAssignmentList as $nodeAssignment )
            {
                if ( $nodeAssignment['parent_node'] == $assignedNode->attribute( 'parent_node_id' ) )
                {
                    $append = true;
                    break;
                }
            }
            if ( $append )
            {
                $parentNodeIDArray[] = $assignedNode->attribute( 'parent_node_id' );
            }
        }

        $db = eZDB::instance();
        $db->begin();
        $locationAdded = false;
        $node = eZContentObjectTreeNode::fetch( $nodeID );
        foreach ( $selectedNodeIDArray as $selectedNodeID )
        {
            if ( !in_array( $selectedNodeID, $parentNodeIDArray ) )
            {
                $parentNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
                $parentNodeObject = $parentNode->attribute( 'object' );

                $canCreate = ( ( $parentNode->checkAccess( 'create', $class->attribute( 'id' ), $parentNodeObject->attribute( 'contentclass_id' ) ) == 1 ) ||
                                ( $parentNode->canAddLocation() && $node->canRead() ) );

                if ( $canCreate )
                {
                    $insertedNode = $object->addLocation( $selectedNodeID, true );

                    // Now set is as published and fix main_node_id
                    $insertedNode->setAttribute( 'contentobject_is_published', 1 );
                    $insertedNode->setAttribute( 'main_node_id', $node->attribute( 'main_node_id' ) );
                    $insertedNode->setAttribute( 'contentobject_version', $node->attribute( 'contentobject_version' ) );
                    // Make sure the url alias is set updated.
                    $insertedNode->updateSubTreePath();
                    $insertedNode->sync();

                    $locationAdded = true;
                }
            }
        }
        if ( $locationAdded )
        {

            //call appropriate method from search engine
            eZSearch::addNodeAssignment( $nodeID, $objectID, $selectedNodeIDArray );

            // clear user policy cache if this was a user object
            if ( in_array( $object->attribute( 'contentclass_id' ), $userClassIDArray ) )
            {
                eZUser::purgeUserCacheByUserId( $object->attribute( 'id' ) );
            }


        }
        $db->commit();

        eZContentCacheManager::clearContentCacheIfNeeded( $objectID );

        if ( !eZSearch::getEngine() instanceof eZSearchEngine )
        {
            eZContentOperationCollection::registerSearchObject( $objectID );
        }

        return array( 'status' => true );
    }
static public function addAssignment ( $ nodeID , $ objectID , $ selectedNodeIDArray ) { $ userClassIDArray = eZUser :: contentClassIDs ( ) ; $ object = eZContentObject :: fetch ( $ objectID ) ; $ class = $ object -> contentClass ( ) ; $ nodeAssignmentList = eZNodeAssignment :: fetchForObject ( $ objectID , $ object -> attribute ( 'current_version' ) , 0 , false ) ; $ assignedNodes = $ object -> assignedNodes ( ) ; $ parentNodeIDArray = array ( ) ; foreach ( $ assignedNodes as $ assignedNode ) { $ append = false ; foreach ( $ nodeAssignmentList as $ nodeAssignment ) { if ( $ nodeAssignment [ 'parent_node' ] == $ assignedNode -> attribute ( 'parent_node_id' ) ) { $ append = true ; break ; } } if ( $ append ) { $ parentNodeIDArray [ ] = $ assignedNode -> attribute ( 'parent_node_id' ) ; } } $ db = eZDB :: instance ( ) ; $ db -> begin ( ) ; $ locationAdded = false ; $ node = eZContentObjectTreeNode :: fetch ( $ nodeID ) ; foreach ( $ selectedNodeIDArray as $ selectedNodeID ) { if ( ! in_array ( $ selectedNodeID , $ parentNodeIDArray ) ) { $ parentNode = eZContentObjectTreeNode :: fetch ( $ selectedNodeID ) ; $ parentNodeObject = $ parentNode -> attribute ( 'object' ) ; $ canCreate = ( ( $ parentNode -> checkAccess ( 'create' , $ class -> attribute ( 'id' ) , $ parentNodeObject -> attribute ( 'contentclass_id' ) ) == 1 ) || ( $ parentNode -> canAddLocation ( ) && $ node -> canRead ( ) ) ) ; if ( $ canCreate ) { $ insertedNode = $ object -> addLocation ( $ selectedNodeID , true ) ; // Now set is as published and fix main_node_id $ insertedNode -> setAttribute ( 'contentobject_is_published' , 1 ) ; $ insertedNode -> setAttribute ( 'main_node_id' , $ node -> attribute ( 'main_node_id' ) ) ; $ insertedNode -> setAttribute ( 'contentobject_version' , $ node -> attribute ( 'contentobject_version' ) ) ; // Make sure the url alias is set updated. $ insertedNode -> updateSubTreePath ( ) ; $ insertedNode -> sync ( ) ; $ locationAdded = true ; } } } if ( $ locationAdded ) { //call appropriate method from search engine eZSearch :: addNodeAssignment ( $ nodeID , $ objectID , $ selectedNodeIDArray ) ; // clear user policy cache if this was a user object if ( in_array ( $ object -> attribute ( 'contentclass_id' ) , $ userClassIDArray ) ) { eZUser :: purgeUserCacheByUserId ( $ object -> attribute ( 'id' ) ) ; } } $ db -> commit ( ) ; eZContentCacheManager :: clearContentCacheIfNeeded ( $ objectID ) ; if ( ! eZSearch :: getEngine ( ) instanceof eZSearchEngine ) { eZContentOperationCollection :: registerSearchObject ( $ objectID ) ; } return array ( 'status' => true ) ; }
Adds a new nodeAssignment

@param int $nodeID
@param int $objectId
@param array $selectedNodeIDArray

@return array An array with operation status, always true
Adds a new nodeAssignment