From eba55e18325543532c9f5c5a61122713ba0f0eb6 Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 14 Nov 2013 21:19:24 +0100 Subject: [PATCH 1/2] Issue #258 Randomizing items even the output is cached. --- core/components/gallery/model/gallery/galitem.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/components/gallery/model/gallery/galitem.class.php b/core/components/gallery/model/gallery/galitem.class.php index 61e85e8..8872b88 100644 --- a/core/components/gallery/model/gallery/galitem.class.php +++ b/core/components/gallery/model/gallery/galitem.class.php @@ -243,6 +243,7 @@ public function move($album) { } public static function getList(modX &$modx,array $scriptProperties = array()) { + $sort = $modx->getOption('sort',$scriptProperties,'rank'); $cacheKey = 'gallery/item/list/'.md5(serialize($scriptProperties)); if ($modx->getCacheManager() && $cache = $modx->cacheManager->get($cacheKey)) { $items = array(); @@ -254,6 +255,11 @@ public static function getList(modX &$modx,array $scriptProperties = array()) { } $data = array( + + if (in_array(strtolower($sort),array('random','rand()','rand'))) { + shuffle($items); + } + 'items' => $items, 'total' => $cache['total'], 'album' => $cache['album'], From 6f8b67f997724cfffb8048764e8a18ff6cab4fc2 Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 14 Nov 2013 21:27:56 +0100 Subject: [PATCH 2/2] small changes --- core/components/gallery/model/gallery/galitem.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/components/gallery/model/gallery/galitem.class.php b/core/components/gallery/model/gallery/galitem.class.php index 8872b88..b54a9fb 100644 --- a/core/components/gallery/model/gallery/galitem.class.php +++ b/core/components/gallery/model/gallery/galitem.class.php @@ -253,13 +253,12 @@ public static function getList(modX &$modx,array $scriptProperties = array()) { $item->fromArray($data,'',true,true); $items[] = $item; } - - $data = array( if (in_array(strtolower($sort),array('random','rand()','rand'))) { shuffle($items); } + $data = array( 'items' => $items, 'total' => $cache['total'], 'album' => $cache['album'], @@ -273,7 +272,6 @@ public static function getList(modX &$modx,array $scriptProperties = array()) { /* Fix to make it work with getPage which uses "offset" instead of "start" */ $offset = $modx->getOption('offset',$scriptProperties,0); if ($offset > 0) { $start = $offset; } - $sort = $modx->getOption('sort',$scriptProperties,'rank'); $sortAlias = $modx->getOption('sortAlias',$scriptProperties,'galItem'); if ($sort == 'rank') $sortAlias = 'AlbumItems'; $dir = $modx->getOption('dir',$scriptProperties,'ASC');