Forums / Developer / How to fetch objects in PHP on specified attributes ?

How to fetch objects in PHP on specified attributes ?

Author Message

Patrick ALLAERT

Thursday 30 June 2005 12:25:16 pm

I have a class named <i>CommandLine</i> that have the following custom attributes:

* price
* product_id
* quantity
* ...

I have to fetch all <b>CommandLine</b> that have, for example, product_id <b>100</b>.

At this time, the following code gives me all CommandLine objects :

$contentObject = eZContentObject::fetchList( true,
    array( 'contentclass_id' => 43 ) );

Do I need to proceed this way, fetching all attributes and then filtering (in PHP) on results or is it possible to use the $conditions parameter or any other techniques (SQL,...) ?

Any help would be greatly appreciated :)

Thanks in advance!

Patrick ALLAERT
http://www.dixite.com/
http://users.pandora.be/patrick_allaert/

perrin aybara

Friday 01 July 2005 1:56:33 am

you can filter on attributes using the eZContentObjectTreeNode::subTree() function

ex:

$params = array(
 'ClassFilterType' => 'include',
 'ClassFilterArray' => 'CommandLine',
 'AttributeFilter' => array( array(
 'CommandLine/product_id', 'eq', 100 ) )
); // assuming that CommandLine is the identifier of your class

$nodeList =& eZContentObjectTreeNode::subTree($params, $parentNodeId); // where $parentNodeId is the root node or whatever...

Patrick ALLAERT

Friday 01 July 2005 3:29:55 am

Thank you very much perrin !

This is exactly what I needed! Just a few corrections to fit my business:

'ClassFilterArray' => 'CommandLine' --> 'ClassFilterArray' => array( 'commandline' )
'eq' --> '='

Here the final result for reuse:

$params = array(
'ClassFilterType' => 'include',
'ClassFilterArray' => array( 'commandline' ),
'AttributeFilter' => array( array(
'commandeline/product_id', '=', 100 ) )
); // assuming that CommandLine is the identifier of your class
        
$nodeList =& eZContentObjectTreeNode::subTree( $params , $parentNodeId ); // where $parentNodeId is the root node or whatever...

Patrick ALLAERT
http://www.dixite.com/
http://users.pandora.be/patrick_allaert/

Christoph von Siebenthal

Sunday 13 September 2009 11:55:34 am

This was very usefull.

But for 4.1.3 you have to use:

eZContentObjectTreeNode::subTreeByNodeId( $searchParams, $nodeID)