Forums / Setup & design / Process matrix array

Process matrix array

Author Message

paul bolger

Friday 02 May 2008 8:49:05 pm

Can anyone fill me in on a neat way to do this?

I'm generating an xml playlist from a matrix. The matrix data looks like this:

>0 string 'clip one'
>1 string 'http://test.com/one.mp4'
>2 string 'http://test.com/one.flv'
>3 string 'http://test.com/one.jpg'
>4 string 'clip two'
>5 string 'http://test.com/two.mp4'
>6 string 'http://test.com/two.flv'
>7 string 'http://test.com/two.jpg'
>8 string 'clip three'
>9 string 'http://test.com/three.mp4'
>10 string 'http://test.com/three.flv'
>11 string 'http://test.com/three.jpg'

and I need to turn it into this:

<item>
<title>clip one</title>
<location>http://test.com/one.mp4</location>
<fallback>http://test.com/one.flv</fallback>
<image>http://test.com/one.jpg</image>
</item>
<item>
<title>clip two</title>
<location>http://test.com/two.mp4</location>
<fallback>http://test.com/two.flv</fallback>
<image>http://test.com/two.jpg</image>
etc etc

Thanks.

Paul Bolger

Maxime Thomas

Saturday 03 May 2008 12:51:48 am

I will do this like this :

$results = array();
$results[]='<item>';

foreach ($matrix_data as $index => $row)
{

$case = $index % 4;

switch ($case)
{
case 0 :
$results[]="<title>$row</tile>";
break;
case 1:
$results[]="<location>$row</location>";
break;
case 2:
$results[]="<fallback>$row</fallback>";
break;
case 3 : 
$results[]="<image>$row</image>";
break;
}

}

$results[]='</item>';

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

Saturday 10 May 2008 5:47:07 am

I must admit that I'm having real problems getting this to work. I'm a little hazy on some of the template syntax used here (and the documentation doesn't seem to explain it).

What does adding empty square brackets to a variable do?

$results[]

And what does a

&

do?

regards

Paul Bolger

Maxime Thomas

Monday 12 May 2008 10:39:30 am

Hi Paul,

I've written the PHP version of the process, in case you were in a custom module/function.
By the way, you can adapt to the template version :

{def $results = '<item>'}

{foreach ($matrix_data as $index => $row)}

{def $case = $index|mod(4)}

{switch match=$case}
{case match=0}
{set $results=$results|append("<title>$row</title>")}
{/case}
{case match=1}
{set $results=$results|append("<location>$row</location>")}
{/case}

{case match=2}
{set $results=$results|append("<fallback>$row</fallback>")}
{/case}

{case match=3}
{set $results=$results|append("<image>$row</image>")}
{/case}

{/switch}

{/foreach}

{set $results=$results|append('</item>')}

{$results}

Is it clearer ?

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

Wednesday 14 May 2008 5:18:15 am

Thanks Maxime

That looks a lot more like what I understand. "Learn PHP" is unfortunately still on my todo list...

As a matter of interest I managed to make the template work using the sequence array method too. I'd be interested to know if you think this is worse, or more inefficient, than your method. I might put both into the documentation as comments in the Matrix section - save myself a lot of time when I need to do this again!

{def   $objects = $attribute.content.cells}
<title>{$attribute.object.name}</title>
<trackList>
{foreach $objects as $object sequence array( 'title', 'location' , 'fallback' , 'image') as $element}
{if eq( $element, 'title')}
<track>
{/if}
{if eq( $element, 'fallback')}
<meta rel='{$element}'>{$object}</meta>
{else}
<{$element}>{$object}</{$element}>
{/if}
{if eq( $element, 'location')}
<meta rel='type'>flv</meta>
{elseif eq( $element, 'image')}
</track>
{/if}
{/foreach}
</trackList>

Paul Bolger

Maxime Thomas

Wednesday 14 May 2008 10:40:02 pm

Hi Paul,

I guess it's the same. However, my way is closer to PHP because the sequence functionnality does not exist in PHP.

Max

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

eZ debug

Timing: Jan 18 2025 15:57:45
Script start
Timing: Jan 18 2025 15:57:45
Module start 'content'
Timing: Jan 18 2025 15:57:46
Module end 'content'
Timing: Jan 18 2025 15:57:47
Script end

Main resources:

Total runtime1.4431 sec
Peak memory usage4,096.0000 KB
Database Queries203

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 587.7031180.8438
Module start 'content' 0.00701.2709 768.5469599.3203
Module end 'content' 1.27790.1651 1,367.8672341.3828
Script end 1.4430  1,709.2500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.2743210.0002
Check MTime0.00150.1017210.0001
Mysql Total
Database connection0.00060.043010.0006
Mysqli_queries1.356093.96722030.0067
Looping result0.00230.15892010.0000
Template Total1.402697.220.7013
Template load0.00230.159020.0011
Template processing1.400397.038520.7002
Template load and register function0.00010.009410.0001
states
state_id_array0.00110.078710.0011
state_identifier_array0.00080.052520.0004
Override
Cache load0.00200.1401630.0000
Sytem overhead
Fetch class attribute can translate value0.00110.078530.0004
Fetch class attribute name0.00090.061680.0001
XML
Image XML parsing0.00150.102130.0005
class_abstraction
Instantiating content class attribute0.00000.0014120.0000
General
dbfile0.00330.2301330.0001
String conversion0.00000.000630.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
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/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: 34
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs