Skip to content

Commit

Permalink
monitoring: Fix that sorting a data view is not possible if its sort
Browse files Browse the repository at this point in the history
rules are empty
  • Loading branch information
Alexander Fuhr committed Oct 7, 2014
1 parent 421263a commit a9ae75b
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions modules/monitoring/library/Monitoring/DataView/DataView.php
Expand Up @@ -204,42 +204,43 @@ public function pivot($xAxisColumn, $yAxisColumn)
public function sort($column = null, $order = null)
{
$sortRules = $this->getSortRules();

if ($sortRules !== null) {
if ($column === null) {
$sortColumns = reset($sortRules);
if ($column === null) {
// Use first available sort rule as default
if (empty($sortRules)) {
return $this;
}
$sortColumns = reset($sortRules);
if (! isset($sortColumns['columns'])) {
$sortColumns['columns'] = array(key($sortRules));
}
} else {
if (isset($sortRules[$column])) {
$sortColumns = $sortRules[$column];
if (! isset($sortColumns['columns'])) {
$sortColumns['columns'] = array(key($sortRules));
$sortColumns['columns'] = array($column);
}
} else {
if (isset($sortRules[$column])) {
$sortColumns = $sortRules[$column];
if (! isset($sortColumns['columns'])) {
$sortColumns['columns'] = array($column);
}
} else {
$sortColumns = array(
'columns' => array($column),
'order' => $order
);
};
}
$sortColumns = array(
'columns' => array($column),
'order' => $order
);
};
}

$order = $order === null ? (isset($sortColumns['order']) ? $sortColumns['order'] : self::SORT_ASC) : $order;
$order = (strtoupper($order) === self::SORT_ASC) ? 'ASC' : 'DESC';
$order = $order === null ? (isset($sortColumns['order']) ? $sortColumns['order'] : self::SORT_ASC) : $order;
$order = (strtoupper($order) === self::SORT_ASC) ? 'ASC' : 'DESC';

foreach ($sortColumns['columns'] as $column) {
if (! $this->isValidFilterTarget($column)) {
throw new QueryException(
t('The sort column "%s" is not allowed in "%s".'),
$column,
get_class($this)
);
}
$this->query->order($column, $order);
foreach ($sortColumns['columns'] as $column) {
if (! $this->isValidFilterTarget($column)) {
throw new QueryException(
t('The sort column "%s" is not allowed in "%s".'),
$column,
get_class($this)
);
}
$this->isSorted = true;
$this->query->order($column, $order);
}
$this->isSorted = true;
return $this;
}

Expand All @@ -250,7 +251,7 @@ public function sort($column = null, $order = null)
*/
public function getSortRules()
{
return null;
return array();
}

/**
Expand Down Expand Up @@ -365,6 +366,9 @@ public function addFilter(Filter $filter)
*/
public function paginate($itemsPerPage = null, $pageNumber = null)
{
if (! $this->isSorted) {
$this->order();
}
return $this->query->paginate($itemsPerPage, $pageNumber);
}

Expand Down

0 comments on commit a9ae75b

Please sign in to comment.