static function addChildTo($contentobjectID, $nodeID, $asObject = false, $contentObjectVersion = false) { $node = eZContentObjectTreeNodeNoLanguage::fetch($nodeID); $contentObject = eZContentObject::fetch($contentobjectID); if (!$contentObject) { return false; } if (!$contentObjectVersion) { $contentObjectVersion = $contentObject->attribute('current_version'); } $db = eZDB::instance(); $parentMainNodeID = $node->attribute('node_id'); //$parent->attribute( 'main_node_id' ); $parentPath = $node->attribute('path_string'); $parentDepth = $node->attribute('depth'); $isInvinsible = $node->attribute('is_invisible'); $nodeDepth = $parentDepth + 1; $insertedNode = eZContentObjectTreeNodeNoLanguage::create($parentMainNodeID, $contentobjectID); // set default sorting from content class $contentClass = $contentObject->attribute('content_class'); $insertedNode->setAttribute('sort_field', $contentClass->attribute('sort_field')); $insertedNode->setAttribute('sort_order', $contentClass->attribute('sort_order')); $insertedNode->setAttribute('depth', $nodeDepth); $insertedNode->setAttribute('path_string', '/TEMPPATH'); $insertedNode->setAttribute('contentobject_version', $contentObjectVersion); // If the parent node is invisible, the new created node should be invisible as well. $insertedNode->setAttribute('is_invisible', $isInvinsible); $db->begin(); $insertedNode->store(); $insertedID = $insertedNode->attribute('node_id'); $newNodePath = $parentPath . $insertedID . '/'; $insertedNode->setAttribute('path_string', $newNodePath); $insertedNode->store(); $db->commit(); if ($asObject) { return $insertedNode; } else { return $insertedID; } }