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>

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

eZ debug

Timing: Jan 30 2025 19:47:34
Script start
Timing: Jan 30 2025 19:47:34
Module start 'layout'
Timing: Jan 30 2025 19:47:34
Module start 'content'
Timing: Jan 30 2025 19:47:34
Module end 'content'
Timing: Jan 30 2025 19:47:34
Script end

Main resources:

Total runtime0.0259 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 588.6406151.2734
Module start 'layout' 0.00570.0042 739.9141220.8672
Module start 'content' 0.00990.0141 960.78131,006.5703
Module end 'content' 0.02400.0018 1,967.351641.9766
Script end 0.0259  2,009.3281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002911.0827140.0002
Check MTime0.00124.7947140.0001
Mysql Total
Database connection0.00072.536410.0007
Mysqli_queries0.003312.580630.0011
Looping result0.00000.054310.0000
Template Total0.00124.510.0012
Template load0.00093.633810.0009
Template processing0.00020.822110.0002
Override
Cache load0.00062.270310.0006
General
dbfile0.00031.095680.0000
String conversion0.00000.038740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs