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 $isSorted = false;
/**
* Create a new view
*
@ -99,6 +101,7 @@ public function dump()
protected function applyUrlFilter($request = null)
{
$url = Url::fromRequest();
$limit = $url->shift('limit');
$sort = $url->shift('sort');
$dir = $url->shift('dir');
@ -132,6 +135,8 @@ public function dump()
}
}
if (isset($params['sort'])) {
$order = isset($params['order']) ? $params['order'] : null;
if ($order !== null) {
if (strtolower($order) === 'desc') {
@ -141,11 +146,8 @@ public function dump()
}
}
$view->sort(
isset($params['sort']) ? $params['sort'] : null,
$order
);
$view->sort($params['sort'], $order);
}
return $view;
}
@ -226,6 +228,7 @@ public function dump()
foreach ($sortColumns['columns'] as $column) {
$this->query->order($column, $order);
}
$this->isSorted = true;
}
return $this;
}
@ -285,6 +288,7 @@ public function dump()
*/
public function getQuery()
{
if (! $this->isSorted) { $this->sort(); }
return $this->query;
}