2016-10-13 11:13:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2017-08-16 23:51:15 +02:00
|
|
|
use Icinga\Module\Director\Forms\IcingaServiceSetForm;
|
2016-10-13 11:13:21 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaHost;
|
|
|
|
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
|
|
|
use Icinga\Module\Director\Web\Controller\ObjectController;
|
2017-08-16 23:51:15 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
use Icinga\Module\Director\Web\Table\IcingaServiceSetHostTable;
|
|
|
|
use Icinga\Module\Director\Web\Table\IcingaServiceSetServiceTable;
|
2017-10-09 15:23:27 +02:00
|
|
|
use dipl\Html\Link;
|
2016-10-13 11:13:21 +02:00
|
|
|
|
|
|
|
class ServicesetController extends ObjectController
|
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
/** @var IcingaHost */
|
2016-10-13 11:13:21 +02:00
|
|
|
protected $host;
|
|
|
|
|
2017-08-16 23:51:15 +02:00
|
|
|
protected function checkDirectorPermissions()
|
|
|
|
{
|
|
|
|
$this->assertPermission('director/servicesets');
|
|
|
|
}
|
|
|
|
|
2016-10-13 11:13:21 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
if (null !== ($host = $this->params->get('host'))) {
|
2016-10-13 11:13:21 +02:00
|
|
|
$this->host = IcingaHost::load($host, $this->db());
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::init();
|
2016-10-26 01:01:18 +02:00
|
|
|
if ($this->object) {
|
2017-08-16 23:51:15 +02:00
|
|
|
$this->addServiceSetTabs();
|
2016-10-26 01:01:18 +02:00
|
|
|
}
|
2016-10-13 11:13:21 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 23:51:15 +02:00
|
|
|
protected function onObjectFormLoaded(DirectorObjectForm $form)
|
2016-10-20 09:22:08 +02:00
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
if ($this->host) {
|
|
|
|
/** @var IcingaServiceSetForm $form */
|
2016-10-20 09:22:08 +02:00
|
|
|
$form->setHost($this->host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 01:01:18 +02:00
|
|
|
public function addAction()
|
|
|
|
{
|
|
|
|
parent::addAction();
|
|
|
|
if ($this->host) {
|
2017-07-04 01:34:50 +02:00
|
|
|
$this->addTitle(
|
2016-10-26 01:01:18 +02:00
|
|
|
$this->translate('Add a service set to "%s"'),
|
2017-08-16 23:51:15 +02:00
|
|
|
$this->host->getObjectName()
|
2016-10-26 01:01:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function servicesAction()
|
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
/** @var IcingaServiceSet $set */
|
2016-10-26 01:01:18 +02:00
|
|
|
$set = $this->object;
|
2017-08-16 23:51:15 +02:00
|
|
|
$name = $set->getObjectName();
|
2017-07-04 01:34:50 +02:00
|
|
|
$this->tabs()->activate('services');
|
|
|
|
$this->addTitle(
|
2016-10-26 01:01:18 +02:00
|
|
|
$this->translate('Services in this set: %s'),
|
2017-08-16 23:51:15 +02:00
|
|
|
$name
|
2016-10-26 01:01:18 +02:00
|
|
|
);
|
2017-07-04 01:34:50 +02:00
|
|
|
$this->actions()->add(Link::create(
|
|
|
|
$this->translate('Add service'),
|
|
|
|
'director/service/add',
|
2017-08-16 23:51:15 +02:00
|
|
|
['set' => $name],
|
2017-07-04 01:34:50 +02:00
|
|
|
['class' => 'icon-plus']
|
|
|
|
));
|
|
|
|
|
2017-08-16 23:51:15 +02:00
|
|
|
IcingaServiceSetServiceTable::load($set)->renderTo($this);
|
2016-10-26 01:01:18 +02:00
|
|
|
}
|
|
|
|
|
2016-11-11 15:33:11 +01:00
|
|
|
public function hostsAction()
|
|
|
|
{
|
2017-08-16 23:51:15 +02:00
|
|
|
/** @var IcingaServiceSet $set */
|
2016-11-11 15:33:11 +01:00
|
|
|
$set = $this->object;
|
2017-07-04 01:34:50 +02:00
|
|
|
$this->tabs()->activate('hosts');
|
|
|
|
$this->addTitle(
|
2016-11-11 15:33:11 +01:00
|
|
|
$this->translate('Hosts using this set: %s'),
|
2017-08-16 23:51:15 +02:00
|
|
|
$set->getObjectName()
|
2016-11-11 15:33:11 +01:00
|
|
|
);
|
|
|
|
|
2017-08-16 23:51:15 +02:00
|
|
|
IcingaServiceSetHostTable::load($set)->renderTo($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function addServiceSetTabs()
|
|
|
|
{
|
|
|
|
$tabs = $this->tabs();
|
|
|
|
$name = $this->object->getObjectName();
|
|
|
|
$tabs->add('services', [
|
|
|
|
'url' => 'director/serviceset/services',
|
|
|
|
'urlParams' => ['name' => $name],
|
|
|
|
'label' => 'Services'
|
|
|
|
])->add('hosts', [
|
|
|
|
'url' => 'director/serviceset/hosts',
|
|
|
|
'urlParams' => ['name' => $name],
|
|
|
|
'label' => 'Hosts'
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this;
|
2016-11-11 15:33:11 +01:00
|
|
|
}
|
|
|
|
|
2016-10-13 11:13:21 +02:00
|
|
|
protected function loadObject()
|
|
|
|
{
|
|
|
|
if ($this->object === null) {
|
2017-08-16 23:51:15 +02:00
|
|
|
if (null !== ($name = $this->params->get('name'))) {
|
|
|
|
$params = ['object_name' => $name];
|
2016-10-13 11:13:21 +02:00
|
|
|
$db = $this->db();
|
|
|
|
|
|
|
|
if ($this->host) {
|
2017-08-16 23:51:15 +02:00
|
|
|
$params['host_id'] = $this->host->get('id');
|
2016-10-13 11:13:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->object = IcingaServiceSet::load($params, $db);
|
|
|
|
} else {
|
|
|
|
parent::loadObject();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->object;
|
|
|
|
}
|
|
|
|
}
|