From 8fa2419e05138935f606722ccf28262abc8e680a Mon Sep 17 00:00:00 2001 From: Oliver Haase-Lobinger Date: Fri, 18 Sep 2015 20:18:26 +0200 Subject: [PATCH 1/2] Make output order of resources like input order To preserve the CSV order of `&resources` one has to manually insert `&sortby='FIELD(modResource.id,[[+myResources]])'`. This is a possible way how do do it but I thought it would be nicer if we had the `sortby` token "resources" which ads this behavior automatically. --- core/components/getresources/snippet.getresources.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/components/getresources/snippet.getresources.php b/core/components/getresources/snippet.getresources.php index 62d71d0..da3f8cd 100644 --- a/core/components/getresources/snippet.getresources.php +++ b/core/components/getresources/snippet.getresources.php @@ -410,6 +410,10 @@ if (strpos($sortby, '{') === 0) { $sorts = $modx->fromJSON($sortby); } else { + if (strtolower($sortby) == "resources") { + $resources__csv = implode(',',$resources); + $sortby= "FIELD(modResource.id,{$resources__csv})"; + } $sorts = array($sortby => $sortdir); } if (is_array($sorts)) { From 8baff2ff1e81ea5efa59a68e4f054f5aa4ec6e0b Mon Sep 17 00:00:00 2001 From: Oliver Haase-Lobinger Date: Fri, 18 Sep 2015 20:41:45 +0200 Subject: [PATCH 2/2] Make output order of resources like input order To preserve the CSV order of &resources one has to manually insert &sortby='FIELD(modResource.id,[[+myResources]])'. This is a possible way how do do it but I thought it would be nicer if we had the sortby token resources which ads this behavior automatically. I hope you like my little addition and will merge it. Or just feel free to modify it. cheers Oliver --- core/components/getresources/snippet.getresources.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/components/getresources/snippet.getresources.php b/core/components/getresources/snippet.getresources.php index da3f8cd..e5b0ee4 100644 --- a/core/components/getresources/snippet.getresources.php +++ b/core/components/getresources/snippet.getresources.php @@ -411,6 +411,11 @@ $sorts = $modx->fromJSON($sortby); } else { if (strtolower($sortby) == "resources") { + if (is_array($resources)) { + $resources__csv = implode(',',$resources); + } else { + $resources__csv = $resources; + } $resources__csv = implode(',',$resources); $sortby= "FIELD(modResource.id,{$resources__csv})"; }