icingaweb2-module-director/application/controllers/HostsController.php

112 lines
3.3 KiB
PHP
Raw Normal View History

<?php
2015-10-20 22:34:04 +02:00
namespace Icinga\Module\Director\Controllers;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filter\FilterChain;
use Icinga\Data\Filter\FilterExpression;
use Icinga\Module\Director\Forms\IcingaAddServiceForm;
use Icinga\Module\Director\Forms\IcingaAddServiceSetForm;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Web\Controller\ObjectsController;
2017-10-09 15:23:27 +02:00
use dipl\Html\Link;
2015-10-20 22:34:04 +02:00
class HostsController extends ObjectsController
{
protected $multiEdit = array(
'imports',
'groups',
'disabled'
);
protected function checkDirectorPermissions()
{
$this->assertPermission('director/hosts');
}
public function editAction()
{
$url = clone($this->getRequest()->getUrl());
$url->setPath('director/hosts/addservice');
$urlSet = clone($url);
$urlSet->setPath('director/hosts/addserviceset');
parent::editAction();
$this->actions()->add(Link::create(
$this->translate('Add Service'),
$url,
null,
['class' => 'icon-plus']
))->add(Link::create(
$this->translate('Add Service Set'),
$urlSet,
null,
['class' => 'icon-plus']
));
}
public function addserviceAction()
{
$this->addSingleTab($this->translate('Add Service'));
$filter = Filter::fromQueryString($this->params->toString());
$objects = array();
$db = $this->db();
/** @var $filter FilterChain */
foreach ($filter->filters() as $sub) {
/** @var $sub FilterChain */
foreach ($sub->filters() as $ex) {
/** @var $ex FilterChain|FilterExpression */
if ($ex->isExpression() && $ex->getColumn() === 'name') {
$name = $ex->getExpression();
$objects[$name] = IcingaHost::load($name, $db);
}
}
}
$this->addTitle(
$this->translate('Add service to %d hosts'),
count($objects)
);
2017-07-13 17:02:32 +02:00
$this->content()->add(
IcingaAddServiceForm::load()
2017-07-13 17:02:32 +02:00
->setHosts($objects)
->setDb($this->db())
->handleRequest()
);
}
public function addservicesetAction()
{
$this->addSingleTab($this->translate('Add Service Set'));
$filter = Filter::fromQueryString($this->params->toString());
$objects = array();
$db = $this->db();
/** @var $filter FilterChain */
foreach ($filter->filters() as $sub) {
/** @var $sub FilterChain */
foreach ($sub->filters() as $ex) {
/** @var $ex FilterChain|FilterExpression */
if ($ex->isExpression() && $ex->getColumn() === 'name') {
$name = $ex->getExpression();
$objects[$name] = IcingaHost::load($name, $db);
}
}
}
$this->addTitle(
$this->translate('Add Service Set to %d hosts'),
count($objects)
);
$this->content()->add(
IcingaAddServiceSetForm::load()
->setHosts($objects)
->setDb($this->db())
->handleRequest()
);
}
}