Share » Forums » Developer » Fetch and filter on object relations

Fetch and filter on object relations

Fetch and filter on object relations

Wednesday 29 October 2008 5:00:02 am - 6 replies

Author Message

justin kazadi

Wednesday 29 October 2008 5:53:53 am

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.

The theory is when we know everything and nothing works.
The practice is when everything works and nobody knows why.
If the practice and theory are met, nothing works and we do not know why.

Albert Einstein

Koutouan Emmanuel

Tuesday 04 November 2008 7:31:34 am

Thanks for you answer.

But we want the exact opposite.

Grégory BECUE

Thursday 20 November 2008 12: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/developer/attribute_filter_on_object_relations_datatype

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

Grégory BECUE

Friday 21 November 2008 12: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/datatypes/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

Grégory BECUE

Friday 21 November 2008 1: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/datatypes/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

Simon Boyer

Wednesday 13 July 2011 8:15:16 am

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.

--
Developer at Open Wide

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

36 542 Users on board!

Forums menu