IcingaObjectDatafieldTable: move and base on new

...SimpleQueryBased table
This commit is contained in:
Thomas Gelf 2017-08-13 13:38:35 +02:00
parent 38ebf2dd2d
commit e5305cb049

View File

@ -1,25 +1,25 @@
<?php
namespace Icinga\Module\Director\Tables;
namespace Icinga\Module\Director\Web\Table;
use Icinga\Data\DataArray\ArrayDatasource;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Web\Form\IcingaObjectFieldLoader;
use Icinga\Module\Director\Web\Table\QuickTable;
use Icinga\Web\Url;
use ipl\Html\Link;
use ipl\Web\Table\SimpleQueryBasedTable;
class IcingaObjectDatafieldTable extends QuickTable
class IcingaObjectDatafieldTable extends SimpleQueryBasedTable
{
protected $object;
/** @var int */
protected $objectId;
public function setObject(IcingaObject $object)
public function __construct(IcingaObject $object)
{
$this->object = $object;
$this->objectId = (int) $object->id;
$this->setConnection($object->getConnection());
return $this;
}
@ -43,43 +43,41 @@ class IcingaObjectDatafieldTable extends QuickTable
);
}
protected function getActionUrl($row)
public function getColumnsToBeRendered()
{
if ((int) $row->object_id !== $this->objectId) {
return null;
}
return Url::fromRequest()->with('field_id', $row->id);
}
protected function getRowClasses($row)
{
if ((int) $row->object_id !== $this->objectId) {
return array('disabled');
}
}
public function getTitles()
{
$view = $this->view();
return array(
'caption' => $view->translate('Label'),
'varname' => $view->translate('Field name'),
'is_required' => $view->translate('Mandatory'),
'caption' => $this->translate('Label'),
'varname' => $this->translate('Field name'),
'is_required' => $this->translate('Mandatory'),
);
}
public function count()
public function renderRow($row)
{
return $this->getBaseQuery()->count();
$definedOnThis = (int) $row->object_id === $this->objectId;
if ($definedOnThis) {
$caption = new Link(
$row->caption,
Url::fromRequest()->with('field_id', $row->id)
);
} else {
$caption = $row->caption;
}
$row = $this::row([
$caption,
$row->varname,
$row->is_required
]);
if (! $definedOnThis) {
$row->attributes()->add('class', 'disabled');
}
return $row;
}
public function fetchData()
{
return $this->getBaseQuery()->fetchAll();
}
public function getBaseQuery()
public function prepareQuery()
{
$loader = new IcingaObjectFieldLoader($this->object);
$fields = $loader->fetchFieldDetailsForObject($this->object);