2015-07-26 15:39:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Tables;
|
|
|
|
|
2015-12-02 04:23:00 +01:00
|
|
|
use Icinga\Data\DataArray\ArrayDatasource;
|
2016-07-13 21:36:45 +02:00
|
|
|
use Icinga\Module\Director\Objects\ImportRun;
|
|
|
|
use Icinga\Module\Director\Web\Table\QuickTable;
|
2015-07-26 15:39:37 +02:00
|
|
|
|
|
|
|
class ImportedrowsTable extends QuickTable
|
|
|
|
{
|
2016-07-13 21:36:45 +02:00
|
|
|
protected $columns;
|
2015-07-26 15:39:37 +02:00
|
|
|
|
2016-07-13 21:36:45 +02:00
|
|
|
protected $importRun;
|
|
|
|
|
|
|
|
public function setImportRun(ImportRun $run)
|
2015-07-26 15:39:37 +02:00
|
|
|
{
|
2016-07-13 21:36:45 +02:00
|
|
|
$this->importRun = $run;
|
|
|
|
return $this;
|
2015-07-26 15:39:37 +02:00
|
|
|
}
|
|
|
|
|
2016-07-13 21:36:45 +02:00
|
|
|
public function setColumns($columns)
|
2015-07-26 15:39:37 +02:00
|
|
|
{
|
2016-07-13 21:36:45 +02:00
|
|
|
$this->columns = $columns;
|
2015-07-26 15:39:37 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-07-13 21:36:45 +02:00
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
if ($this->columns === null) {
|
|
|
|
$cols = $this->importRun->listColumnNames();
|
|
|
|
} else {
|
|
|
|
$cols = $this->columns;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_combine($cols, $cols);
|
|
|
|
}
|
|
|
|
|
2015-07-26 15:39:37 +02:00
|
|
|
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
|
|
|
return $query->fetchAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function count()
|
|
|
|
{
|
|
|
|
return $this->getBaseQuery()->count();
|
2015-07-26 15:39:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getBaseQuery()
|
|
|
|
{
|
2015-12-16 20:27:10 +01:00
|
|
|
$ds = new ArrayDatasource(
|
2016-07-13 21:36:45 +02:00
|
|
|
$this->importRun->fetchRows($this->columns, $this->filter)
|
2015-12-16 20:27:10 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return $ds->select()->order('object_name');
|
2015-07-26 15:39:37 +02:00
|
|
|
}
|
|
|
|
}
|