Forums / Setup & design / Struggling with shuffle operator

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>

eZ debug

Timing: Jan 19 2025 09:40:10
Script start
Timing: Jan 19 2025 09:40:10
Module start 'content'
Timing: Jan 19 2025 09:40:12
Module end 'content'
Timing: Jan 19 2025 09:40:12
Script end

Main resources:

Total runtime1.4579 sec
Peak memory usage4,096.0000 KB
Database Queries222

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0069 588.9766180.8281
Module start 'content' 0.00691.3275 769.8047712.0938
Module end 'content' 1.33440.1234 1,481.8984344.4609
Script end 1.4578  1,826.3594 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.2687210.0002
Check MTime0.00150.1018210.0001
Mysql Total
Database connection0.00070.045310.0007
Mysqli_queries1.370694.01702220.0062
Looping result0.00220.15102200.0000
Template Total1.428198.020.7141
Template load0.00210.145220.0011
Template processing1.426097.815320.7130
Template load and register function0.00030.019610.0003
states
state_id_array0.00120.081210.0012
state_identifier_array0.00150.104120.0008
Override
Cache load0.00190.1282640.0000
Sytem overhead
Fetch class attribute can translate value0.00170.117550.0003
Fetch class attribute name0.00120.0794130.0001
XML
Image XML parsing0.00140.093250.0003
class_abstraction
Instantiating content class attribute0.00000.0018150.0000
General
dbfile0.00180.1267330.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
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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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