Author Topic

quang lam

Friday 21 January 2011 3:22:00 am

Comment65228

Hi

I was only interested by sorting on different attributes in differents classes within a fetch

Base on previous posts, I was able to correct the code ( EZ v 4.x) in this purpose :

<?php

class eZExtendedCategoryFilter
{
    /*!      Constructor     */
    function eZExtendedCategoryFilter()
    {
    }

    function createSqlParts( $params )
    {
        $result = array( 'tables' => '', 'joins'  => '' );

        if ( isset( $params['classes'] ) )
        {
             $classes = $params['classes'];
        } else
        return;
        
        if ( isset( $params['sort_fields'] ) )
        {
             $sort_fields = $params['sort_fields'];
        } else
        return;

        $filterSQL = array();
        $filterSQL['from']  = ", ezcontentobject_attribute  ";

    $attribute_ids = array();
    $i=0;
    foreach ($classes as $class) {
            array_push($attribute_ids,eZContentObjectTreeNode::classAttributeIDByIdentifier( $class . '/'.$sort_fields[$i] ));
            $i++;
    }
    $class_cond = array();
    foreach ($attribute_ids as $aid) {
        if ($aid) {
        array_push($class_cond, 'ezcontentobject_attribute.contentclassattribute_id = '.$aid);
        }
    }

        $string_class_cond = implode(" OR ",$class_cond);

        $filterSQL['where'] = " ( ezcontentobject_attribute.contentobject_id = ezcontentobject.id AND (" . $string_class_cond . ") AND                ezcontentobject_attribute.version = ezcontentobject.current_version ". ") AND ";

    return array( 'tables' => $filterSQL['from'], 'joins'  => $filterSQL['where'] );

    }
}

?>

Template call

{def $news=fetch( 'content', 'tree', hash( parent_node_id, $parent_node_id ,
'limit',$nbnews,
'sort_by', array(array('ezcontentobject_attribute.data_int', 0)),
'extended_attribute_filter', hash('id','ExtendedCategoryFilter','params',hash('classes',array('press','article_mainpage'),'sort_fields',array('date','publish_date')))
))
  • sort_by : put the data type of the attributes. i.e my attributes were date. they are store as data_int en EZ
  • params :
    classes : put the class names ,
    sort_fields: put the user defined identifiers on which the sort should run, in the same order as class names.
    i.e . I have two classes ( press - field identifier : date / article_mainpage - field identifier : publish_date )

Thanks everyone for helping me to write this "missing" feature