PropertymodifierTable: move and refactor

This commit is contained in:
Thomas Gelf 2017-08-16 12:32:53 +02:00
parent 578446d79c
commit a4e6d3251a
2 changed files with 76 additions and 62 deletions

View File

@ -1,62 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\QuickTable;
class PropertymodifierTable extends QuickTable
{
public function getColumns()
{
return array(
'id' => 'm.id',
'source_id' => 'm.source_id',
'source_name' => 's.source_name',
'property' => 'CASE WHEN m.description IS NULL THEN'
. ' CASE WHEN m.target_property IS NULL'
. ' THEN m.property_name'
. " ELSE m.target_property || ' <- ' || m.property_name END"
. ' ELSE'
. ' CASE WHEN m.target_property IS NULL'
. ' THEN m.property_name'
. " ELSE m.target_property || ' <- ' || m.property_name END"
. " || ': ' || m.description END",
'provider_class' => 'm.provider_class',
'priority' => 'm.priority',
'description' => 'CASE WHEN s.description IS NULL THEN s.source_name'
. " ELSE s.source_name || ': ' || s.description END",
);
}
protected function getActionUrl($row)
{
return $this->url(
'director/importsource/editmodifier',
array(
'id' => $row->id,
'source_id' => $row->source_id,
)
);
}
public function getTitles()
{
$view = $this->view();
return array(
'property' => $view->translate('Property'),
);
}
public function getBaseQuery()
{
return $this->db()->select()->from(
array('s' => 'import_source'),
array()
)->join(
array('m' => 'import_row_modifier'),
's.id = m.source_id',
array()
)->order('property')
->order('priority');
}
}

View File

@ -0,0 +1,76 @@
<?php
namespace Icinga\Module\Director\Web\Table;
use Icinga\Module\Director\Objects\ImportSource;
use ipl\Html\Link;
use ipl\Web\Table\ZfQueryBasedTable;
class PropertymodifierTable extends ZfQueryBasedTable
{
/** @var ImportSource */
protected $source;
public static function load(ImportSource $source)
{
$table = new static($source->getConnection());
$table->source = $source;
return $table;
}
protected function assemble()
{
$this->attributes()->set('data-base-target', '_self');
}
public function getColumns()
{
return array(
'id' => 'm.id',
'source_id' => 'm.source_id',
'property_name' => 'm.property_name',
'target_property' => 'm.target_property',
'description' => 'm.description',
'provider_class' => 'm.provider_class',
'priority' => 'm.priority',
);
}
public function renderRow($row)
{
$caption = $row->property_name;
if ($row->target_property !== null) {
$caption .= ' -> ' . $row->target_property;
}
if ($row->description !== null) {
$caption .= ': ' . $row->description;
}
return $this::row([
Link::create(
$caption,
'director/importsource/editmodifier',
[
'id' => $row->id,
'source_id' => $row->source_id,
]
)
]);
}
public function getColumnsToBeRendered()
{
return [
$this->translate('Property'),
];
}
public function prepareQuery()
{
return $this->db()->select()->from(
['m' => 'import_row_modifier'],
$this->getColumns()
)->where('m.source_id = ?', $this->source->getId())
->order('priority');
}
}