Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop: Randomizing images from Gallery even the output is cached. #276

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions core/components/gallery/model/gallery/galitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -252,8 +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'],
Expand All @@ -267,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');
Expand Down