eZ Community » Forums » Extensions » EZflow block Valid Nodes
expandshrink

EZflow block Valid Nodes

EZflow block Valid Nodes

Thursday 15 April 2010 12:14:50 am - 2 replies

I need to fetch the valid_nodes in a block priority basis instead of default publish date.When I loop over $block.valid_nodes , now its displaying based on publish date. I need to change it to priority.how is it possible?

Thanks,

John

Thursday 15 April 2010 10:36:15 am

You should not try to alter the priority within the template, but rather within the function that is used to put the nodes in the block queue.

This involves creating a new block fetch function. In its results array, the ts_publication variable is the one that can be used to do the propert sorting, albeit in a 'hackish' mode.

Here's the code:

class allchildren extends eZFlowFetchInterface {
 
    /*** we return all the children when some content has changed in the subtree of the param node
     *
     * It expects the params from block:
     * Source int a NodeId
     * Class string a ';' separated list of classes for the grouping (optional, if not given all classes are taken into account)
     *
     * @todo add a parameter to specify the min, max depth to the fetch?
     */
    public function fetch( $parameters, $publishedAfter, $publishedBeforeOrAt )
    {
        if ( isset( $parameters['Source'] ) )
        {
            $nodeID = $parameters['Source'];
 
            //selection of the parent node with his attribute. This way, we can sort the children same as the back office order
            $nodeSource = eZContentObjectTreeNode::fetch( $nodeID );
            $sortBy = eZContentObjectTreeNode::sortArrayBySortFieldAndSortOrder($nodeSource->attribute('sort_field'), $nodeSource->attribute('sort_order'));
 
            $subTreeParameters = array();
            $subTreeParameters['AsObject'] = false;
            $subTreeParameters['Depth'] = 1;
            $subTreeParameters['SortBy'] = $sortBy[0];
            // $subTreeParameters['IgnoreVisibility'] = false;
            $subTreeParameters['AttributeFilter'] = array(
                    'and',
                    array( 'modified', '>', $publishedAfter ),
                    array( 'modified', '<=', $publishedBeforeOrAt )
            );
            if ( isset( $parameters['Class'] ) && $parameters['Class'] != "" )
            {
                $subTreeParameters['ClassFilterType'] = 'include';
                $subTreeParameters['ClassFilterArray'] = explode( ';', $parameters['Class'] );
            }
            $result = eZContentObjectTreeNode::subTreeByNodeID( $subTreeParameters, $nodeID );
            $fetchResult = array();
            /*
             * ezFlow stores the result ($fetchResult[]) in a table. The results are sorted by the ts_publication.
             * For having the same order than the back office, it's mandatory to modify the ts_publication of each item of the $fetchResult.
             * It's done by using the $timeTest variable.
             */
            $timeTest = time()-(3600*24);
 
            if ( count( $result ) )
            {
                foreach( $result as $item )
                {
                    if( !$item['is_invisible'] )
                    $fetchResult[] = array(  'object_id' => $item['contentobject_id'],
                                             'node_id' => $item['node_id'],
                                             'ts_publication' => $timeTest-- ); //$item['published']
                }
            }
 
            return $fetchResult;
        }
        else
        {
            /// @todo log error!
            return array();
        }
    }
}

Modified on Thursday 15 April 2010 5:34:12 pm by Nicolas Pastorino

Wednesday 19 December 2012 11:57:48 am

I really don't get this: why is the result array sorted twice?

 It is straightforward to pass sort parameters to the subtreeparameters, but what is the function of the ts_publication item? It should be possible to sort block items by attribute values.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from