2015-06-29 15:40:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Icinga\Data\ResourceFactory;
|
2015-06-30 11:27:32 +02:00
|
|
|
use Icinga\Forms\ConfigForm;
|
|
|
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
2015-06-29 15:40:24 +02:00
|
|
|
|
|
|
|
class Director_SettingsController extends ActionController
|
|
|
|
{
|
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
$this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
|
|
|
|
|
|
|
|
$resource = $this->Config()->get('db', 'resource');
|
|
|
|
|
|
|
|
$form = new ConfigForm();
|
|
|
|
|
|
|
|
$form->setIniConfig($this->Config('config'));
|
|
|
|
$form->addElement('select', 'resource', array(
|
|
|
|
'required' => true,
|
|
|
|
'label' => $this->translate('DB Resource'),
|
2015-06-29 16:05:12 +02:00
|
|
|
'multiOptions' => array(null => $this->translate('- please choose -')) + $this->getResources(),
|
2015-06-29 15:40:24 +02:00
|
|
|
'value' => $resource
|
|
|
|
));
|
|
|
|
$form->setSubmitLabel($this->translate('Save'));
|
|
|
|
|
|
|
|
$form->setOnSuccess(function($form) {
|
|
|
|
/** @var $form ConfigForm */
|
|
|
|
$this->Config('config')->setSection('db', array(
|
|
|
|
'resource' => $form->getValue('resource')
|
|
|
|
));
|
|
|
|
$form->save();
|
|
|
|
});
|
|
|
|
|
|
|
|
$form->handleRequest();
|
|
|
|
|
|
|
|
$this->view->form = $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getResources()
|
|
|
|
{
|
|
|
|
$resources = array();
|
|
|
|
foreach (ResourceFactory::getResourceConfigs() as $name => $resource) {
|
|
|
|
if ($resource->type === 'db') {
|
|
|
|
$resources['ido'][$name] = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $resources;
|
|
|
|
}
|
|
|
|
}
|