From a19b40e51c63ebb1ef7d7a68e8195bd707280ecb Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 8 Feb 2015 15:57:41 +1030 Subject: [PATCH] Fix index sorting --- framework/core/src/Flarum/Api/Actions/Base.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/framework/core/src/Flarum/Api/Actions/Base.php b/framework/core/src/Flarum/Api/Actions/Base.php index 897425488..53a765e91 100644 --- a/framework/core/src/Flarum/Api/Actions/Base.php +++ b/framework/core/src/Flarum/Api/Actions/Base.php @@ -104,16 +104,19 @@ abstract class Base extends Controller protected function sort($options) { $criteria = (string) $this->input('sort', ''); + $order = null; + + if ($criteria && $criteria[0] == '-') { + $order = 'desc'; + $criteria = substr($criteria, 1); + } if (! in_array($criteria, $options)) { $criteria = reset($options); } - $order = $criteria ? 'asc' : null; - - if ($criteria && $criteria[0] == '-') { - $order = 'desc'; - $criteria = substr($criteria, 1); + if ($criteria && ! $order) { + $order = 'asc'; } return [