ImportsourceHookTable: move and refactor based...

...on SimpleQueryBasedTable
This commit is contained in:
Thomas Gelf 2017-08-16 11:15:39 +02:00
parent 9f70f84423
commit 6f3d07f729

View File

@ -1,14 +1,13 @@
<?php <?php
namespace Icinga\Module\Director\Tables; namespace Icinga\Module\Director\Web\Table;
use Icinga\Data\DataArray\ArrayDatasource; use Icinga\Data\DataArray\ArrayDatasource;
use Icinga\Data\Paginatable;
use Icinga\Module\Director\Hook\ImportSourceHook; use Icinga\Module\Director\Hook\ImportSourceHook;
use Icinga\Module\Director\Objects\ImportSource; use Icinga\Module\Director\Objects\ImportSource;
use Icinga\Module\Director\Web\Table\QuickTable; use ipl\Web\Table\SimpleQueryBasedTable;
class ImportsourceHookTable extends QuickTable class ImportsourceHookTable extends SimpleQueryBasedTable
{ {
/** @var ImportSource */ /** @var ImportSource */
protected $source; protected $source;
@ -46,47 +45,33 @@ class ImportsourceHookTable extends QuickTable
return $this; return $this;
} }
public function getTitles() public function getColumnsToBeRendered()
{ {
$cols = $this->getColumns(); return $this->getColumns();
return array_combine($cols, $cols);
}
public function count()
{
$q = clone($this->getBaseQuery());
return $q->count();
} }
protected function sourceHook() protected function sourceHook()
{ {
if ($this->sourceHook === null) { if ($this->sourceHook === null) {
$this->sourceHook = ImportSourceHook::loadByName( $this->sourceHook = ImportSourceHook::forImportSource(
$this->source->source_name, $this->source
$this->connection()
); );
} }
return $this->sourceHook; return $this->sourceHook;
} }
public function fetchData() public function fetchQueryRows()
{ {
if ($this->dataCache === null) { if ($this->dataCache === null) {
$query = $this->getBaseQuery()->columns($this->getColumns()); $this->dataCache = parent::fetchQueryRows();
if ($this->hasLimit() || $this->hasOffset()) {
$query->limit($this->getLimit(), $this->getOffset());
}
$this->dataCache = $query->fetchAll();
$this->source->applyModifiers($this->dataCache); $this->source->applyModifiers($this->dataCache);
} }
return $this->dataCache; return $this->dataCache;
} }
public function getBaseQuery() public function prepareQuery()
{ {
$ds = new ArrayDatasource($this->sourceHook()->fetchData()); $ds = new ArrayDatasource($this->sourceHook()->fetchData());
return $ds->select(); return $ds->select();