Extension : How to retrieve a node_id sort_array ?

Author Message

H-Works Agency

Tuesday 30 May 2006 4:26:47 am

Hi all

I am using 'fetchObjectTree' function to export contents to a CSV file in my modified "CSV Extract" extension.

I want to make shure that the sorting of the export is the same as the sorting of the parent folder.

I use 'fetchObjectTree' like this :

$list =& eZContentFunctionCollection::fetchObjectTree($Subtree, $sortBy, false, false, $Offset, $Limit,
$Class_id, false, false, 'include', array($Class_id),
false, false, true, true, true);

My problem is to retrieve the 'sort_array' of a certain node to force the function to order the results the same as the parent node with the $sortBy variable. '$Subtree' is the node_id integer.

This is the code i use to retrieve the sort_array for this node_id :

$myNode =& eZContentObjectTreeNode::fetch($Subtree, false, false);
$sortBy = eZContentObjectTreeNode::sortArrayBySortFieldAndSortOrder($myNode['sort_field'], $myNode['sort_order']);
$sortBy = $sortBy[0];

$sortBy give me the sort_array of the $Subtree node_id

It works but is there a shorter/cleaner way to do the same thing ? Why all those classes/php functions aren't documented ?

Thanx for every help :p

Martin

EZP is Great

Łukasz Serwatka

Thursday 01 June 2006 12:13:49 am

Hi,

You can get sort_array and node_id like:

include_once( 'kernel/classes/ezcontentobjecttreenode.php' );

// {def $node=fetch( 'content', 'node', hash( 'node_id', 2 ) )}
$node =& eZContentObjectTreeNode::fetch( 2 );

// {$node.node_id}
$node->attribute('node_id');

// {$node.sort_array}
$nodeSortArray =& $node->sortArray();
// {$node.parent.sort_array}
$parent =& $node->fetchParent();
$parentSortArray =& $parent->sortArray();

Hope it will help you.

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

H-Works Agency

Thursday 01 June 2006 1:40:20 pm

Thanx Lukas, i am gonna try that.

But if i understand, if i want to only get a node sort_array i should use :

$node =& eZContentObjectTreeNode::fetch( 2 );
$nodeSortArray =& $node->sortArray();

Or do i have to include the following line inbetween :

$node->attribute('node_id');

Well i am gonna try anyway. Thanx a lot for your help.

Martin

EZP is Great

Łukasz Serwatka

Thursday 01 June 2006 1:47:21 pm

No, you don't need to put $node->attribute('node_id'); between. It was just an example how to get node id ;)

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

H-Works Agency

Friday 02 June 2006 11:05:18 am

Ok thanx a lot...it works !

I finally use this code :

$node =& eZContentObjectTreeNode::fetch($node_id);
$sortBy =& $node->sortArray();
$sortBy = $sortBy[0];

I had to add '$sortBy = $sortBy[0];' otherwise it output 'array(array('published',false))' and not just 'array('published',false)' as needed.

Martin

EZP is Great

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.