Skip to content

Commit

Permalink
DataView: use default sort order if none given
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Thomas-Gelf committed Sep 2, 2014
1 parent 6be31f4 commit 307787c
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions modules/monitoring/library/Monitoring/DataView/DataView.php
Expand Up @@ -31,6 +31,8 @@ abstract class DataView implements Browsable, Filterable, Sortable

protected $connection;

protected $isSorted = false;

/**
* Create a new view
*
Expand Down Expand Up @@ -99,6 +101,7 @@ public static function fromRequest($request, array $columns = null)
protected function applyUrlFilter($request = null)
{
$url = Url::fromRequest();

$limit = $url->shift('limit');
$sort = $url->shift('sort');
$dir = $url->shift('dir');
Expand Down Expand Up @@ -132,20 +135,19 @@ public static function fromParams(array $params, array $columns = null)
}
}

$order = isset($params['order']) ? $params['order'] : null;
if ($order !== null) {
if (strtolower($order) === 'desc') {
$order = self::SORT_DESC;
} else {
$order = self::SORT_ASC;
}
}
if (isset($params['sort'])) {

$view->sort(
isset($params['sort']) ? $params['sort'] : null,
$order
);
$order = isset($params['order']) ? $params['order'] : null;
if ($order !== null) {
if (strtolower($order) === 'desc') {
$order = self::SORT_DESC;
} else {
$order = self::SORT_ASC;
}
}

$view->sort($params['sort'], $order);
}
return $view;
}

Expand Down Expand Up @@ -226,6 +228,7 @@ public function sort($column = null, $order = null)
foreach ($sortColumns['columns'] as $column) {
$this->query->order($column, $order);
}
$this->isSorted = true;
}
return $this;
}
Expand Down Expand Up @@ -285,6 +288,7 @@ public function getMappedField($field)
*/
public function getQuery()
{
if (! $this->isSorted) { $this->sort(); }
return $this->query;
}

Expand Down

0 comments on commit 307787c

Please sign in to comment.