class and attribute filtering

Author Message

Jean-Luc Chassaing

Wednesday 04 February 2009 6:26:16 am

Hello,

Let me try to turn that simple way ..

I've made multiple classes witch are copies of the Folder class. That means they all have the same attribute names.

Now I want to fetch objects of different classes and make an attribute filtering.

The problem is that attribute filtering can only be done on objects of the same class. Is there a tricky way to manage that or have I to build an extended attribute filter ?

Thank you.

Jean-Luc Chassaing

Thursday 05 February 2009 2:06:17 am

I found a solution and would like to have your opinion.

My problem deals with the inheritance between classes. So I solved it by using an extended attribute filter.

Here is the code for this filter :

class eZMultiClassAttributeFilter
{
	/**
	 * Constructor
	 *
	 */
	function __construct()
	{
	
	}
	
	public function filterAttributes($params)
	{
		$sqlJoins = "";
		
		$subrequest = array();
		
		$attribId = '(';
		foreach ( $params as $key => $sort )
		{
			if ($key > 0)
			{
				$attribId .= ',';
			}
			if (! is_numeric( $sort[0] ))
			{
				$attribId .= eZContentObjectTreeNode::classAttributeIDByIdentifier( $sort[0] );
			} else
			{
				$attribId .= $sort[0];
			}
		}
		$attribId .= ')';
		
		$subrequest = "SELECT attr.contentobject_id 
					   FROM ezcontentobject_attribute as attr, ezcontentobject as obj
					   WHERE obj.id = attr.contentobject_id 
					   AND attr.version = obj.current_version 
					   AND attr.contentclassattribute_id in $attribId 
					   AND attr.data_int = 0 ";
		
		$sqlJoins .= " ezcontentobject.id in (" . $subrequest . ") AND";
		
		return array('tables' => '', 'joins' => $sqlJoins, 'colums' => '' );
	}

}

it would need some more improvements on the attribute filtering but this solution solved my problem.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 04:25:07
Script start
Timing: Jan 31 2025 04:25:07
Module start 'layout'
Timing: Jan 31 2025 04:25:07
Module start 'content'
Timing: Jan 31 2025 04:25:07
Module end 'content'
Timing: Jan 31 2025 04:25:07
Script end

Main resources:

Total runtime0.0124 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0046 588.1328151.2109
Module start 'layout' 0.00460.0021 739.343836.6484
Module start 'content' 0.00670.0044 775.992290.1719
Module end 'content' 0.01110.0013 866.164129.9922
Script end 0.0124  896.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002117.2001140.0002
Check MTime0.00118.5770140.0001
Mysql Total
Database connection0.00086.401610.0008
Mysqli_queries0.002217.628330.0007
Looping result0.00000.088310.0000
Template Total0.00108.210.0010
Template load0.00086.587810.0008
Template processing0.00021.611010.0002
Override
Cache load0.00064.800210.0006
General
dbfile0.00129.491080.0001
String conversion0.00000.048040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs