Fetch & filter by class and attribute

Author Message

Andreas Kaiser

Thursday 31 August 2006 2:20:07 am

I've been looking around the forum and think this can't be done...

I'm trying to select inisde the admin area which folders are fetched by the suckerfish reloaded extension. I've created a checkbox in the folder class to select if the folder has to be displayed in the navigation menu.

The code of the extension is:

{def $base=fetch( 'content', 'node', hash( 'node_id', 2 ) )}
{* FIRST LEVEL *}
{section loop=fetch(content,list,hash(parent_node_id,$top_cat, class_filter_type, "include", class_filter_array, array(1), sort_by,$base.sort_array))}
{let child_check=fetch(content,list,hash(parent_node_id,$:item.node_id, class_filter_type, "include", class_filter_array, array(1),sort_by,$base.sort_array))}<li><a {section show=$child_check|count|gt(0)}{/section} href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a>

I've tested to add an attribute_filter, but it didn't work.

{def $base=fetch( 'content', 'node', hash( 'node_id', 2 ) )}
{* FIRST LEVEL *}
{section loop=fetch(content,list,hash(parent_node_id,$top_cat, class_filter_type, "include", class_filter_array, array(1), attribute_filter, array(198,'=',1), sort_by,$base.sort_array))}
{let child_check=fetch(content,list,hash(parent_node_id,$:item.node_id, class_filter_type, "include", class_filter_array, array(1),sort_by,$base.sort_array))}
<li>
<a {section show=$child_check|count|gt(0)}{/section} href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a>

I'm just begining with eZPublish and not programmer...

eZ Partner in Madrid (Spain)
Web: http://www.atela.net/

Claudia Kosny

Thursday 31 August 2006 9:40:50 am

Hello Andreas

The attribute filter has a slightly different structure. Here an example from the documentation:

{fetch( 'content', 'list',
        hash( 'parent_node_id',   42,
              'attribute_filter', array( 'or',
                                        array( 152, '=', 'abc' ),
                                        array( 153, '=', '42' ) ) ) )}

You can find the documentation here:
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/content/fetch_functions/list

If you want to filter on one attribute only you can leave the first array item (the 'or' in the example, which could also be an 'and') off, as it defaults to 'and'. So the attribute filter looks like this:
'attribute_filter', array(array(198, '=', '1'))

Greetings from Luxembourg

Claudia

Daniele Nocentini

Friday 01 September 2006 12:57:11 am

Hello,
I try this in my fetch function:

'attribute_filter', array( 'and', array(308, '=', false()), array(310, '=', false()) )

but return 0, it's wrong because there are many nodes that match this fetch.

Antica Bottega Digitale srl
http://www.abd.it

Claudia Kosny

Friday 01 September 2006 2:20:27 am

Hello Daniele

are you sure that you want to match an attribute to false()? If you want to match to 0 (zero) then rather match to 0, not to false()

Claudia

Daniele Nocentini

Friday 01 September 2006 2:35:18 am

the attributes are checkbox, in another fetch I false() and work fine

{def $list_items=fetch('content','list',hash('parent_node_id',$node.node_id,
										  'class_filter_type', $class_filter_type, 
										  'class_filter_array', $class_array,
										  'attribute_filter', array( array( 308, '=', false() ) ),
										  'sort_by', $node.sort_array,
										  'limit', $page_limit,
										  'offset', $view_parameters.offset,
										  'depth_operator', eq))

this fetch works fine, but if I add another attributes filter does not works.

Antica Bottega Digitale srl
http://www.abd.it

Andreas Kaiser

Friday 01 September 2006 4:38:53 am

Thanks Claudia!!!! You're the best.

I have added this line and it works:

attribute_filter, array(array(198, '=', 1))

Anyway I have to learn a lot more about the templating code. I'm not a programmer, I do too much copy & paste. (but normally it works... have seen too much code in my life!)

Thanks again Claudia.

eZ Partner in Madrid (Spain)
Web: http://www.atela.net/

Andreas Kaiser

Friday 01 September 2006 4:50:17 am

Daniele,

have you tried to use 0 instead of false() (like Claudia says)? Also, when you try to add another attribute filter are you using "or"?

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

In my case the attribute is also a checkbox and I use 0 or 1.

eZ Partner in Madrid (Spain)
Web: http://www.atela.net/

Daniele Nocentini

Friday 01 September 2006 5:33:03 am

I try:

'attribute_filter', array( 'and', array(308, '=', 0), array(310, '=', 0) )

and does not works.

The question is, why if I use false and one attribute filter condition the fetch return nodes right and if I use two attribute filter condition (and logical) not works?

Antica Bottega Digitale srl
http://www.abd.it

Andreas Kaiser

Friday 01 September 2006 7:45:21 am

Have you tried to clear cache?

I have been testing this (198 = checkbox / 201 = checkbox; these attributes are from the same class):

attribute_filter, array('and', array(198,'=',1), array(201,'=',1)),

and modifications with other attributes (like textline) and 'or'. Only some worked until I cleared the cache everytime I modified the template. After clearing cache it works!

eZ Partner in Madrid (Spain)
Web: http://www.atela.net/

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 21:06:42
Script start
Timing: Jan 18 2025 21:06:42
Module start 'layout'
Timing: Jan 18 2025 21:06:42
Module start 'content'
Timing: Jan 18 2025 21:06:43
Module end 'content'
Timing: Jan 18 2025 21:06:43
Script end

Main resources:

Total runtime1.3290 sec
Peak memory usage4,096.0000 KB
Database Queries77

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 588.0313152.6406
Module start 'layout' 0.00690.0030 740.671939.4609
Module start 'content' 0.00991.3175 780.1328662.2109
Module end 'content' 1.32740.0015 1,442.343824.1563
Script end 1.3289  1,466.5000 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.2574160.0002
Check MTime0.00140.1029160.0001
Mysql Total
Database connection0.00090.068310.0009
Mysqli_queries1.249994.0511770.0162
Looping result0.00070.0528750.0000
Template Total1.288897.020.6444
Template load0.00210.157220.0010
Template processing1.286796.816020.6433
Template load and register function0.00010.006710.0001
states
state_id_array0.00150.113010.0015
state_identifier_array0.00090.064220.0004
Override
Cache load0.00190.1412610.0000
Sytem overhead
Fetch class attribute can translate value0.00060.045730.0002
Fetch class attribute name0.00150.1092110.0001
XML
Image XML parsing0.00100.073830.0003
class_abstraction
Instantiating content class attribute0.00000.0027160.0000
General
dbfile0.00090.0705220.0000
String conversion0.00000.000640.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/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
19content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
9content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 49
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs