Struggling with shuffle operator

Author Message

Bjørn Kaarstein

Friday 16 April 2004 3:50:31 pm

I'm trying to use the shuffle-operator found here :

http://www.ez.no/community/contributions/template_plugins/random_sort_array_or_fetch_shuffle_operator

The extension is installed, my directory is called extensions, is put on the EZ root, and configured in site.ini.append.php. I can't get it to work though...

{let randomised_array=fetch('content','tree', hash('parent_node_id', '77'))|shuffle}
{section name=random loop=$randomised_array}
{$:item.name}  -- testing</br>
{/section}
{/let}

This is in my pagelayout, the fetch works, but it comes with the same list on every reload. I'm clearing the caches, so I don't think that's the problem. Any suggestions? Is there a place where I can check whether the extension is properly installed=

Regards Bjørn

Alex Jones

Monday 19 April 2004 6:42:48 am

Well, in 3.3 at least you can check to ensure an extension is enabled by going to yoru Admin area, choosing the <i>Setup</i> tab, clicking on <i>Advanced</i> and then choosing <i>Extension Setup</i>. The box next to the shuffle operator needs to be checked.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

James Packham

Monday 19 April 2004 7:12:40 am

Yeah, your template code looks fine, so I'd guess it's something to do with the way the extension is installed. I have shuffle working and looked at my override/site.ini.append.php, it has two entries for shuffle:

[ExtensionSettings]
ActiveExtensions[]=shuffle

and

[TemplateSettings]
ExtensionAutoloadPath[]=shuffle

Try including both if you haven't already.

Regards,

James

Bjørn Kaarstein

Monday 19 April 2004 7:32:54 am

Thanks guys, but still no success.

The shuffle operator is activated within the admin interface.
I have the correct lines in my site.ini.append.php.

James, could you please compare your extension folder to mine?

site/extensions/shuffle/ ->contains readme.txt and shuffleoperator.php
site/extensions/shuffle/autoloads/ ->contains eztemplateautloload.php

Might the problem be that my extension directory is named extensions instead of extension?
I have altered that in the site.ini.append.php, so that would be strange...

Regards Bjørn

Alex Jones

Monday 19 April 2004 7:56:26 am

The directory name may very well be the problem as <i>eztemplateautoload.php</i> contains the path extension/shuffle/shuffleoperator.php

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

K259

Monday 19 April 2004 8:32:20 am

Bjørn, I hope your file in:
site/extensions/shuffle/autoloads/ is called eztemplateautoload.php and not eztemplateautloload.php as you have written.

Zinistry

Bjørn Kaarstein

Monday 19 April 2004 3:10:25 pm

Got it!

That loload was just a typo :)

Thx Alex, it was just extensions instead of extension directory which caused the problem.
Now I'll get around to some shuffling!

Regards Bjørn

Bjørn Kaarstein

Monday 19 April 2004 3:55:40 pm

Well, so far so good, I've got a random list...

{let randomised_array=fetch('content','tree', hash('parent_node_id', '77',
						class_filter_type, "include", class_filter_array, array(17)))|shuffle}

{section name=random loop=$randomised_array}

{node_view_gui view=element content_node=$random:item} </br>

{/section}
{/let}

This shows every object fetched in a random order, and works just fine, but I only want to show ONE result. Any ideas on how to do that? It would be pointless to set a limit on the fetch, because then I wan't have anything to shuffle... It should be an easy thing to achieve I guess, but I can't seem to figure it out at the moment...

Regards Bjørn

K259

Tuesday 20 April 2004 3:07:34 am

Maybe this will work ;)

{let randomised_array=fetch('content','tree', hash('parent_node_id', '77',
						class_filter_type, "include", class_filter_array, array(17)))|shuffle}

{section name=random loop=$randomised_array max=1}

{node_view_gui view=element content_node=$random:item} </br>

{/section}
{/let}

Bjørn Kaarstein

Tuesday 20 April 2004 3:32:33 am

Thanks a million.

I knew it had to be simple. Even though I've broken my leg, I didn't think it would affect my brain in such an ugly manner. Must be side-effects from medication during surgery :)

Regards Bjørn

Alex Jones

Tuesday 20 April 2004 7:04:21 am

Nice bit of code Zinistry. I've somehow missed the <i>max</i> attribute of <i>{section}</i> causing me to solve the issue (pulling a single random object) in a different way. Instead of looping through the objects a single time, I pull the first item in the generated array. It is good to see a different way to achieve the same goal. I may well change my templates after playing with <i>max</i>. :) The code I've written looks like:

{let KID=fetch(content,tree,hash(parent_node_id,186,class_filter_type,include,class_filter_array, array(14)))|shuffle}
  <a href={$KID.0.url_alias|ezurl}>{attribute_view_gui attribute=$KID.0.data_map.image image_class=ce_main}</a><br />
  <a href={$KID.0.url_alias|ezurl}>{$KID.0.data_map.type_model.content|wash}
{/let}

Thanks!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

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 19 2025 11:53:46
Script start
Timing: Jan 19 2025 11:53:46
Module start 'layout'
Timing: Jan 19 2025 11:53:46
Module start 'content'
Timing: Jan 19 2025 11:53:47
Module end 'content'
Timing: Jan 19 2025 11:53:47
Script end

Main resources:

Total runtime0.9821 sec
Peak memory usage4,096.0000 KB
Database Queries85

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0054 589.1797152.6250
Module start 'layout' 0.00540.0032 741.804739.4453
Module start 'content' 0.00860.9723 781.2500707.0156
Module end 'content' 0.98090.0012 1,488.265624.1563
Script end 0.9821  1,512.4219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.3882160.0002
Check MTime0.00160.1580160.0001
Mysql Total
Database connection0.00060.064110.0006
Mysqli_queries0.881389.7336850.0104
Looping result0.00090.0947830.0000
Template Total0.942195.920.4710
Template load0.00300.308020.0015
Template processing0.939095.609620.4695
Template load and register function0.00020.016210.0002
states
state_id_array0.00200.198910.0020
state_identifier_array0.00130.136920.0007
Override
Cache load0.00250.2557640.0000
Sytem overhead
Fetch class attribute can translate value0.00100.101240.0002
Fetch class attribute name0.00140.1397130.0001
XML
Image XML parsing0.00900.919440.0023
class_abstraction
Instantiating content class attribute0.00000.0032150.0000
General
dbfile0.01091.1131220.0005
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
11content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
20content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/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: 48
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs