mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-26 03:09:11 +02:00
QuickTable: allow to enforce filters
This commit is contained in:
parent
0f65d18168
commit
7bc59c010e
@ -7,6 +7,7 @@ use Icinga\Data\Filter\FilterAnd;
|
|||||||
use Icinga\Data\Filter\FilterChain;
|
use Icinga\Data\Filter\FilterChain;
|
||||||
use Icinga\Data\Filter\FilterNot;
|
use Icinga\Data\Filter\FilterNot;
|
||||||
use Icinga\Data\Filter\FilterOr;
|
use Icinga\Data\Filter\FilterOr;
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Data\Selectable;
|
use Icinga\Data\Selectable;
|
||||||
use Icinga\Data\Paginatable;
|
use Icinga\Data\Paginatable;
|
||||||
use Icinga\Exception\QueryException;
|
use Icinga\Exception\QueryException;
|
||||||
@ -27,6 +28,8 @@ abstract class QuickTable implements Paginatable
|
|||||||
|
|
||||||
protected $filter;
|
protected $filter;
|
||||||
|
|
||||||
|
protected $enforcedFilters = array();
|
||||||
|
|
||||||
protected $searchColumns = array();
|
protected $searchColumns = array();
|
||||||
|
|
||||||
protected function renderRow($row)
|
protected function renderRow($row)
|
||||||
@ -96,8 +99,18 @@ abstract class QuickTable implements Paginatable
|
|||||||
$query->limit($this->getLimit(), $this->getOffset());
|
$query->limit($this->getLimit(), $this->getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filter = null;
|
||||||
|
$enforced = $this->enforcedFilters;
|
||||||
if ($this->filter && ! $this->filter->isEmpty()) {
|
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);
|
return $db->fetchAll($query);
|
||||||
@ -234,6 +247,15 @@ abstract class QuickTable implements Paginatable
|
|||||||
return $this;
|
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)
|
public function getFilterEditor(Request $request)
|
||||||
{
|
{
|
||||||
$filterEditor = Widget::create('filterEditor')
|
$filterEditor = Widget::create('filterEditor')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user