ApplRulesTable: allowto link with names

This commit is contained in:
Thomas Gelf 2019-04-10 17:19:46 +02:00
parent 5a36735400
commit 54b62c7179
2 changed files with 34 additions and 3 deletions

View File

@ -13,6 +13,17 @@ class ScheduledDowntimesController extends ObjectsController
return $res;
}
protected function getTable()
{
return parent::getTable()
->setBaseObjectUrl('director/scheduled-downtime');
}
protected function getApplyRulesTable()
{
return parent::getApplyRulesTable()->createLinksWithNames();
}
public function getType()
{
return 'scheduledDowntime';

View File

@ -30,6 +30,8 @@ class ApplyRulesTable extends ZfQueryBasedTable
protected $baseObjectUrl;
protected $linkWithName = false;
public static function create($type, Db $db)
{
$table = new static($db);
@ -51,6 +53,13 @@ class ApplyRulesTable extends ZfQueryBasedTable
return $this;
}
public function createLinksWithNames($linksWithName = true)
{
$this->linkWithName = (bool) $linksWithName;
return $this;
}
public function getType()
{
return $this->type;
@ -63,9 +72,12 @@ class ApplyRulesTable extends ZfQueryBasedTable
public function renderRow($row)
{
$url = Url::fromPath("director/{$this->type}/edit", [
'id' => $row->id,
]);
if ($this->linkWithName) {
$params = ['name' => $row->object_name];
} else {
$params = ['id' => $row->id];
}
$url = Url::fromPath("director/{$this->baseObjectUrl}/edit", $params);
$tr = static::tr([
static::td(Link::create($row->object_name, $url)),
@ -80,6 +92,14 @@ class ApplyRulesTable extends ZfQueryBasedTable
return $tr;
}
/**
* Should be triggered from renderRow, still unused.
*
* @param IcingaObject $template
* @param string $inheritance
* @return $this
* @throws \Icinga\Exception\ProgrammingError
*/
public function filterTemplate(
IcingaObject $template,
$inheritance = IcingaObjectFilterHelper::INHERIT_DIRECT