Fetching nodes by attribute content

Author Message

Sao Tavi

Tuesday 05 July 2011 9:24:39 am

This should be simple, but I cannot find the function.

So, I need to fetch all the nodes of a specific class, that descend from a specific node and that have some attribute content equal to some value. It should be something like a search with these criteria.

Steven E. Bailey

Tuesday 05 July 2011 3:07:34 pm

API or template?

If it's template you have to do something like this:

 {def $items=fetch( content, tree, hash( parent_node_id, $topNodeID, attribute_filter, array( 'and', array( $identifier,'like',$char.'*'),array( 'profile/staff ,'!=', 2 ), array( 'profile/staff ,'!=', 0 )) ))}

*Not tested - variables changed to match the php code - no idea if this will work in this form - but it should give you the idea.

If it's the API you have to do something like this:

$attributefilter[]= 'and';
 $attributefilter[]= array( $identifier,'like',mysql_escape_string($char).'*');
 $attributefilter[]= array( 'profile/staff ,'!=', 2 );
 $attributefilter[]= array( 'profile/stafff' ,'!=', 0 );

$params['AttributeFilter']              = ($attributefilter);

$output = eZContentObjectTreeNode::subTreeByNodeID( $params, $topNodeID );

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Marko Žmak

Thursday 07 July 2011 6:17:54 am

Sao, for the complete documentation of the templat fetch function look here:

As for the "documentation" for the API you should inspect the code of subTreeByNodeID() function:

Also, note that attribute filtering can have an impact on site performance (it produces complex and consuming sql queries), and should be used with caution.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

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