Forums / Developer / coding fetch in PHP

coding fetch in PHP

Author Message

anne martinet

Thursday 21 August 2008 9:56:59 am

Hi,

I don't understand how coding this function, in my file .php

{def $video_mm=fetch('content','list',hash(     'parent_node_id', 365,
                                                'class_filter_type',include,
                                                'class_filter_array',array('video_flash_mm')))}

André R.

Thursday 21 August 2008 11:35:24 am

In php you should really use the api, most of the objects that you use in templates (nodes, objects, classes, object attributes..) have a php class in kernel/classes/.
And most of those classes have fetch functions.

Your template example would look like this in php:

$nodes = eZContentObjectTreeNode::subTreeByNodeID(array(
    'ClassFilterType' => 'include',
    'ClassFilterArray' => array( 'video_flash_mm' ),
    'Depth' => 1,
    'DepthOperator' => 'eq'
    ), 365);

Or if you want to sort by the parent node:

$node  = eZContentObjectTreeNode::fetch( 365 );
$nodes = $node->subTree(array(
    'ClassFilterType' => 'include',
    'ClassFilterArray' => array( 'video_flash_mm' ),
    'Depth' => 1,
    'DepthOperator' => 'eq',
    'SortBy' => $node->sortArray() 
    ));

Note: If you plan to use most of the attributes, then set the LoadDataMap parameter to true.
Note2: For counts there usually similar functions that takes the same parameters, in the above case it would be ::subTreeCountByNodeID() and ->subTreeCount()

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

anne martinet

Friday 22 August 2008 2:20:02 am

Thanks,

I have again difficulties to read API, and to find interesting functions.

I code your answer :

$v=eZContentObjectTreeNode::subTreeByNodeID(
        array(  'ClassFilterType' => 'include',
                'ClassFilterArray' => array('video_flash_mm'),
                'Depth' => 1,
                'DepthOperator' => 'eq'),
        365
);

foreach ( $v as $o )
{
        echo $o->attribute('name')." --- et son etat ".$dm['etat_ezstring']."<br/>";
}

But I don't see the string for $dm['etat_ezstring'], I see this : Object id #47
How can I see this content???

thanks

Pascal Specht

Friday 22 August 2008 3:57:41 am

Hello,

is $dm['etat_ezstring'] a datamap ?
Probably, you should use $dm['etat_ezstring']->content() instead.

</Pascal>

anne martinet

Friday 22 August 2008 4:13:04 am

effectively, ($dm=$o->dataMap();) $dm is datamap.

and yes, $dm['etat_ezstring']->content() write content of attribute

:)
thanks
:)

anne martinet

Friday 22 August 2008 5:41:18 am

But if I want change content of an attribute to an instance (of classe 'video_flash_mm') how can I do?

thanks