2015-07-26 15:39:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Tables;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Web\Table\QuickTable;
|
2015-12-02 04:23:00 +01:00
|
|
|
use Icinga\Data\DataArray\ArrayDatasource;
|
2015-07-26 15:39:37 +02:00
|
|
|
|
|
|
|
class ImportedrowsTable extends QuickTable
|
|
|
|
{
|
|
|
|
protected $checksum;
|
|
|
|
|
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
$db = $this->connection();
|
|
|
|
return $db->listImportedRowsetColumnNames($this->checksum);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setChecksum($checksum)
|
|
|
|
{
|
|
|
|
$this->checksum = $checksum;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitles()
|
|
|
|
{
|
|
|
|
$cols = $this->getColumns();
|
2015-12-02 04:23:00 +01:00
|
|
|
// TODO: replace key column with object name!?
|
|
|
|
// $view = $this->view();
|
|
|
|
// 'object_name' => $view->translate('Object name')
|
|
|
|
return array_combine($cols, $cols);
|
2015-07-26 15:39:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function fetchData()
|
|
|
|
{
|
2015-12-02 04:23:00 +01:00
|
|
|
$query = $this->getBaseQuery()->columns($this->getColumns());
|
2015-07-26 15:39:37 +02:00
|
|
|
|
|
|
|
if ($this->hasLimit() || $this->hasOffset()) {
|
|
|
|
$query->limit($this->getLimit(), $this->getOffset());
|
|
|
|
}
|
|
|
|
|
2015-12-02 04:23:00 +01:00
|
|
|
// TODO: move to dedicated method in parent class
|
|
|
|
$filter = null;
|
|
|
|
$enforced = $this->enforcedFilters;
|
|
|
|
if ($this->filter && ! $this->filter->isEmpty()) {
|
|
|
|
$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 $query->fetchAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function count()
|
|
|
|
{
|
|
|
|
return $this->getBaseQuery()->count();
|
2015-07-26 15:39:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getBaseQuery()
|
|
|
|
{
|
2015-12-02 04:23:00 +01:00
|
|
|
return (new ArrayDatasource(
|
|
|
|
$this->connection()->fetchImportedRowsetRows(
|
|
|
|
$this->checksum,
|
|
|
|
null
|
|
|
|
)
|
|
|
|
))->select()->order('object_name');
|
2015-07-26 15:39:37 +02:00
|
|
|
return $this->connection()->createImportedRowsetRowsQuery(
|
|
|
|
$this->checksum
|
|
|
|
)->order('object_name');
|
|
|
|
}
|
|
|
|
}
|