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

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 18 2025 01:13:18
Script start
Timing: Jan 18 2025 01:13:18
Module start 'layout'
Timing: Jan 18 2025 01:13:18
Module start 'content'
Timing: Jan 18 2025 01:13:19
Module end 'content'
Timing: Jan 18 2025 01:13:19
Script end

Main resources:

Total runtime0.8954 sec
Peak memory usage4,096.0000 KB
Database Queries74

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 587.9375152.6250
Module start 'layout' 0.00630.0033 740.562539.4453
Module start 'content' 0.00960.8840 780.0078676.1719
Module end 'content' 0.89370.0017 1,456.179720.1563
Script end 0.8954  1,476.3359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.4265160.0002
Check MTime0.00150.1620160.0001
Mysql Total
Database connection0.00070.082810.0007
Mysqli_queries0.812490.7267740.0110
Looping result0.00110.1238720.0000
Template Total0.850595.020.4252
Template load0.00270.298220.0013
Template processing0.847894.679120.4239
Template load and register function0.00020.017710.0002
states
state_id_array0.00250.273710.0025
state_identifier_array0.00160.175920.0008
Override
Cache load0.00250.2756710.0000
Sytem overhead
Fetch class attribute can translate value0.00080.093840.0002
Fetch class attribute name0.00170.193990.0002
XML
Image XML parsing0.00300.337240.0008
class_abstraction
Instantiating content class attribute0.00000.002090.0000
General
dbfile0.00350.3875220.0002
String conversion0.00000.001240.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
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_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