Forums / Setup & design / Fetch & filter by class and attribute

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/

eZ debug

Timing: Jan 31 2025 04:31:31
Script start
Timing: Jan 31 2025 04:31:31
Module start 'content'
Timing: Jan 31 2025 04:31:31
Module end 'content'
Timing: Jan 31 2025 04:31:31
Script end

Main resources:

Total runtime0.1492 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 588.0313180.8281
Module start 'content' 0.00500.0041 768.8594106.0078
Module end 'content' 0.00910.1400 874.8672535.8281
Script end 0.1492  1,410.6953 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00312.1102200.0002
Check MTime0.00120.8226200.0001
Mysql Total
Database connection0.00060.404710.0006
Mysqli_queries0.106971.63881410.0008
Looping result0.00110.76351390.0000
Template Total0.139893.710.1398
Template load0.00070.461710.0007
Template processing0.139193.186910.1391
Override
Cache load0.00050.337710.0005
Sytem overhead
Fetch class attribute can translate value0.00080.559710.0008
XML
Image XML parsing0.00030.203710.0003
General
dbfile0.00593.9347200.0003
String conversion0.00000.005330.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.0002 secs