Forums / Developer / class and attribute filtering

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.