Forums / Developer / Group organisation objects by selection value

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

eZ debug

Timing: Jan 18 2025 02:18:20
Script start
Timing: Jan 18 2025 02:18:20
Module start 'content'
Timing: Jan 18 2025 02:18:22
Module end 'content'
Timing: Jan 18 2025 02:18:23
Script end

Main resources:

Total runtime2.7503 sec
Peak memory usage4,096.0000 KB
Database Queries191

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 587.8438180.8203
Module start 'content' 0.00631.5837 768.6641547.7500
Module end 'content' 1.59001.1603 1,316.4141332.7422
Script end 2.7503  1,649.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00410.1490210.0002
Check MTime0.00160.0571210.0001
Mysql Total
Database connection0.00080.028410.0008
Mysqli_queries0.759427.61011910.0040
Looping result0.00250.09061890.0000
Template Total1.787465.020.8937
Template load0.00180.065820.0009
Template processing1.785664.924420.8928
Template load and register function0.00010.003510.0001
states
state_id_array0.00180.064210.0018
state_identifier_array0.00160.057720.0008
Override
Cache load0.00150.0534300.0000
Sytem overhead
Fetch class attribute can translate value0.00210.076730.0007
Fetch class attribute name0.00090.032040.0002
XML
Image XML parsing0.00130.047430.0004
class_abstraction
Instantiating content class attribute0.00000.000340.0000
General
dbfile0.00310.1143340.0001
String conversion0.00000.000230.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
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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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