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.