Forums / Developer / Tree Node Assignment

Tree Node Assignment

Author Message

Julien Fieutelot

Monday 23 January 2006 2:26:51 am

Hi,

I want to insert an object in a node. But it's doesn't work, but I have no error report and no process error.

$class =& eZContentClass::fetch(21);
$customer =& $class->instantiate(15);

$nodeAssignment =& eZNodeAssignment::create( 
	array( 
    'contentobject_id' => $customer->attribute( 'id' ), 
    'contentobject_version' => 1,
    'parent_node' => $parent_node_id, 
    'is_main' => 1
  ) 
); 
$nodeAssignment->store(); 

$version =& $customer->version( 1 ); 
$version->setAttribute( 'modified', eZDateTime::currentTimeStamp() ); 
$version->setAttribute( 'status', EZ_VERSION_STATUS_PUBLISHED ); 
$version->store(); 

$db = & eZDB::instance();

$customers = $db->arrayQuery("SELECT * FROM customer WHERE code='$custNumber'");

if( $customers ) {
	$contentObjectAttributes =& $version->contentObjectAttributes();
	$contentObjectAttributes[0]->setAttribute('data_text', $customers[0]['name']);
	$contentObjectAttributes[0]->store();
	
	$contentObjectAttributes[1]->setAttribute('data_text', $customers[0]['code']);
	$contentObjectAttributes[1]->store();
	
	$customer->store();
}

This is the whole proccess with $customer object. This part doesn't work but I don't know why ?...The $customer object is not null and contains the required value. The query result is right too. Is there an error in eZNodeAssignment::create ? Do I forget parameters ? Or is the second parameter section for $class->instantiate required ?

Thanks for your help
Julien

Łukasz Serwatka

Monday 23 January 2006 3:24:49 am

It looks like your code is missing with at the end:

include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
...
...
//publish new object
 $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $customer->attribute( 'id' ),
'version' => 1 ) );

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Julien Fieutelot

Monday 23 January 2006 4:48:51 am

It works fine now.

Thanks
Julien

Sébastien Antoniotti

Sunday 11 February 2007 12:42:55 pm

Hi,

I'm using your code, all is right, but I need to know the node_id of the node added precedently. Is there any way to do this ?

eZ Publish Freelance
web : http://www.webaxis.fr

Bruce Morrison

Sunday 11 February 2007 3:29:22 pm

Hi Sébastien

Adding

$nodeID = $customer->attribute('main_node_id');

after the end will do the trick.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Sébastien Antoniotti

Sunday 11 February 2007 9:58:57 pm

Hi Bruce,

Many thanks !

Good webdev ;-)

eZ Publish Freelance
web : http://www.webaxis.fr