attribute_filter with strings

Author Message

Ulrich L.

Tuesday 07 December 2004 2:13:19 am

Hi,
I just don't get it... I'm dealing with 'fetch' and the attribute_filter, but obviously there is still a synthax error. Can anybody help me?

{let string_node_name=concat("'", $node.name, "'")}
{let cds_by_artist=fetch( 'content', 'list', 
     hash( parent_node_id, 109, depth, 255, 
     class_filter_type, "include", class_filter_array, array(28),
     attribute_filter, array( 237, '=', $string_node_name) ) ) }

This piece of code shall give back all nodes under parent '109' which have the class_id '28' and the class_attribute_id with value of string_node_name.

(Application: I'd like to fetch all CDs by a certain artist, the name of the artist is stored in class_attribute 237).

Perhaps I made a very basic mistake, but I'm really struggling with the documentation on 'fetch' at the moment. However, I'm very impressed what can be achieved.

Hope anybody can help me.

Silke Fox

Tuesday 07 December 2004 2:48:35 am

attribute_filter expects an array of arrays as parameter.

Snippet from this documentation:
http://ez.no/ez_publish/documentation/development/libraries/ez_template/operators/data_fetch

fetch( 'content', 'list', 
          hash( parent_node_id, $node.node_id, 
                attribute_filter, array( array( 'article/title', '=', 'abc' ) ) ) )

This is because you can specify more than one filter option, like for example

... attribute_filter, array( array( 'article/id', '>', 100 ), array( 'article/id', '<', 200 ) ) ...

Ulrich L.

Tuesday 07 December 2004 6:06:19 am

Thank you, Silke.

My solution looks now like this:

{let cds_by_artist=fetch( 'content', 'list', 
   hash( parent_node_id, 109, depth, 63, 
   attribute_filter, array( array( 237, '=', $node.name ) ) ) ) }

I understand now that filtering an attribute makes it obsolet to filter the class_id first, because the attribute always belongs to a certain class. Is that right?

Silke Fox

Tuesday 07 December 2004 6:18:07 am

Yes, you're right, Ulrich.

And remember that you can use "class_identifier/class_attribute_identifier" instead of "attribute_id".
Improves readability and will still work after moving the class to another system (e.g. with package export/ import), while the ids will probably change.

Ulrich L.

Tuesday 07 December 2004 6:35:24 am

Thank you for this very useful hint.
Is there a similar way to deal with the numbers of the node IDs, can they be replaced by plain text as well?

Silke Fox

Wednesday 08 December 2004 12:50:00 am

As far as I know there is no way to avoid node ids completely, but at least you can avoid to use them <i>in templates</i>.

Have a look at the fetch_alias mechanism
http://ez.no/ez_publish/download/changelogs/ez_publish_3_3/template_fetch_by_alias
http://ez.no/ez_publish/documentation/reference/template_functions/miscellaneous/fetch_alias

Using this you can change ids in your fetchalias.ini.append while using more descriptive names in the templates.

Ulrich L.

Wednesday 08 December 2004 1:08:28 am

fetch_alias doesn't look too newbie-compatible...

(Probably) last question concerning this topic:
There is no way to define constant values in a global way?
Or perhaps I could use a kind of 'include' for this purpose?

Silke Fox

Wednesday 08 December 2004 4:55:58 am

One possibility might be to add a new ini file with the node ids you need
and read them from the template with

{ezini('[section]','[variable]','[ini file]')}

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 31 2025 05:59:03
Script start
Timing: Jan 31 2025 05:59:03
Module start 'layout'
Timing: Jan 31 2025 05:59:03
Module start 'content'
Timing: Jan 31 2025 05:59:03
Module end 'content'
Timing: Jan 31 2025 05:59:03
Script end

Main resources:

Total runtime0.0194 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 588.1328151.2109
Module start 'layout' 0.00620.0034 739.343836.6484
Module start 'content' 0.00960.0083 775.992298.1563
Module end 'content' 0.01790.0015 874.148437.9922
Script end 0.0194  912.1406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002613.1648140.0002
Check MTime0.00115.9021140.0001
Mysql Total
Database connection0.00073.582810.0007
Mysqli_queries0.003618.336830.0012
Looping result0.00000.185610.0000
Template Total0.00125.910.0012
Template load0.00094.573410.0009
Template processing0.00031.345910.0003
Override
Cache load0.00063.119410.0006
General
dbfile0.003819.538880.0005
String conversion0.00000.050440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_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