Author Topic

Ivo Lukac

Tuesday 05 May 2009 2:38:35 am

Comment51086

Found something for ez3 (php4). If you working with ez4 (php5) you will need to modify the constructor call.
This filter is used for objectrelation attribute, but you can make it to work with selection attribute.

Make a new extension with file kernel\classes\ezcategoryfilter.php

<?php

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

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

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

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

	$attribute_ids = array();
	foreach ($classes as $class) {
			array_push($attribute_ids,eZContentObjectTreeNode::classAttributeIDByIdentifier( $class . '/category' ));
	}
	$class_cond = array();
	foreach ($attribute_ids as $aid) {
		if ($aid) {
		array_push($class_cond, 'i1.contentclassattribute_id = '.$aid);
		}
	}

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

        $filterSQL['where'] = " ( i1.from_contentobject_id = ezcontentobject.id AND (" . $string_class_cond . ") AND 			   i1.from_contentobject_version = ezcontentobject.current_version AND i1.to_contentobject_id = " . $params['object_id'] . ") AND ";

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

    }
}

?>

Also add this to extendedattributefilter.ini:

[ExtendedCategoryFilter]
#The name of the extension where the filtering code is defined.
ExtensionName=your_extension

#The name of the filter class.
ClassName=eZExtendedCategoryFilter

#The name of the method which is called to generate the SQL parts.
MethodName=createSqlParts

#The file which should be included (extension/myextension will automatically be prepended).
FileName=kernel/classes/ezcategoryfilter.php

And activate the extension.
You then use this in your templates like this:

fetch( 'content', 'tree', hash( parent_node_id, $parent_node_id ,
'extended_attribute_filter', hash('id','ExtendedCategoryFilter','params',hash('object_id', $value,'classes',array('class1','class2'))),	))}

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac