Friday 18 November 2005 1:29:22 pm
Hi, I'm having some trouble adding a new content object/node programmatically. For simplicity, let's just say that I have a user group (although I think this discussion will be the same for any class)...
$userGroup =& eZContentObject::fetch($myContentObjectId);
...and that I want to add a new user group as a child of that object. Here's my code to add a new group.
$contentClass =& eZContentClass::fetchByIdentifier($userGroup->className());
$newGroup =& eZContentObject::create('A new child group', $contentClass->attribute('id'));
This seems to work fine and I can retrieve the group by calling eZContentObject::fetchList() with the group's name ('A new child group') as a parameter. At this point, the group does not appear in the tree of user groups when I click on 'User accounts' in the admin site. So I have tried a few things to add the group as a child of the desired node. Something like this seems to deal with data in the eznodeassignment table...
$parameters = array(
'contentobject_id' => $newGroup->attribute('id'),
'contentobject_version' => $newGroup->attribute('current_version'),
'parent_node' => $userGroup->attribute('main_node_id'),
'is_main' => 1);
$nodeAssignment =& eZNodeAssignment::create($parameters);
And this seems to deal with the ezcontentobject_tree table...
$treeNode =& eZContentObjectTreeNode::create(
$contentobject->attribute('main_node_id'),
$newObject->attribute('id'));
By examining the DB (and changing values as an experiment), it seems that the path_string field of the ezcontentobject_tree table is very important in deciding how the tree is displayed in the admin site. Can someone describe how the ezcontentobject, ezcontentobject_tree, and eznodeassignment tables are related and what code should be used to manipulate them appropriately? Thanks in advance, Brian.
|