|
Clemens T
|
Wednesday 29 July 2009 6:25:20 am
Comment51097
Benjamin, and others, Maybe I'm too late, but here's my extende PHP filter. First off, important to know is that I have multiple classes that share a category string. A dropdown box in my case is used to filter through these categories, hence the 'LIKE' statement (categories can be added just by typing text and separating by comma's). Here's my code (based on previous steps discussed in this thread):
<?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_attribute ";
$attribute_ids = array();
foreach ($classes as $class) {
array_push($attribute_ids,eZContentObjectTreeNode::classAttributeIDByIdentifier( $class . '/categories' ));
}
$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 ezcontentobject_attribute.data_text LIKE '%" .
$params['textLIKEfilter'] .
"%') AND ";
return array( 'tables' => $filterSQL['from'], 'joins' => $filterSQL['where'] );
}
}
?>
And the template function looks like this:
{def $list=fetch('content','list',hash('parent_node_id',$myNodeID,
offset, $#view_parameters.offset,
sort_by, array( 'priority', false()),
limit, 5,
'extended_attribute_filter', hash('id','ExtendedCategoryFilter',
'params',
hash( 'textLIKEfilter', ezhttp('categories', 'get'),
'classes',array('class1','class2')
)
)
))}
Hopefully this helps you, and others.
|