} if (!$hasOtherNodeType and !$hasLDAPNodeType) { $noRemoveAssignmentList[$defaultUserPlacement] = 1; } $newVersion = $contentObject->createNewVersion(); $newVersionNr = $newVersion->attribute('version'); $nodeAssignmentList = $newVersion->attribute('node_assignments'); $noAddAssignmentList = array(); foreach ($nodeAssignmentList as $nodeAssignment) { $parentNodeID = $nodeAssignment->attribute('parent_node'); if (array_key_exists($parentNodeID, $noRemoveAssignmentList)) { $noAddAssignmentList[] = $parentNodeID; $nodeAssignment->setAttribute('parent_remote_id', uniqid('LDAP_')); $nodeAssignment->store(); } else { eZNodeAssignment::removeByID($nodeAssignment->attribute('id')); } } if ($hasOtherNodeType) { foreach ($otherNodeArray as $otherNode) { if (!in_array($otherNode['parent_node_id'], $noAddAssignmentList)) { $newVersion->assignToNode($otherNode['parent_node_id'], $otherNode['is_main']); } } } if ($hasLDAPNodeType) { foreach ($newLDAPNodeArray as $newLDAPNode) { if (!in_array($newLDAPNode['parent_node_id'], $noAddAssignmentList)) { $newVersion->assignToNode($newLDAPNode['parent_node_id'], $newLDAPNode['is_main']); } $assignment = eZNodeAssignment::fetch($contentObject->attribute('id'), $newVersionNr, $newLDAPNode['parent_node_id']);
function checkNodeActions( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage ) { // If the object has been previously published we do not allow node assignment operations if ( $object->attribute( 'status' ) != eZContentObject::STATUS_DRAFT ) { if ( !$module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { return; } } $http = eZHTTPTool::instance(); if ( $module->isCurrentAction( 'BrowseForNodes' ) || $module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { // Remove custom actions from attribute editing. $http->removeSessionVariable( 'BrowseCustomAction' ); $ignoreNodesSelect = array(); $ignoreNodesClick = array(); $assigned = $version->nodeAssignments(); $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->attribute( 'parent_node' ) == $element['parent_node_id'] ) $append = true; } /* If the current version (draft) has no assigned nodes then * we should disallow adding assignments under nodes * the previous published version is assignned to. * Thus we avoid fatal errors in eZ Publish. */ if ( count($assigned) == 0 ) { $ignoreNodesSelect[] = $element['node_id']; $ignoreNodesClick[] = $element['node_id']; } if ( $append ) { $ignoreNodesSelect[] = $element['node_id']; $ignoreNodesClick[] = $element['node_id']; $ignoreNodesSelect[] = $element['parent_node_id']; } } if ( !$isTopLevel ) { $ignoreNodesSelect = array_unique( $ignoreNodesSelect ); $objectID = $object->attribute( 'id' ); $action = 'AddNodeAssignment'; if ( $module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { $action = 'AddPrimaryNodeAssignment'; } eZContentBrowse::browse( array( 'action_name' => $action, 'description_template' => 'design:content/browse_placement.tpl', 'keys' => array( 'class' => $class->attribute( 'id' ), 'class_id' => $class->attribute( 'identifier' ), 'classgroup' => $class->attribute( 'ingroup_id_list' ), 'section' => $object->attribute( 'section_id' ) ), 'ignore_nodes_select' => $ignoreNodesSelect, 'ignore_nodes_click' => $ignoreNodesClick, 'content' => array( 'object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage ), 'from_page' => "/content/edit/$objectID/$editVersion/$editLanguage/$fromLanguage" ), $module ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } // If node assignment handling is diabled we return $useNodeAssigments = true; if ( $http->hasPostVariable( 'UseNodeAssigments' ) ) $useNodeAssigments = (bool)$http->postVariable( 'UseNodeAssigments' ); if ( !$useNodeAssigments ) return; // Remove custom actions from attribute editing. $http->removeSessionVariable( 'BrowseCustomAction' ); if ( $module->isCurrentAction( 'ConfirmAssignmentDelete' ) && $http->hasPostVariable( 'RemoveNodeID' ) ) { $nodeID = $http->postVariable( 'RemoveNodeID' ); $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } if ( $module->isCurrentAction( 'DeleteNode' ) ) { if ( $http->hasPostVariable( 'RemoveNodeID' ) ) { $nodeID = $http->postVariable( 'RemoveNodeID' ); } $mainNodeID = $http->postVariable( 'MainNodeID' ); // if ( $nodeID != $mainNodeID ) { $objectID = $object->attribute( 'id' ); $publishedNode = eZContentObjectTreeNode::fetchNode( $objectID, $nodeID ); if ( $publishedNode != null ) { $publishParentNodeID = $publishedNode->attribute( 'parent_node_id' ); if ( $publishParentNodeID > 1 ) { $childrenCount = $publishedNode->childrenCount(); if ( $childrenCount != 0 ) { $module->redirectToView( 'removenode', array( $objectID, $editVersion, $editLanguage, $nodeID ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } else { $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } } } else { $nodeAssignment = eZNodeAssignment::fetch( $objectID, $version->attribute( 'version' ), $nodeID ); if ( $nodeAssignment->attribute( 'from_node_id' ) != 0 ) { $publishedNode = eZContentObjectTreeNode::fetchNode( $objectID, $nodeAssignment->attribute( 'from_node_id' ) ); $childrenCount = 0; if ( $publishedNode !== null ) $childrenCount = $publishedNode->childrenCount(); if ( $childrenCount != 0 ) { $module->redirectToView( 'removenode', array( $objectID, $editVersion, $editLanguage, $nodeID ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } } } if ( $module->isCurrentAction( 'RemoveAssignments' ) ) { if( $http->hasPostVariable( 'AssignmentIDSelection' ) ) { $selected = $http->postVariable( 'AssignmentIDSelection' ); $objectID = $object->attribute( 'id' ); $versionInt = $version->attribute( 'version' ); $hasChildren = false; $assignmentsIDs = array(); $assignments = array(); // Determine if at least one node of ones we remove assignments for has children. foreach ( $selected as $parentNodeID ) { $assignment = eZNodeAssignment::fetch( $objectID, $versionInt, $parentNodeID ); if( !$assignment ) { eZDebug::writeWarning( "No assignment found for object $objectID version $versionInt, parent node $parentNodeID" ); continue; } $assignmentID = $assignment->attribute( 'id' ); $assignmentsIDs[] = $assignmentID; $assignments[] = $assignment; $node = $assignment->attribute( 'node' ); if( !$node ) continue; if( $node->childrenCount( false ) > 0 ) $hasChildren = true; unset( $assignment ); } if ( $hasChildren ) { // We need user confirmation if at least one node we want to remove assignment for contains children. // Aactual removal is done in content/removeassignment in this case. $http->setSessionVariable( 'AssignmentRemoveData', array( 'remove_list' => $assignmentsIDs, 'object_id' => $objectID, 'edit_version' => $versionInt, 'edit_language' => $editLanguage, 'from_language' => $fromLanguage ) ); $module->redirectToView( 'removeassignment' ); return eZModule::HOOK_STATUS_CANCEL_RUN; } else { // Just remove all the selected locations. $mainNodeChanged = false; $db = eZDB::instance(); $db->begin(); foreach ( $assignments as $assignment ) { $assignmentID = $assignment->attribute( 'id' ); if ( $assignment->attribute( 'is_main' ) ) $mainNodeChanged = true; eZNodeAssignment::removeByID( $assignmentID ); } if ( $mainNodeChanged ) eZNodeAssignment::setNewMainAssignment( $objectID, $versionInt ); $db->commit(); unset( $mainNodeChanged ); } unset( $assignmentsIDs, $assignments ); } else { eZDebug::writeNotice( 'No nodes to remove selected' ); } } if ( $module->isCurrentAction( 'MoveNode' ) ) { $objectID = $object->attribute( 'id' ); if ( $http->hasPostVariable( 'MoveNodeID' ) ) { $fromNodeID = $http->postVariable( 'MoveNodeID' ); //$sourceNodeID[0]; $oldAssignmentParentID = $fromNodeID; $fromNodeAssignment = eZNodeAssignment::fetch( $objectID, $version->attribute( 'version' ), $fromNodeID ); $publishParentNodeID = $fromNodeAssignment->attribute( 'parent_node' ); if ( $publishParentNodeID > 1 ) { if( $fromNodeAssignment->attribute( 'from_node_id' ) != 0 ) { $fromNodeID = $fromNodeAssignment->attribute( 'from_node_id' ); $oldAssignmentParentID = $fromNodeAssignment->attribute( 'parent_node' ); } // we don't allow moving object to itself, to its descendants or parent object(s) $objectAssignedNodes = $object->attribute( 'assigned_nodes' ); // nodes that are not allowed to select (via checkbox or radiobutton) when browsing $ignoreNodesSelectArray = array(); // nodes that are not allowed to click on $ignoreNodesClickArray = array(); foreach( $objectAssignedNodes as $curAN ) { // current node should be neither selectable, nor clickable $ignoreNodesClickArray[] = $curAN->NodeID; $ignoreNodesSelectArray[] = $curAN->NodeID; // parent node should be only clickable, but not selectable $ignoreNodesSelectArray[] = $curAN->ParentNodeID; } eZContentBrowse::browse( array( 'action_name' => 'MoveNodeAssignment', 'description_template' => 'design:content/browse_move_placement.tpl', 'keys' => array( 'class' => $class->attribute( 'id' ), 'class_id' => $class->attribute( 'identifier' ), 'classgroup' => $class->attribute( 'ingroup_id_list' ), 'section' => $object->attribute( 'section_id' ) ), 'start_node' => $fromNodeID, 'persistent_data' => array( 'FromNodeID' => $fromNodeID, 'OldAssignmentParentID' => $oldAssignmentParentID ), 'ignore_nodes_select' => $ignoreNodesSelectArray, 'ignore_nodes_click' => $ignoreNodesClickArray, 'content' => array( 'object_id' => $objectID, 'previous_node_id' => $fromNodeID, 'object_version' => $editVersion, 'object_language' => $editLanguage ), 'from_page' => "/content/edit/$objectID/$editVersion/$editLanguage" ), $module ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } } }
/** * Removes previously selected, now unselected assignments. * * This hook is run at "post_store" time. * * @param mixed $module Is eZModule. * @param mixed $class Is eZContentClass. * @param mixed $object Is eZContentObject. * @param mixed $version Is eZContentObjectVersion. * @param mixed $contentObjectAttributes Is eZContentObjectAttribute. * @param string $editVersion Number as String. * @param string $editLanguage E.g. eng-GB. * @param mixed $fromLanguage Or false. * @param mixed &$validation Array. * * @return int eZModule::HOOK_STATUS_CANCEL_RUN */ public function removeNodeAssignments($module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, &$validation) { $http = eZHTTPTool::instance(); if (!$http->hasPostVariable('ymcNodeAssignmentsPool')) { return eZModule::HOOK_STATUS_OK; } $ymcActiveNodeAssignmentsPool = $http->postVariable('ymcActiveNodeAssignmentsPool'); $ymcNodeAssignmentsPool = $http->postVariable('ymcNodeAssignmentsPool'); if (!is_array($ymcActiveNodeAssignmentsPool)) { $ymcActiveNodeAssignmentsPool = array(); } if (!is_array($ymcNodeAssignmentsPool)) { $ymcNodeAssignmentsPool = array(); } $selected = array(); foreach ($ymcNodeAssignmentsPool as $ymcAllNodeAssignment) { if ((int) $ymcAllNodeAssignment > 0 and !in_array($ymcAllNodeAssignment, $ymcActiveNodeAssignmentsPool)) { $selected[] = (int) $ymcAllNodeAssignment; } } $objectID = $object->attribute('id'); $versionInt = $version->attribute('version'); $hasChildren = false; $assignmentsIDs = array(); $assignments = array(); // Determine if at least one node of ones we remove assignments for has children. foreach ($selected as $parentNodeID) { $assignment = eZNodeAssignment::fetch($objectID, $versionInt, $parentNodeID); if (!$assignment) { eZDebug::writeWarning("[ymcEdit] No assignment found for object {$objectID} version {$versionInt},\n parent node {$parentNodeID}"); continue; } $assignmentID = $assignment->attribute('id'); $assignmentsIDs[] = $assignmentID; $assignments[] =& $assignment; $node =& $assignment->attribute('node'); if (!$node) { continue; } if ($node->childrenCount(false) > 0) { $hasChildren = true; } unset($assignment); } if ($hasChildren) { // We need user confirmation if at least one node we want to // remove assignment for contains children. Aactual removal is // done in content/removeassignment in this case. $http->setSessionVariable('AssignmentRemoveData', array('remove_list' => $assignmentsIDs, 'object_id' => $objectID, 'edit_version' => $versionInt, 'edit_language' => $editLanguage, 'from_language' => $fromLanguage)); $module->redirectToView('removeassignment'); return eZModule::HOOK_STATUS_CANCEL_RUN; } else { // Just remove all the selected locations. $mainNodeChanged = false; $db = eZDB::instance(); $db->begin(); foreach ($assignments as $assignment) { $assignmentID = $assignment->attribute('id'); if ($assignment->attribute('is_main')) { $mainNodeChanged = true; } eZNodeAssignment::removeByID($assignmentID); } if ($mainNodeChanged) { eZNodeAssignment::setNewMainAssignment($objectID, $versionInt); } $db->commit(); unset($mainNodeChanged); } unset($assignmentsIDs, $assignments); }