1
0
mirror of https://github.com/flarum/core.git synced 2025-07-19 07:41:22 +02:00

Fix index sorting

This commit is contained in:
Toby Zerner
2015-02-08 15:57:41 +10:30
parent 9fd935285f
commit a19b40e51c

View File

@@ -104,16 +104,19 @@ abstract class Base extends Controller
protected function sort($options) protected function sort($options)
{ {
$criteria = (string) $this->input('sort', ''); $criteria = (string) $this->input('sort', '');
$order = null;
if ($criteria && $criteria[0] == '-') {
$order = 'desc';
$criteria = substr($criteria, 1);
}
if (! in_array($criteria, $options)) { if (! in_array($criteria, $options)) {
$criteria = reset($options); $criteria = reset($options);
} }
$order = $criteria ? 'asc' : null; if ($criteria && ! $order) {
$order = 'asc';
if ($criteria && $criteria[0] == '-') {
$order = 'desc';
$criteria = substr($criteria, 1);
} }
return [ return [