Forums / Setup & design / How do I sort a custom class' selection attribute?

How do I sort a custom class' selection attribute?

Author Message

Mindshare Interactive Campaigns

Wednesday 13 September 2006 8:17:24 am

I have a custom class with a multiple selection attribute named <b>Country</b>. This attribute lists several countries listed in no particular order.

This code is being used to display it as a dropdown:

<select name="study_country">
   <option value="-99" selected>Please select a country...</option>
   <option disabled>&nbsp;</option>
   {def $countries = fetch('content', 'class_attribute', hash('attribute_id', 308))}
     {foreach $countries.content.options as $dropdown_item}
        <option>{$dropdown_item.name}</option>
     {/foreach}
 </select>

This displays the countries in whatever order they are listed in the class definition. I need these to be sorted alphabetically. <b>fetch('content', 'class_attribute')</b> does not seem to allow this.

How can I accomplish this?

http://www.mindshare.net

Claudia Kosny

Thursday 14 September 2006 11:19:34 am

Hello there

As far as I know there is no inbuilt way to do this. The easy way out is to fetch all the country names in an array, sort this array and then loop through this array. Unfortunately there is no array sort function built into EZ so either take the contribution
http://ez.no/community/contribs/template_plugins/arraysortoperator
or just write your own wrapper for the php sort function.

Greetings from Luxembourg

Claudia

Mindshare Interactive Campaigns

Friday 15 September 2006 12:12:52 pm

Thank you for the suggestion Claudia. I installed the extension and rewrote the code above like so:

 {def $country_array = array("foo")}
 {def $countries = fetch('content', 'class_attribute', hash('attribute_id', 308))}
 
 {foreach $countries.content.options as $dropdown_item}
   {set $country_array = $country_array|append($dropdown_item.name)} 	
 {/foreach}
 
 {set $country_array = $country_array|remove(0,1)}
 {def $sorted_country_array = $country_array|sort('string')}
 
 <select name="study_country">
   <option value="-99" selected>Please select a country...</option>
   <option disabled>&nbsp;</option>
   {foreach $sorted_country_array as $sorted_country}
     <option>{$sorted_country}</option>
   {/foreach}
 </select>

This bit of code presents the list of attributes in the same order; i.e. the arraysortoperator extension is doing nothing. I noticed that the extension's description page states that it works with version 3.6 and 3.7, but I am using 3.8.

Any idea what is going wrong?

http://www.mindshare.net

Claudia Kosny

Friday 15 September 2006 1:18:57 pm

Hi there

The sort operator of this extension works fine for me (EZ 3.8.3). Are you sure that the extension is loaded alright? If not you should see an message in the debug output that the operator sort is not defined. Another possible thhough unlikely problem might be interference from another extension which might already implement an sort operator wich behaves differently.

Greetings from Luxembourg

Claudia

Mindshare Interactive Campaigns

Wednesday 20 September 2006 7:23:45 am

Good thinking. I turned on the debug output and found this line:

Warning: eZTemplate  	Sep 20 2006 17:19:51
Operator 'sort' is not registered

This is confusing though because the extension is registered in the admin screen. I tried both registering it manually by updating the necessary .ini files as well as using the Setup -> Extension form.

Am I missing a step?

http://www.mindshare.net

Claudia Kosny

Wednesday 20 September 2006 7:42:11 am

Hi there

Maybe the directry structure if the extension is not correct - this happens quite often to me if I unzip into a directory with the name of the extension and the zipfile provides already such a directory. So check your extensions folder and open the folder for the array sort extension. There you should see the folders autoloads and maybe settings (I already deleted the extension again so I am not sure).

Claudia

Mindshare Interactive Campaigns

Wednesday 20 September 2006 10:36:26 am

Claudia, you're brilliant!

I never considered that the files were not unzipped correctly. I went into the extension directory and found this:

|-extension
|---arraysortoperator
|-----docs
|-------autoloads
|-------classes
|-------settings

The <b>docs</b> directory contained the other directories, which is clearly wrong. The correct directory structure should look like this:

|-extension
|---arraysortoperator
|-----docs
|-----autoloads
|-----classes
|-----settings

Now my countries are sorted correctly. Thank you!

http://www.mindshare.net

eZ debug

Timing: Jan 18 2025 11:03:02
Script start
Timing: Jan 18 2025 11:03:02
Module start 'content'
Timing: Jan 18 2025 11:03:03
Module end 'content'
Timing: Jan 18 2025 11:03:03
Script end

Main resources:

Total runtime1.1057 sec
Peak memory usage4,096.0000 KB
Database Queries206

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0085 587.8594180.8125
Module start 'content' 0.00850.9613 768.6719556.6875
Module end 'content' 0.96980.1358 1,325.3594341.7813
Script end 1.1056  1,667.1406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.3871210.0002
Check MTime0.00170.1507210.0001
Mysql Total
Database connection0.00150.134810.0015
Mysqli_queries1.012391.55432060.0049
Looping result0.00210.19142040.0000
Template Total1.061496.020.5307
Template load0.00220.203120.0011
Template processing1.059195.790920.5296
Template load and register function0.00030.030810.0003
states
state_id_array0.00280.248710.0028
state_identifier_array0.00330.294220.0016
Override
Cache load0.00210.1887410.0001
Sytem overhead
Fetch class attribute can translate value0.00170.152930.0006
Fetch class attribute name0.00120.110270.0002
XML
Image XML parsing0.00050.041030.0002
class_abstraction
Instantiating content class attribute0.00000.001670.0000
General
dbfile0.00480.4349210.0002
String conversion0.00000.000730.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
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs