2016-10-13 05:13:21 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
2016-10-20 00:29:23 -04:00
|
|
|
use Icinga\Module\Director\Objects\IcingaHost;
|
|
|
|
|
use Icinga\Module\Director\Objects\IcingaService;
|
2016-10-13 05:13:21 -04:00
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
|
|
|
|
|
|
class IcingaServiceSetForm extends DirectorObjectForm
|
|
|
|
|
{
|
|
|
|
|
protected $host;
|
|
|
|
|
|
|
|
|
|
public function setup()
|
|
|
|
|
{
|
2016-10-20 03:22:56 -04:00
|
|
|
if ($this->host === null) {
|
|
|
|
|
$this->setupTemplate();
|
|
|
|
|
} else {
|
|
|
|
|
$this->setupHost();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->setupFields()
|
|
|
|
|
->setButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function setupFields()
|
|
|
|
|
{
|
|
|
|
|
$object = $this->object();
|
2016-10-13 05:13:21 -04:00
|
|
|
|
2016-10-20 03:22:56 -04:00
|
|
|
$this->assertResolvedImports();
|
|
|
|
|
|
|
|
|
|
if ($this->hasBeenSent() && $services = $this->getSentValue('service')) {
|
|
|
|
|
$object->service = $services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->assertResolvedImports()) {
|
|
|
|
|
$this->fieldLoader($object)
|
|
|
|
|
->loadFieldsForMultipleObjects($object->getServiceObjects());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function setupTemplate()
|
|
|
|
|
{
|
2016-10-13 05:13:21 -04:00
|
|
|
$this->addElement('text', 'object_name', array(
|
|
|
|
|
'label' => $this->translate('Service set name'),
|
|
|
|
|
'description' => $this->translate(
|
2016-10-19 22:56:19 -04:00
|
|
|
'A short name identifying this set of services'
|
2016-10-13 05:13:21 -04:00
|
|
|
),
|
|
|
|
|
'required' => true,
|
|
|
|
|
));
|
2016-10-20 03:22:56 -04:00
|
|
|
|
|
|
|
|
$this->addHidden('object_type', 'template');
|
|
|
|
|
$this->addDescriptionElement();
|
|
|
|
|
|
|
|
|
|
$this->addElement('multiselect', 'service', array(
|
|
|
|
|
'label' => $this->translate('Services'),
|
|
|
|
|
'description' => $this->translate(
|
|
|
|
|
'Services in this set'
|
2016-10-13 05:13:21 -04:00
|
|
|
),
|
2016-10-20 03:22:56 -04:00
|
|
|
'rows' => '5',
|
|
|
|
|
'multiOptions' => $this->enumServices(),
|
|
|
|
|
'required' => true,
|
|
|
|
|
'class' => 'autosubmit',
|
2016-10-13 05:13:21 -04:00
|
|
|
));
|
2016-10-20 03:22:56 -04:00
|
|
|
}
|
2016-10-13 05:13:21 -04:00
|
|
|
|
2016-10-20 03:22:56 -04:00
|
|
|
protected function setupHost()
|
|
|
|
|
{
|
|
|
|
|
$object = $this->object();
|
|
|
|
|
if ($this->hasBeenSent()) {
|
|
|
|
|
$object->object_name = $object->imports = $this->getSentValue('imports');
|
2016-10-13 05:13:21 -04:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 03:22:56 -04:00
|
|
|
if (! $object->hasBeenLoadedFromDb()) {
|
|
|
|
|
$this->addSingleImportsElement();
|
2016-10-20 00:29:23 -04:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 03:22:56 -04:00
|
|
|
if (count($object->imports)) {
|
|
|
|
|
$this->addHtmlHint(
|
|
|
|
|
$this->getView()->escape(
|
|
|
|
|
$object->getResolvedProperty('description')
|
|
|
|
|
)
|
|
|
|
|
);
|
2016-10-20 00:29:23 -04:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 03:22:56 -04:00
|
|
|
$this->addHidden('object_type', 'object');
|
|
|
|
|
$this->addHidden('host_id', $this->host->id);
|
2016-10-13 05:13:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setHost(IcingaHost $host)
|
|
|
|
|
{
|
|
|
|
|
$this->host = $host;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2016-10-20 03:22:56 -04:00
|
|
|
protected function addSingleImportsElement()
|
|
|
|
|
{
|
|
|
|
|
$enum = $this->enumAllowedTemplates();
|
|
|
|
|
|
|
|
|
|
$this->addElement('select', 'imports', array(
|
|
|
|
|
'label' => $this->translate('Service set'),
|
|
|
|
|
'description' => $this->translate(
|
|
|
|
|
'The service set that should be assigned to this host'
|
|
|
|
|
),
|
|
|
|
|
'required' => true,
|
|
|
|
|
'multiOptions' => $this->optionallyAddFromEnum($enum),
|
|
|
|
|
'class' => 'autosubmit'
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function addDescriptionElement()
|
|
|
|
|
{
|
|
|
|
|
$this->addElement('textarea', 'description', array(
|
|
|
|
|
'label' => $this->translate('Description'),
|
|
|
|
|
'description' => $this->translate(
|
|
|
|
|
'A meaningful description explaining your users what to expect'
|
|
|
|
|
. ' when assigning this set of services'
|
|
|
|
|
),
|
|
|
|
|
'rows' => '3',
|
|
|
|
|
'required' => ! $this->isTemplate(),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2016-10-13 05:13:21 -04:00
|
|
|
|
|
|
|
|
protected function enumServices()
|
|
|
|
|
{
|
|
|
|
|
$db = $this->db->getDbAdapter();
|
|
|
|
|
$query = $db->select()
|
|
|
|
|
->from('icinga_service', 'object_name')
|
2016-10-20 00:29:23 -04:00
|
|
|
->where('object_type = ?', 'template')
|
|
|
|
|
->order('object_name');
|
2016-10-13 05:13:21 -04:00
|
|
|
$names = $db->fetchCol($query);
|
|
|
|
|
|
|
|
|
|
return array_combine($names, $names);
|
|
|
|
|
}
|
|
|
|
|
}
|