Forums / Developer / subTreeByNodeID function with priority paramter to fetch nodes based on priority ,not working

subTreeByNodeID function with priority paramter to fetch nodes based on priority ,not working

Author Message

Romeo Antony

Wednesday 26 January 2011 5:34:30 am

Hi ,

After a lot of tries, still fails to fetch nodes into a dynamic block based on priority value of nodes.

Always getting results based on publishing time of nodes.

Here is the code I tried.

$nodeID = $parameters['Source'];

$subTreeParameters['SortBy'] = array('priority', true); // to fetch node based on priority value.

$result = eZContentObjectTreeNode::subTreeByNodeID( $subTreeParameters, $nodeID );

But still subTreeByNodeID functions fetch nodes based on publication time and not based on priority value of nodes.

I have checked the

1823 of file ezcontentobjecttreenode.php. But didn't seen the sortby value passed to subTreeByNodeID function. Always sets sortyby parameter as FALSE.

Any ideas will be a great help.

Thanks in advance

Romeo..

Franck Magnan

Wednesday 26 January 2011 12:01:18 pm

Hello Romeo,

can you tell us more about your problem? Which version of eZPublish do you have?

I'have just test this following code in a module/view and it's working

$result = eZContentObjectTreeNode::subTreeByNodeID( array('SortBy' => array('priority', true)), 2 ); 
foreach ($result as $item)
{
    echo $item->Name.'<br/>';
}

--
Developer at Open Wide

Romeo Antony

Thursday 27 January 2011 3:43:27 am

Thanks a lot for helping me Franck.

Ezpublish version is 4.3.0

I am trying to fetch nodes into ezflow dynamic block using fetch class.

Here is the code.

<?php
class eZFlowLatestObjects implements eZFlowFetchInterface
{
public function fetch( $parameters, $publishedAfter, $publishedBeforeOrAt )
{
if ( isset( $parameters['Source'] ) )
{
$nodeID = $parameters['Source'];
$node = eZContentObjectTreeNode::fetch( $nodeID, false, false ); // not as an object
if ( $node && $node['modified_subnode'] <= $publishedAfter )
{
return array();
}
}
else
{
$nodeID = 0;
}
$subTreeParameters = array();
$subTreeParameters['AsObject'] = false;
$subTreeParameters['SortBy'] = array( 'priority', true ); // fetch nodes based on priority
$subTreeParameters['AttributeFilter'] = array(
'and',
array( 'published', '>', $publishedAfter ),
array( 'published', '<=', $publishedBeforeOrAt )
);
if ( isset( $parameters['Class'] ) )
{
$subTreeParameters['ClassFilterType'] = 'include';
$subTreeParameters['ClassFilterArray'] = explode( ';', $parameters['Class'] );
}

// Do not fetch hidden nodes even when ShowHiddenNodes=true
$subTreeParameters['AttributeFilter'] = array( 'and', array( 'visibility', '=', true ) );
$result = eZContentObjectTreeNode::subTreeByNodeID( $subTreeParameters, $nodeID );
$fetchResult = array();
foreach( $result as $item )
{
$fetchResult[] = array( 'object_id' => $item['contentobject_id'],
'node_id' => $item['node_id'],
'ts_publication' => $item['published'] );
}
return $fetchResult;
}
}
?>

But still nodes are fetched based on publishing time and not based on priority.

Any ideas regarding this will be a really a help Franck.

Romeo

Romeo Antony

Thursday 27 January 2011 5:29:41 am

After digging into much more about the same issue , got some points as

by deafult ezflow fetch class fetch nodes and stored in a table based on publication time even if we specified the priority to sort the nodes. So setting priority to sort the nodes in ezflow fetch class's fetch function will not work. Anyone knows about it.Any ideas.

The following thrad says like that.

http://share.ez.no/forums/extensions/ezflow-block-valid-nodes

Romeo Antony

Thursday 27 January 2011 5:44:22 am

Finally I got it. The above thread helped to http://share.ez.no/forums/extensions/ezflow-block-valid-nodes

The below code did the job

  <span>$timeTest</span> <span>=</span> <a href="http://www.php.net/time" mce_href="http://www.php.net/time" target="ez_no_documentation"><span>time</span></a><span>(</span><span>)</span><span>-</span><span>(</span><span>3600</span><span>*</span><span>24</span><span>)</span><span>;</span>



            <span>if</span> <span>(</span> <a href="http://www.php.net/count" target="ez_no_documentation"><span>count</span></a><span>(</span> <span>$result</span> <span>)</span> <span>)</span>
            <span>{</span>
                <span>foreach</span><span>(</span> <span>$result</span> <span>as</span> <span>$item</span> <span>)</span>
                <span>{</span>
                    <span>if</span><span>(</span> <span>!</span><span>$item</span><span>[</span><span>'is_invisible'</span><span>]</span> <span>)</span>
                    <span>$fetchResult</span><span>[</span><span>]</span> <span>=</span> <a href="http://www.php.net/array" target="ez_no_documentation"><span>array</span></a><span>(</span>  <span>'object_id'</span> <span>=></span> <span>$item</span><span>[</span><span>'contentobject_id'</span><span>]</span><span>,</span>
                                             <span>'node_id'</span> <span>=></span> <span>$item</span><span>[</span><span>'node_id'</span><span>]</span><span>,</span>
                                             <span>'ts_publication'</span> <span>=></span> <span>$timeTest</span><span>--</span> <span>)</span><span>;</span> <span>//$item['published']</span>
                <span>}</span>
            <span>}</span>