Forums / Developer / Fetch and filter on object relations

Fetch and filter on object relations

Author Message

Koutouan Emmanuel

Wednesday 29 October 2008 5:00:02 am

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/technical_manual/4_0/reference/modules/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

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

eZ debug

Timing: Jan 17 2025 22:40:38
Script start
Timing: Jan 17 2025 22:40:38
Module start 'content'
Timing: Jan 17 2025 22:40:39
Module end 'content'
Timing: Jan 17 2025 22:40:39
Script end

Main resources:

Total runtime0.8123 sec
Peak memory usage4,096.0000 KB
Database Queries75

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 588.8516180.8281
Module start 'content' 0.00700.8005 769.6797679.3438
Module end 'content' 0.80760.0047 1,449.023450.1016
Script end 0.8122  1,499.1250 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4062140.0002
Check MTime0.00140.1701140.0001
Mysql Total
Database connection0.00100.122210.0010
Mysqli_queries0.744191.5990750.0099
Looping result0.00100.1195730.0000
Template Total0.778695.920.3893
Template load0.00270.329020.0013
Template processing0.775995.519620.3880
Template load and register function0.00020.027910.0002
states
state_id_array0.00120.152210.0012
state_identifier_array0.00090.116820.0005
Override
Cache load0.00240.2964710.0000
Sytem overhead
Fetch class attribute can translate value0.00080.097440.0002
Fetch class attribute name0.00230.280590.0003
XML
Image XML parsing0.00360.440740.0009
class_abstraction
Instantiating content class attribute0.00000.002090.0000
General
dbfile0.00470.5804240.0002
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
19content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 44
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs