Tuesday 04 May 2010 4:19:21 am
Hello,
I am using my own extension that have a module which will create objects.
Basic code:
$contentClassIdentifier = 'article';
$class = eZContentClass::fetchByIdentifier( $contentClassIdentifier );
$ParentNodeID = 2;
$node = eZContentObjectTreeNode::fetch( $ParentNodeID );
$contentClassIdentifier = 'article';
$class = eZContentClass::fetchByIdentifier( $contentClassIdentifier );
$ParentNodeID = 2; $node = eZContentObjectTreeNode::fetch( $ParentNodeID ); I call class article (attributes) and then fetches node 2 (Home) because I want to place the new article in the Home subdir directory. I am using eznodeassignment to create the object and the object is created with default attributes of the class article. Evereything looks fine. The only part it does not create data is in table ezcontentobject_tree, and my guess is that is why I can't see the new article in my admin interface. I need some input on how I can add an object, with custom attribute data and in table ezcontentobject_tree so I can view and edit the object in the admin interface. {* Begin Code *} ------------------------------------------------------------------------------------ include_once( 'kernel/common/template.php' );$contentClassIdentifier = 'article'; $class = eZContentClass::fetchByIdentifier( $contentClassIdentifier ); $ParentNodeID = 2;
$node = eZContentObjectTreeNode::fetch( $ParentNodeID );
if ( is_object( $class ) ){ $contentClassID = $class->attribute( 'id' ); $parentContentObject =& $node->attribute( 'object' ); $accessResult = $parentContentObject->checkAccess( 'create', $contentClassID, $parentContentObject->attribute( 'contentclass_id' ) ); if ( $accessResult == '1' ) { include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' ); $user =& eZUser::currentUser(); $userID =& $user->attribute( 'contentobject_id' ); $sectionID = $parentContentObject->attribute( 'section_id' ); include_once( 'lib/ezdb/classes/ezdb.php' ); $db =& eZDB::instance(); $db->begin(); $contentObject =& $class->instantiate( $userID, $sectionID ); $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObject->attribute( 'id' ), 'contentobject_version' => $contentObject->attribute( 'current_version' ), 'parent_node' => $node->attribute( 'node_id' ) ) ); $nodeAssignment->store(); $db->commit(); } } ------------------------------------------------------------------------------------ {* End Code *}
|