QuickTable: allow to enforce filters

This commit is contained in:
Thomas Gelf 2015-09-14 16:26:15 +02:00
parent 0f65d18168
commit 7bc59c010e
1 changed files with 23 additions and 1 deletions

View File

@ -7,6 +7,7 @@ use Icinga\Data\Filter\FilterAnd;
use Icinga\Data\Filter\FilterChain;
use Icinga\Data\Filter\FilterNot;
use Icinga\Data\Filter\FilterOr;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Selectable;
use Icinga\Data\Paginatable;
use Icinga\Exception\QueryException;
@ -27,6 +28,8 @@ abstract class QuickTable implements Paginatable
protected $filter;
protected $enforcedFilters = array();
protected $searchColumns = array();
protected function renderRow($row)
@ -96,8 +99,18 @@ abstract class QuickTable implements Paginatable
$query->limit($this->getLimit(), $this->getOffset());
}
$filter = null;
$enforced = $this->enforcedFilters;
if ($this->filter && ! $this->filter->isEmpty()) {
$query->where($this->renderFilter($this->filter));
$filter = $this->filter;
} elseif (! empty($enforced)) {
$filter = array_shift($enforced);
}
if ($filter) {
foreach ($enforced as $f) {
$filter->andFilter($f);
}
$query->where($this->renderFilter($filter));
}
return $db->fetchAll($query);
@ -234,6 +247,15 @@ abstract class QuickTable implements Paginatable
return $this;
}
public function enforceFilter($filter, $expression = null)
{
if (! $filter instanceof Filter) {
$filter = Filter::where($filter, $expression);
}
$this->enforcedFilters[] = $filter;
return $this;
}
public function getFilterEditor(Request $request)
{
$filterEditor = Widget::create('filterEditor')