Let PivotTable implement Sortable

refs #9333
This commit is contained in:
Eric Lippmann 2015-08-18 14:17:07 +02:00
parent d1f9c5ff0d
commit f2f1e12b8e
1 changed files with 55 additions and 21 deletions

View File

@ -8,7 +8,7 @@ use Icinga\Application\Icinga;
use Icinga\Web\Paginator\Adapter\QueryAdapter;
use Zend_Paginator;
class PivotTable
class PivotTable implements Sortable
{
/**
* The query to fetch as pivot table
@ -17,20 +17,6 @@ class PivotTable
*/
protected $baseQuery;
/**
* The query to fetch the x axis labels
*
* @var SimpleQuery
*/
protected $xAxisQuery;
/**
* The query to fetch the y axis labels
*
* @var SimpleQuery
*/
protected $yAxisQuery;
/**
* The column that contains the labels for the x axis
*
@ -59,6 +45,27 @@ class PivotTable
*/
protected $yAxisFilter;
/**
* The query to fetch the x axis labels
*
* @var SimpleQuery
*/
protected $xAxisQuery;
/**
* The query to fetch the y axis labels
*
* @var SimpleQuery
*/
protected $yAxisQuery;
/**
* Column for sorting the result set
*
* @var array
*/
protected $order = array();
/**
* Create a new pivot table
*
@ -73,6 +80,31 @@ class PivotTable
$this->yAxisColumn = $yAxisColumn;
}
/**
* {@inheritdoc}
*/
public function getOrder()
{
return $this->order;
}
/**
* {@inheritdoc}
*/
public function hasOrder()
{
return ! empty($this->order);
}
/**
* {@inheritdoc}
*/
public function order($field, $direction = null)
{
$this->order[$field] = $direction;
return $this;
}
/**
* Set the filter to apply on the query for the x axis
*
@ -137,9 +169,10 @@ class PivotTable
$this->xAxisQuery->addFilter($this->xAxisFilter);
}
if (! $this->xAxisQuery->hasOrder($this->xAxisColumn)) {
$this->xAxisQuery->order($this->xAxisColumn, 'asc');
}
$this->xAxisQuery->order(
$this->xAxisColumn,
isset($this->order[$this->xAxisColumn]) ? $this->order[$this->xAxisColumn] : self::SORT_ASC
);
}
return $this->xAxisQuery;
@ -161,9 +194,10 @@ class PivotTable
$this->yAxisQuery->addFilter($this->yAxisFilter);
}
if (! $this->yAxisQuery->hasOrder($this->yAxisColumn)) {
$this->yAxisQuery->order($this->yAxisColumn, 'asc');
}
$this->yAxisQuery->order(
$this->yAxisColumn,
isset($this->order[$this->yAxisColumn]) ? $this->order[$this->yAxisColumn] : self::SORT_ASC
);
}
return $this->yAxisQuery;