Merge two arrays

Author Message

paul bolger

Sunday 18 November 2007 3:40:22 pm

I have a news items folder, created by doing a fetch/list on a subfolder, sorted by an attribute (start time, they are calendar events).

I'd like to add nodes from a second folder, and have them appear every x items in the resulting array (folder 1 item 1, folder 1 item 2, folder 2 item 1, folder 1 item 3 etc). the items from the second folder would need to be sorted by priority. I'd prefer to not be locked into having to stipulate the actual priority numbers for the items in the second folder (users hate that sort of thing).

Can anyone suggest a good approach to this?

Paul Bolger

Maxime Thomas

Monday 19 November 2007 5:37:16 am

Hi,

You can use two arrays resulting from a fetch and foreach loop :

{def $index_for_table2=0}
{foreach $table1 as $k => $t1}
Print data for $t1 : {node_view_gui node=$t1}

{delimiter}

{if $k|mod(3)|eq(1)}

Print data for $t2 ! {node_view_gui node=$table2[$index_for_table2]}
{set $index_for_table2=$index_for_table2|inc()}

{/if}

{/delimiter}

{/foreach}
{undef $index_fot_table2}

Reference :
http://ez.no/doc/ez_publish/technical_manual/3_10/reference/template_control_structures/looping/foreach

Maxime Thomas
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

paul bolger

Tuesday 20 November 2007 4:35:18 pm

Thanks, That sound like it would do the job.

Paul Bolger

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 21:18:37
Script start
Timing: Jan 18 2025 21:18:37
Module start 'layout'
Timing: Jan 18 2025 21:18:37
Module start 'content'
Timing: Jan 18 2025 21:18:39
Module end 'content'
Timing: Jan 18 2025 21:18:39
Script end

Main resources:

Total runtime1.4671 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 587.8125152.6094
Module start 'layout' 0.00590.0044 740.421939.4141
Module start 'content' 0.01031.4554 779.8359542.6641
Module end 'content' 1.46570.0014 1,322.500012.1875
Script end 1.4671  1,334.6875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.2316160.0002
Check MTime0.00140.0967160.0001
Mysql Total
Database connection0.00140.094510.0014
Mysqli_queries1.414196.3894570.0248
Looping result0.00060.0425550.0000
Template Total1.428897.420.7144
Template load0.00180.124620.0009
Template processing1.427097.266320.7135
Template load and register function0.00010.006610.0001
states
state_id_array0.00150.099010.0015
state_identifier_array0.00340.230020.0017
Override
Cache load0.00150.1056170.0001
Sytem overhead
Fetch class attribute can translate value0.00140.094320.0007
Fetch class attribute name0.00140.092450.0003
XML
Image XML parsing0.00070.049620.0004
class_abstraction
Instantiating content class attribute0.00000.002760.0000
General
dbfile0.00080.0522220.0000
String conversion0.00000.000640.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
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/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
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs