How to sort arrays of ez content objects?

Author Message

Daniele Nocentini

Tuesday 16 September 2008 8:02:54 am

Hi,
I want to sort array of ez content objects by the object name. The problem is that I'm not getting them with a fetch which would sort them properly because I need to create custom array that contain some ez content object.

Does anyone know a good solution?

Antica Bottega Digitale srl
http://www.abd.it

Paul Etienney

Wednesday 17 September 2008 4:16:17 am

I have the same question.
+1

-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney

Andreas Adelsberger

Wednesday 17 September 2008 4:29:18 am

You can create a new hash array and sort it afterwards using an extension:

http://ez.no/developer/contribs/template_plugins/arraysortoperator

...untested...

{def $new_array = array()} 
{foreach $children as $child}
		{set $new_array=$new_array|append(hash('name',$child.name,'ezobject',$child))}
{/foreach}

{set $new_array=$new_array|sort}

---------------------------------------
Styleflasher New Media OG
Websites. Games/Multimedia.

Daniele Nocentini

Wednesday 17 September 2008 7:44:15 am

Thanks Andreas for your solution it's great and work fine for my project, only one thing I have declared variable as an array:

{def $new_array = array()}

Antica Bottega Digitale srl
http://www.abd.it

Andreas Adelsberger

Wednesday 17 September 2008 7:46:46 am

You are welcome. I fixed it in the code above.

---------------------------------------
Styleflasher New Media OG
Websites. Games/Multimedia.

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 01:28:13
Script start
Timing: Jan 31 2025 01:28:13
Module start 'layout'
Timing: Jan 31 2025 01:28:13
Module start 'content'
Timing: Jan 31 2025 01:28:14
Module end 'content'
Timing: Jan 31 2025 01:28:14
Script end

Main resources:

Total runtime1.1923 sec
Peak memory usage8,192.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 588.2656151.2266
Module start 'layout' 0.00590.0046 739.4922220.7188
Module start 'content' 0.01051.1809 960.21094,512.5547
Module end 'content' 1.19140.0009 5,472.765615.8125
Script end 1.1922  5,488.5781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3059160.0002
Check MTime0.00130.1099160.0001
Mysql Total
Database connection0.00090.078010.0009
Mysqli_queries1.099792.2400650.0169
Looping result0.00060.0540630.0000
Template Total1.127894.620.5639
Template load0.00240.197820.0012
Template processing1.125594.396520.5627
Template load and register function0.00110.089110.0011
states
state_id_array0.00370.308610.0037
state_identifier_array0.00180.148320.0009
Override
Cache load0.00200.1659240.0001
Sytem overhead
Fetch class attribute can translate value0.00160.136630.0005
Fetch class attribute name0.00220.181680.0003
XML
Image XML parsing0.00510.424230.0017
class_abstraction
Instantiating content class attribute0.00000.0021100.0000
General
dbfile0.00460.3883280.0002
String conversion0.00000.000940.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
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/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: 20
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs