2015-07-21 15:16:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
use Icinga\Web\Hook;
|
|
|
|
|
|
|
|
class ImportSourceForm extends DirectorObjectForm
|
|
|
|
{
|
|
|
|
public function setup()
|
|
|
|
{
|
|
|
|
$this->addElement('text', 'source_name', array(
|
|
|
|
'label' => $this->translate('Import source name'),
|
|
|
|
'required' => true,
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->addElement('text', 'key_column', array(
|
|
|
|
'label' => $this->translate('Key column name'),
|
|
|
|
'description' => $this->translate('This must be a column containing unique values like hostnames'),
|
|
|
|
'required' => true,
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->addElement('select', 'provider_class', array(
|
|
|
|
'label' => $this->translate('Source Type'),
|
|
|
|
'required' => true,
|
2015-08-03 13:37:43 +02:00
|
|
|
'multiOptions' => $this->optionalEnum($this->enumSourceTypes()),
|
2015-07-21 15:16:18 +02:00
|
|
|
'class' => 'autosubmit'
|
|
|
|
));
|
|
|
|
|
2015-08-03 13:37:43 +02:00
|
|
|
$this->addSettings();
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function addSettings($class = null)
|
|
|
|
{
|
2015-08-03 13:37:43 +02:00
|
|
|
if ($this->hasBeenSent()) {
|
|
|
|
$class = $this->getRequest()->getPost('provider_class');
|
2015-07-21 15:16:18 +02:00
|
|
|
} else {
|
2015-08-03 13:37:43 +02:00
|
|
|
if (! ($class = $this->object()->provider_class)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 13:37:43 +02:00
|
|
|
if (array_key_exists($class, $this->enumSourceTypes())) {
|
|
|
|
$class::addSettingsFormFields($this);
|
|
|
|
foreach ($this->object()->getSettings() as $key => $val) {
|
|
|
|
if ($el = $this->getElement($key)) {
|
|
|
|
$el->setValue($val);
|
|
|
|
}
|
2015-07-21 15:16:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function enumSourceTypes()
|
|
|
|
{
|
|
|
|
$hooks = Hook::all('Director\\ImportSource');
|
2015-08-03 13:37:43 +02:00
|
|
|
$enum = array();
|
2015-07-21 15:16:18 +02:00
|
|
|
foreach ($hooks as $hook) {
|
|
|
|
$enum[get_class($hook)] = $hook->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $enum;
|
|
|
|
}
|
|
|
|
}
|