Group organisation objects by selection value

Author Message

paul bolger

Friday 22 April 2011 4:09:04 pm

Not sure if this is the best approach to this problem.

I have a custom class 'organisation' (369) with a selection attribute containing 'organisation types'.

I want to group organisations by organisation type.

First, fetch the attributes of the content class:

{def $class_attribute=fetch( 'content', 'class_attribute', hash( 'attribute_id', 369 ) )}

Then start a loop of each of the options, and display the option name:

{foreach $class_attribute.content.options as $option}
<h3>{$option.name}</h3>

Then, get the organisations, which are under node 261:

{def $nodes=fetch( 'content', 'list',
        hash( 'parent_node_id', '261' ,
        'class_filter_type',  'include',
              'class_filter_array', array( 'organisation' )
        ) )}

Start another loop, display the current option id and name, node name and view template output of organisation type:

{foreach $nodes as $node}
Current ID: {$option.id} ({$option.data_map.name.content})<br />
<h1>{$node.name}</h1> 
<h2>{attribute_view_gui attribute=$node.data_map.organisation_type}</h2>

Define $node.data_map.organisation_type.content as array $organisation_ids. Not sure if this is necessary.

{def $organisation_ids=array()
      $organisation_ids=$node.data_map.organisation_type.content
 }

And then test one against the other:

{if array($organisation_ids)|contains ($option.id)} 
Contains: {$option.name}
{else} 
Contains nothing
{/if}

Close the loops, would probably destroy $organisation_ids as well.

{/foreach}

{/foreach}

So, my problem is that I can't get the Contains operator to work. I've tried various combinations of quote marks and spaces, but nothing. I've also tried using the string version of Contains on $node.data_map.organisation_type.data_text also to no avail.

 {$organisation_ids|attribute(show,2)}

Works fine, shows the ids of the selections.

What am I doing wrong?

Paul Bolger

Sander van den Akker

Sunday 24 April 2011 1:01:17 pm

You don't need "def $organisation_ids=array()", but only "$orrganisation_ids=$node.data_map.organisation_type.content", You can't define the same variable name twice, see the docs: http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-functions/Variables/def and you don't need to tell ez publish it is an array, it already knows.

Then, the if-statement should be "if $organisation_ids|contains ($option.id)"

That should work!

eZ Publish certified developer
http://auth.ez.no/certification/verify/392313

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 04:27:57
Script start
Timing: Jan 18 2025 04:27:57
Module start 'layout'
Timing: Jan 18 2025 04:27:57
Module start 'content'
Timing: Jan 18 2025 04:27:57
Module end 'content'
Timing: Jan 18 2025 04:27:57
Script end

Main resources:

Total runtime0.6731 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 589.1641152.6406
Module start 'layout' 0.00560.0034 741.804739.4844
Module start 'content' 0.00900.6628 781.2891542.6563
Module end 'content' 0.67180.0013 1,323.945312.1250
Script end 0.6731  1,336.0703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4882160.0002
Check MTime0.00130.1969160.0001
Mysql Total
Database connection0.00090.127610.0009
Mysqli_queries0.617191.6732540.0114
Looping result0.00060.0831520.0000
Template Total0.642895.520.3214
Template load0.00250.374520.0013
Template processing0.640395.118420.3201
Template load and register function0.00010.015610.0001
states
state_id_array0.00210.314810.0021
state_identifier_array0.00080.117420.0004
Override
Cache load0.00180.2688300.0001
Sytem overhead
Fetch class attribute can translate value0.00060.095120.0003
Fetch class attribute name0.00120.180140.0003
XML
Image XML parsing0.00120.177720.0006
class_abstraction
Instantiating content class attribute0.00000.001240.0000
General
dbfile0.00110.1575230.0000
String conversion0.00000.001540.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
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
8content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs