DataView: use default sort order if none given

We should not be forced to order(null) to have the default order, that
should be the default in case order has not been called.

refs #6644
This commit is contained in:
Thomas Gelf 2014-09-02 12:54:38 +02:00
parent 6be31f4f51
commit 307787cfb7
1 changed files with 16 additions and 12 deletions

View File

@ -31,6 +31,8 @@ abstract class DataView implements Browsable, Filterable, Sortable
protected $connection; protected $connection;
protected $isSorted = false;
/** /**
* Create a new view * Create a new view
* *
@ -99,6 +101,7 @@ public function dump()
protected function applyUrlFilter($request = null) protected function applyUrlFilter($request = null)
{ {
$url = Url::fromRequest(); $url = Url::fromRequest();
$limit = $url->shift('limit'); $limit = $url->shift('limit');
$sort = $url->shift('sort'); $sort = $url->shift('sort');
$dir = $url->shift('dir'); $dir = $url->shift('dir');
@ -132,20 +135,19 @@ public function dump()
} }
} }
$order = isset($params['order']) ? $params['order'] : null; if (isset($params['sort'])) {
if ($order !== null) {
if (strtolower($order) === 'desc') { $order = isset($params['order']) ? $params['order'] : null;
$order = self::SORT_DESC; if ($order !== null) {
} else { if (strtolower($order) === 'desc') {
$order = self::SORT_ASC; $order = self::SORT_DESC;
} else {
$order = self::SORT_ASC;
}
} }
$view->sort($params['sort'], $order);
} }
$view->sort(
isset($params['sort']) ? $params['sort'] : null,
$order
);
return $view; return $view;
} }
@ -226,6 +228,7 @@ public function dump()
foreach ($sortColumns['columns'] as $column) { foreach ($sortColumns['columns'] as $column) {
$this->query->order($column, $order); $this->query->order($column, $order);
} }
$this->isSorted = true;
} }
return $this; return $this;
} }
@ -285,6 +288,7 @@ public function dump()
*/ */
public function getQuery() public function getQuery()
{ {
if (! $this->isSorted) { $this->sort(); }
return $this->query; return $this->query;
} }