eZ Community » Forums » Developer » Fetch and filter on object relations
expandshrink

Fetch and filter on object relations

Fetch and filter on object relations

Wednesday 29 October 2008 1:00:02 pm - 6 replies

Hi ,
I have a class with a attribute of type "Object relations" (I can link multiples objects)) and I want to fetch all items of my class on a unique object.
My class is news with an attribute Theme (list of themes).
I want to get all the news of the theme "Cinema".

My fecth :
set $children=fetch_alias( 'children', hash( 'parent_node_id', $node.node_id,
'offset', $view_parameters.offset,
'sort_by', $node.sort_array,
'class_filter_type', 'exclude',
'class_filter_array', $classes,
'limit', $page_limit,
'attribute_filter', array( array( 'news/theme','=',231))
) )

the id of the node object used is 231 for a test.

But I have no results.
I read the doc (http://ez.no/doc/ez_publish/techn...odules/content/fetch_functions/list)
and the example :
{fetch( 'content',
'list',
hash( 'parent_node_id', 42,
'attribute_filter', array( array( 'article/image',
'=',
87 ) ) ) )}

But it doesn't work in my case.

Anybody with the same problems ?
Any ideas ?

I

Wednesday 29 October 2008 1:53:53 pm

hello,
you can get all the objects related to an attribute of an object by using this:


{foreach $node.data_map.name_of_attribute(theme).content.relation_list as $name}

{$name}
{/foreach}

where

$node

is your current node.

Modified on Wednesday 29 October 2008 1:59:38 pm by justin kazadi

Tuesday 04 November 2008 4:31:34 pm

Thanks for you answer.

But we want the exact opposite.

Thursday 20 November 2008 9:55:20 pm

Hi Emmanuel,

It's not possible to use an attribute_filter on an objet relationS ... but it's possible on an objet relation (single select).

You can read this :
http://ez.no/developer/forum/deve..._filter_on_object_relations_datatype

Perhaps you can use related_objects fetch ... i don't know your project.
Greg

Friday 21 November 2008 9:54:49 pm

Hi Emmanuel,

After few tests, it's possible to fetch items with object relationS parameters. You must to create an extended attribute filter ! it's not possible with a classic fetch !

I have found this : http://ez.no/developer/contribs/d...ypes/enhanced_object_relation_filter
It's nice ; i have made a test and all is ok for me.

With this extension (it's an extended attribute filter), you can make your fetch.

Greg

Modified on Friday 21 November 2008 11:01:05 pm by Grégory BECUE

Friday 21 November 2008 10:58:02 pm

Just an add-on ...

If you want to search about items with object relation X or Y ... it's not possible with the previous extension (http://ez.no/developer/contribs/d...ypes/enhanced_object_relation_filter ; very good work) but you can search about items with object relation X and Y ...

I have modified the main class :
line 40, file 'eorfilter.php'

        // multiple objects ids
        if ( is_array($param[1]) )
        {
	    // Treatment for 'and' parameters
            if($param[2] == 'and')
            {            	
		foreach( $param[1] as $objectId )
		{
			if ( is_numeric( $objectId ) )
			{
			    $tableName = 'eor_link_' . $objectId;
			    $tables[] = 'ezcontentobject_link ' . $tableName;
			
			    $joins[]  = $tableName . '.from_contentobject_id = ezcontentobject.id';
			    $joins[]  = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
			    $joins[]  = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
			    $joins[]  = $tableName . '.to_contentobject_id = ' . $objectId;
			}
		}
	     }
	     elseif($param[2] == 'or') 
	     {
	     	// Treatment for 'or' parameters
	    	$cpt = 0;
		$chaineCritere = "(";
		foreach( $param[1] as $objectId )
		{
			if ( is_numeric( $objectId ) )
			{
				if($cpt == 0)
				{	
					$tableName = 'eor_link_' . $objectId;
					$tables[] = 'ezcontentobject_link ' . $tableName;
					
					$joins[]  = $tableName . '.from_contentobject_id = ezcontentobject.id';
					$joins[]  = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
					$joins[]  = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
					
					$chaineCritere .= $tableName . '.to_contentobject_id = ' . $objectId;
				}
			    	else
			    	{
			    		$chaineCritere .= ' or '.$tableName . '.to_contentobject_id = ' . $objectId;	
			    	}	
			}
			
			$cpt++;
		}	     	
	     	
	     	$joins[]  = $chaineCritere.")";
	     }
	     
        }


Now, it's possible to make an OR or AND search.

 
	{def $listeOffre = fetch(content, list, hash(
	'parent_node_id', 81,
        'extended_attribute_filter', hash(
                              		'id', 'eorfilter',
                              		'params', array(
                              			array('offre_emploi/pays', array(99,100,928), 'or'),
                              			array('offre_emploi/niveau', array(97,98), 'or')
                              			)
                          )))}

Greg

Modified on Friday 21 November 2008 11:05:23 pm by Grégory BECUE

Wednesday 13 July 2011 5:15:16 pm

Hi,

I added a new extension based on the previous extension (enhanced_object_relation_filter) and the previous Grégory Becue's post (good work) :

http://projects.ez.no/oworfilter

This extension provides an extended attribute filter to use with fetch functions, supporting basic logical operators and multiple class attributes.

Modified on Wednesday 13 July 2011 5:18:20 pm by Simon Boyer

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from