2015-06-30 11:19:31 +02:00
|
|
|
<?php
|
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
2015-06-30 11:19:31 +02:00
|
|
|
use Icinga\Module\Director\Web\Controller\ObjectController;
|
2015-12-10 12:52:10 +01:00
|
|
|
use Icinga\Module\Director\Objects\IcingaService;
|
|
|
|
use Icinga\Module\Director\Objects\IcingaHost;
|
2015-06-30 11:19:31 +02:00
|
|
|
|
2015-10-20 22:34:04 +02:00
|
|
|
class ServiceController extends ObjectController
|
2015-06-30 11:19:31 +02:00
|
|
|
{
|
2016-03-18 13:10:08 +01:00
|
|
|
protected $host;
|
|
|
|
|
|
|
|
protected function beforeTabs()
|
|
|
|
{
|
|
|
|
if ($this->host) {
|
|
|
|
$this->getTabs()->add('host', array(
|
|
|
|
'url' => 'director/host',
|
|
|
|
'urlParams' => array('name' => $this->host->object_name),
|
|
|
|
'label' => $this->translate('Host'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 23:58:06 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2016-03-18 13:10:08 +01:00
|
|
|
if ($host = $this->params->get('host')) {
|
|
|
|
$this->host = IcingaHost::load($host, $this->db());
|
|
|
|
}
|
|
|
|
|
2015-10-15 23:58:06 +02:00
|
|
|
parent::init();
|
2016-03-18 13:10:08 +01:00
|
|
|
|
2016-02-24 21:40:46 +01:00
|
|
|
if ($this->object && $this->object->object_type === 'apply') {
|
2015-10-15 23:58:06 +02:00
|
|
|
$this->getTabs()->add('assign', array(
|
2016-03-07 08:16:20 +01:00
|
|
|
'url' => 'director/service/assign',
|
|
|
|
'urlParams' => $this->object->getUrlParams(),
|
2016-03-18 13:10:08 +01:00
|
|
|
'label' => $this->translate('Assign')
|
2015-10-15 23:58:06 +02:00
|
|
|
));
|
2015-12-10 12:52:10 +01:00
|
|
|
|
2016-03-18 13:10:08 +01:00
|
|
|
if ($this->host) {
|
2015-12-10 12:52:10 +01:00
|
|
|
foreach ($this->getTabs()->getTabs() as $tab) {
|
2016-03-18 13:10:08 +01:00
|
|
|
$tab->getUrl()->setParam('host', $this->host->object_name);
|
2015-12-10 12:52:10 +01:00
|
|
|
}
|
|
|
|
}
|
2015-10-15 23:58:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function assignAction()
|
|
|
|
{
|
|
|
|
$this->getTabs()->activate('assign');
|
2016-03-18 13:10:08 +01:00
|
|
|
$this->view->form = $form = $this->loadForm('icingaServiceAssignment');
|
2015-10-15 23:58:06 +02:00
|
|
|
$form
|
|
|
|
->setIcingaObject($this->object)
|
2016-03-18 13:10:08 +01:00
|
|
|
->setDb($this->db());
|
|
|
|
if ($id = $this->params->get('rule_id')) {
|
|
|
|
$this->view->actionLinks = $this->view->qlink(
|
|
|
|
$this->translate('back'),
|
|
|
|
$this->getRequest()->getUrl()->without('rule_id'),
|
|
|
|
null,
|
|
|
|
array('class' => 'icon-left-big')
|
|
|
|
);
|
|
|
|
$form->loadObject($id);
|
|
|
|
}
|
|
|
|
$form->handleRequest();
|
2015-11-26 20:36:13 +01:00
|
|
|
|
|
|
|
$this->view->table = $this->loadTable('icingaObjectAssignment')
|
|
|
|
->setObject($this->object);
|
2016-03-18 13:10:08 +01:00
|
|
|
|
2015-10-15 23:58:06 +02:00
|
|
|
$this->view->title = 'Assign service to host';
|
2015-11-26 20:36:13 +01:00
|
|
|
$this->render('object/fields', null, true); // TODO: render table
|
2015-10-15 23:58:06 +02:00
|
|
|
}
|
2015-12-10 12:52:10 +01:00
|
|
|
|
2016-03-18 13:10:08 +01:00
|
|
|
public function loadForm($name)
|
|
|
|
{
|
|
|
|
$form = parent::loadForm($name);
|
|
|
|
if ($name === 'icingaService' && $this->host) {
|
|
|
|
$form->setHost($this->host);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
2015-12-10 12:52:10 +01:00
|
|
|
protected function loadObject()
|
|
|
|
{
|
2016-03-06 14:26:48 +01:00
|
|
|
if ($this->object === null) {
|
|
|
|
if ($name = $this->params->get('name')) {
|
|
|
|
$params = array('object_name' => $name);
|
|
|
|
$db = $this->db();
|
2015-12-10 12:52:10 +01:00
|
|
|
|
2016-03-18 13:10:08 +01:00
|
|
|
if ($this->host) {
|
|
|
|
$this->view->host = $this->host;
|
|
|
|
$params['host_id'] = $this->host->id;
|
2016-03-06 14:26:48 +01:00
|
|
|
}
|
2015-12-10 12:52:10 +01:00
|
|
|
|
2016-03-06 14:26:48 +01:00
|
|
|
$this->object = IcingaService::load($params, $db);
|
|
|
|
} else {
|
|
|
|
parent::loadObject();
|
|
|
|
}
|
2015-12-10 12:52:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->object;
|
|
|
|
}
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|