eZContentOperationCollection::addAssignment PHP Method

addAssignment() public static method

Adds a new nodeAssignment
public static addAssignment ( integer $nodeID, $objectID, array $selectedNodeIDArray ) : array
$nodeID integer
$selectedNodeIDArray array
return array An array with operation status, always true
    public static 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);
        return array('status' => true);
    }

Usage Example

Esempio n. 1
0
     return $module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
 }
 $existingNode = eZContentObjectTreeNode::fetch($nodeID);
 if (!$existingNode) {
     return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
 }
 $class = $object->contentClass();
 if ($module->isCurrentAction('AddAssignment')) {
     $selectedNodeIDArray = eZContentBrowse::result('AddNodeAssignment');
     if (!is_array($selectedNodeIDArray)) {
         $selectedNodeIDArray = array();
     }
     if (eZOperationHandler::operationIsAvailable('content_addlocation')) {
         $operationResult = eZOperationHandler::execute('content', 'addlocation', array('node_id' => $nodeID, 'object_id' => $objectID, 'select_node_id_array' => $selectedNodeIDArray), null, true);
     } else {
         eZContentOperationCollection::addAssignment($nodeID, $objectID, $selectedNodeIDArray);
     }
 } else {
     if ($module->isCurrentAction('SelectAssignmentLocation')) {
         $ignoreNodesSelect = array();
         $ignoreNodesClick = array();
         $assigned = eZNodeAssignment::fetchForObject($objectID, $object->attribute('current_version'), 0, false);
         $publishedAssigned = $object->assignedNodes(false);
         $isTopLevel = false;
         foreach ($publishedAssigned as $element) {
             $append = false;
             if ($element['parent_node_id'] == 1) {
                 $isTopLevel = true;
             }
             foreach ($assigned as $ass) {
                 if ($ass['parent_node'] == $element['parent_node_id']) {
All Usage Examples Of eZContentOperationCollection::addAssignment