Forums / Developer / Attribute Filter in Fetch Function

Attribute Filter in Fetch Function

Author Message

Bayron Guevara

Friday 07 December 2007 7:49:33 am

Hello!
I have a problem when I want to fetch nodes , filtering by a related object attribute, I don´t know what to write in the comparison. The code is following:

    {def $secc_rel = $node.data_map.seccion_relacionada}

     {***Extrae una lista de las noticias de esta seccion para el dia especificado***}
     {def $noticias = fetch('content', 'list', hash('parent_node_id', $nodo_edicion.node_id,
								 'attribute_filter', array( array('noticia_principal/seccion_relacionada', '=', $secc_rel) ) ) )}

Web Developer & Modern Philosopher
Visit http://www.laprensa.hn, http://www.diez.hn, http://www.estilo.hn

Paul Leclercq

Friday 07 December 2007 10:30:49 am

Hello Bayron,

It isn't possible to use attribute_filters for fetch 'lists' of ObjectRelationLists:
http://ez.no/developer/forum/setup_design/objectrelationlist_and_attribute_filter

So if you have more than one object related to your object then you will need to find another solution:

That way you can maybe try using an operator and use this function:
http://pubsvn.ez.no/doxygen/trunk/html/classeZContentObjectTreeNode.html

 $node_array =& eZContentObjectTreeNode::subTree(
        array( 'Depth' => 1,
               'Limit'            => 50,
               'Offset'           => 0,
               'SortBy'           => array( 'published', 1 ),
               'DepthOperator'    => 'eq',
               'ClassFilterType'  => 'include',
               'ClassFilterArray' =>  array('comment')
               ), $nodeID );

Function which works in a similar way as fetch('content', 'list' ....
You can then try and filter your results related attributes or order them using classic php functions.

Nicolas Lescure

Friday 07 December 2007 12:08:08 pm

I use this on eZ 3.9.2 :
http://ez.no/developer/contribs/datatypes/enhanced_objectrelation (<b>download the svn version :</b>
http://pubsvn.ez.no/community/trunk/extension/enhancedobjectrelation)

Then you'll need an extended attribute filter to use it.

Which version of eZ do you use ?
If your eZ is not a 3.9.10 you'll have to make a little hack for the kernel to add a "distinct" in the query generated.

Bayron Guevara

Monday 10 December 2007 7:26:42 am

Hello, Paul Leclercq.
Thank you for your collaboration, but I want to filter a <i>unique</i> related object, which is permitted.
See bellow:

Filtering on the attribute level is supported for the following datatypes:
• Checkbox
• Date
• Date and time
• E-mail
• Integer
• <b>Object relation</b>
• Selection (will not work when used as multiple selector)
• Text line
• Time

Again, How can I do a single related object filter?

Something more, I was reading the class code than you suggest me, I think than its parameters are similiar to fetch function, except than it uses php code, I am in the right thing?

Web Developer & Modern Philosopher
Visit http://www.laprensa.hn, http://www.diez.hn, http://www.estilo.hn

Paul Leclercq

Tuesday 11 December 2007 1:13:10 am

You need to make sure you have the correct datatype, an object relation List returns an array of objects while an Object Relation Returns a single Object, not only make sure you have one object. You can make sure you have the correct datatype while editing your class in the administration interface->administration->class.

You should then be able to use the attribute_filters in the same way as for other types of attributes, other examples are shown on this page:
http://ez.no/doc/ez_publish/technical_manual/3_9/reference/modules/content/fetch_functions/list

'attribute_filter', array( 'or',
                                        array( 152, '=', 'abc' ),
                                        array( 153, '=', '42' ) 

The php code I gave out, is indeed, to create a custom fetch function by using an operator with php code. Although I read yesterday that it was no longer possible to use the static version of subtree() in ez4:
http://serwatka.net/index.php/en/blog/ez_publish_4_0_post_release_notes

Bayron Guevara

Tuesday 11 December 2007 2:49:51 pm

Paul, the datatype than I'm utilizing is <i>Object Relation</i>, no a Object Relation list. The examples than you give me a link, don't include this datatype. Thank you for your help, but I still don't found a simple solution.

Web Developer & Modern Philosopher
Visit http://www.laprensa.hn, http://www.diez.hn, http://www.estilo.hn

eZ debug

Timing: Jan 30 2025 22:22:44
Script start
Timing: Jan 30 2025 22:22:44
Module start 'content'
Timing: Jan 30 2025 22:22:44
Module end 'content'
Timing: Jan 30 2025 22:22:44
Script end

Main resources:

Total runtime0.1936 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 587.9531370.2891
Module start 'content' 0.00630.0165 958.24221,009.6563
Module end 'content' 0.02280.1706 1,967.89843,898.2109
Script end 0.1935  5,866.1094 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00472.4402200.0002
Check MTime0.00150.7643200.0001
Mysql Total
Database connection0.00070.357010.0007
Mysqli_queries0.097950.55541410.0007
Looping result0.00110.58571390.0000
Template Total0.170187.910.1701
Template load0.00100.523410.0010
Template processing0.169087.338310.1690
Override
Cache load0.00070.375610.0007
Sytem overhead
Fetch class attribute can translate value0.00201.013210.0020
XML
Image XML parsing0.00030.143110.0003
General
dbfile0.00854.3692200.0004
String conversion0.00000.002130.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs