Tuesday 14 June 2005 2:51:04 am
The doc on filter will be reliesed in one week or so.
I will try to explain it a bit here.. Extended attribute filtering The "extended_attribute_filter" parameter can be used to do advanced attribute filtering. It is for expert/experienced users. This mechanism makes it possible to introduce additional SQL conditions within the fetch. It allows filtering based on values in custom tables and/or special filtering within the "ezcontentobject_attribute" table. The mechanism must be configured using a configuration override for "extendedattributefilter.ini". This file allows the site administrator to set up different custom filters. Each filter must be a named collection of configuration settings. The name of a filter is the name of the configuration block under which the filter's settings are defined. The following text shows an example that demonstrates the setup of a filter called "MyFilter".
#The name of the filter.
[MyFilter]
#The name of the extension where the filtering code is defined.
ExtensionName=myextension
#The name of the filter class.
ClassName=eZMyExtendedFilter
#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=classes/ezmyextendedfilter.php
The function defined by the "MethodName" setting must return an associative array containing two strings:
array( 'tables' => '...', 'joins' => '...' );
The contents of "tables" must start with a comma. The rest of the string should contain a comma separated list of other tables that should be included in the query. The contents of "joins" will be added inside the "WHERE" section of the query. This string must start with a space and contain an "AND" and an additional space at the end. The example below shows a solution that filters the content based on values within an additional/cutsom table. This table is joined with the node table (by object ID and object version). The additional/cutsom table would most likely be maintained by a special/custom datatype.
class eZMyExtendedFilter
{
/*!
Constructor
*/
function eZMyExtendedFilter()
{
// Empty...
}
function createSqlParts( $params )
{
$sqlTables= ', ezmyfiltertable ';
$sqlJoins = ' ezcontentobject_tree.contentobject_id = ezmyfiltertable.contentobject_id AND ezcontentobject_tree.contentobject_version = ezmyfiltertable.version AND ';
if ( isset( $params['value1'] ) )
{
$value1 = $params['value1'];
}
else
{
$value1 = "10";
}
if ( isset( $params['value2'] ) )
{
$value2 = $params['value2'];
}
else
{
$value2 = "10";
}
$sqlCondArray = array();
$sqlCondArray[] = 'ezmyfiltertable.my_cond1 = ' . $value1;
$sqlCondArray[] = 'ezmyfiltertable.my_cond1 = ' . $value2;
$sqlCond = implode( ' or ', $sqlCondArray );
$sqlCond = ' ( ' . $sqlCond . ' ) AND ' . $sqlJoins . ' ';
return array( 'tables' => $sqlTables, 'joins' => $sqlCond );
}
}
The following template code shows how the extended attribute filter (see the PHP code above) can be used within a fetch.
{fetch( 'content', 'list',
hash( 'parent_node_id', 2,
'sort_by', array( array( 'priority' ) ),
'limit', 15,
'extended_attribute_filter', hash( 'id', 'MyFilter',
'params', hash( 'value1', 15,
'value2' ,30 ) ),
'depth', 10,
'main_node_only', true() ) )}
additional example
{fetch( 'content', 'list',
hash( 'parent_node_id', 2,
'sort_by', array( array( 'priority' ) ),
'limit', 15,
'extended_attribute_filter', hash( 'id','MyFilter',
'params', hash( 'value1', 'text1',
'value2', 'text2' ) ) ) )}
This example demonstrates how the extended attribute filter can be used. The template code above will fetch objects that match the following condition: any object using the ezstring datatype containing either "text1" or "text2". The necessary PHP implementation is shown in the example below.
class eZMyExtendedFilter
{
/*!
Constructor
*/
function eZMyExtendedFilter()
{
// Empty...
}
function createSqlParts( $params )
{
$sqlTables= ', ezcontentobject_attribute as myfilter_alias ';
$sqlJoins = ' ezcontentobject_tree.contentobject_id = myfilter_alias.contentobject_id AND ezcontentobject_tree.contentobject_version = myfilter_alias.version AND myfilter_alias.data_type_string = "ezstring" AND';
if ( isset( $params['value1'] ) )
{
$value1 = $params['value1'];
}
else
{
$value1 = 'fooo';
}
if ( isset( $params['value2'] ) )
{
$value2 = $params['value2'];
}
else
{
$value2 = 'boooo';
}
$sqlCondArray = array();
$sqlCondArray[] = 'myfilter_alias.data_text = "' . $value1 . '"';
$sqlCondArray[] = 'myfilter_alias.data_text = "' . $value2 . '"';
$sqlCond = implode( ' or ', $sqlCondArray );
$sqlCond = ' ( ' . $sqlCond . ' ) AND ' . $sqlJoins . ' ';
return array( 'tables' => $sqlTables, 'joins' => $sqlCond );
}
}
|