Last active
June 8, 2016 16:01
-
-
Save Opencontent/21982c5848cc66b8ae8d6e0e52e3501f to your computer and use it in GitHub Desktop.
eZ Publish Legacy Add Location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function addLocation( | |
eZContentObject $object, | |
$parentNodeId, | |
$addAsMain = false | |
) { | |
$node = $object->mainNode(); | |
$parentNode = eZContentObjectTreeNode::fetch($parentNodeId); | |
if ($node instanceof eZContentObjectTreeNode && $parentNode instanceof eZContentObjectTreeNode) { | |
$nodeID = $node->attribute('node_id'); | |
$objectID = $node->attribute('contentobject_id'); | |
$selectedNodeIDArray = array($parentNode->attribute('node_id')); | |
/** @var eZContentObject $parentNodeObject */ | |
$parentNodeObject = $parentNode->attribute('object'); | |
/** @var eZContentObject $object */ | |
$object = $node->attribute('object'); | |
/** @var eZContentClass $class */ | |
$class = $object->contentClass(); | |
$canCreate = ( | |
( $parentNode->checkAccess('create', $class->attribute('id'), | |
$parentNodeObject->attribute('contentclass_id')) == 1 ) | |
|| ( $parentNode->canAddLocation() && $node->canRead() ) | |
); | |
if ($canCreate) { | |
eZContentOperationCollection::addAssignment($nodeID, $objectID, $selectedNodeIDArray); | |
if ($addAsMain) { | |
$mainAssignmentParentID = $parentNode->attribute('node_id'); | |
foreach ($node->object()->assignedNodes() as $assignedNode) { | |
if ($assignedNode->attribute('parent_node_id') == $mainAssignmentParentID) { | |
eZContentOperationCollection::updateMainAssignment( | |
$assignedNode->attribute('node_id'), | |
$objectID, | |
$mainAssignmentParentID | |
); | |
} | |
} | |
} | |
return true; | |
} else { | |
eZDebug::writeError("Current user can not add a location in $parentNodeId to object $objectID", __METHOD__); | |
} | |
} else { | |
eZDebug::writeError("Object corrupted or parent node $parentNodeId not found", __METHOD__); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Per rendere principale la nuova collocazione impostare $addAsMain a true