Forums / Developer / Fetching and sorting in PHP, using extended attribute filter

Fetching and sorting in PHP, using extended attribute filter

Author Message

Igor Vrdoljak

Thursday 13 May 2010 8:08:55 am

Hi all,

I am looking for example of making subtree fetch from PHP (for example by using eZContentObjectTreeNode::subTreeByNodeID) while using extended attribute filter and sorting on arbitrary sql statement (that is generated by extended attribute)

I tried something like this, but it does not seem to work:

$nodes = eZContentObjectTreeNode::subTreeByNodeID(  
    array(     'MainNodeOnly' => true,
        'ClassFilterType' => 'include',
        'ClassFilterArray' => array( $class_identifier ),
        'SortBy' => array( 'my_sql_var', true ),
        'ExtendedAttributeFilter' => hash( 'id', 'myExtFilter', 'params', hash( 'var_1', $var_1 ))
        ), 
    $parent_node_id 
    );

Thnx.

http://www.netgen.hr/eng
http://twitter.com/ivrdoljak

Damien Pobel

Thursday 13 May 2010 2:10:20 pm

Hi Igor

The equivalent of the template hash operator is the array PHP function. (the hash PHP function exists but it's not what you expect here). So I guess the correct code is the following (depending on the extended attribute filter you use) :

$nodes = eZContentObjectTreeNode::subTreeByNodeID( array( 'MainNodeOnly' => true,
                                                          'ClassFilterType' => 'include',
                                                          'ClassFilterArray' => array( $class_identifier ),
                                                          'SortBy' => array( 'my_sql_var', true ),
                                                          'ExtendedAttributeFilter' => array( 'id' => 'myExtFilter',
                                                                                              'params', array( 'var_1' => $var_1 ) ) ),
                                                   $parent_node_id );

Cheers !

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Igor Vrdoljak

Saturday 15 May 2010 2:16:26 am

Hi Damien,

Thanx for the tip, it was the case of using hash arrays in PHP.

Params attribute also has to be in a hash array, so the final working snippet is:

eZContentObjectTreeNode::subTreeByNodeID( array('MainNodeOnly' => true,
  'ClassFilterType' => 'include',
  'ClassFilterArray' => array( $class_identifier ),
  'SortBy' => array( 'my_sql_var', true ),
  'ExtendedAttributeFilter' => array( 'id' => 'myExtFilter',
    'params' => array( 'var_1' => $var_1 ) ) ),
  $parent_node_id );

http://www.netgen.hr/eng
http://twitter.com/ivrdoljak