2013-06-27 12:45:18 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-02-17 14:11:55 +01:00
|
|
|
use Icinga\Web\Controller\BasePreferenceController;
|
|
|
|
use Icinga\Web\Widget\Tab;
|
|
|
|
use Icinga\Application\Config as IcingaConfig;
|
|
|
|
use Icinga\Web\Url;
|
|
|
|
use Icinga\Form\Preference\GeneralForm;
|
2014-07-10 13:43:49 +02:00
|
|
|
use Icinga\Web\Notification;
|
2013-06-27 12:45:18 +02:00
|
|
|
|
|
|
|
/**
|
2013-08-12 15:58:26 +02:00
|
|
|
* Application wide preference controller for user preferences
|
2013-06-27 12:45:18 +02:00
|
|
|
*/
|
2013-08-12 15:58:26 +02:00
|
|
|
class PreferenceController extends BasePreferenceController
|
2013-06-27 12:45:18 +02:00
|
|
|
{
|
2013-08-12 15:58:26 +02:00
|
|
|
/**
|
2013-08-14 12:42:32 +02:00
|
|
|
* Create tabs for this preference controller
|
2013-08-12 15:58:26 +02:00
|
|
|
*
|
2013-08-16 14:56:23 +02:00
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @see BasePreferenceController::createProvidedTabs()
|
2013-08-12 15:58:26 +02:00
|
|
|
*/
|
|
|
|
public static function createProvidedTabs()
|
2013-06-27 12:45:18 +02:00
|
|
|
{
|
2013-08-12 15:58:26 +02:00
|
|
|
return array(
|
2014-03-07 18:02:43 +01:00
|
|
|
'general' => new Tab(
|
2013-08-12 15:58:26 +02:00
|
|
|
array(
|
2013-08-19 20:00:55 +02:00
|
|
|
'title' => 'General settings',
|
2013-08-16 14:56:23 +02:00
|
|
|
'url' => Url::fromPath('/preference')
|
2013-08-12 15:58:26 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2013-06-27 12:45:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-19 20:00:55 +02:00
|
|
|
* General settings for date and time
|
2013-06-27 12:45:18 +02:00
|
|
|
*/
|
2013-06-27 16:06:38 +02:00
|
|
|
public function indexAction()
|
2013-06-27 12:45:18 +02:00
|
|
|
{
|
2013-08-19 20:00:55 +02:00
|
|
|
$form = new GeneralForm();
|
2014-03-07 18:02:43 +01:00
|
|
|
$this->getTabs()->activate('general');
|
2014-02-17 14:11:55 +01:00
|
|
|
$form->setConfiguration(IcingaConfig::app())
|
|
|
|
->setRequest($this->getRequest());
|
2013-08-19 20:00:55 +02:00
|
|
|
if ($form->isSubmittedAndValid()) {
|
|
|
|
try {
|
2014-02-17 14:11:55 +01:00
|
|
|
$this->savePreferences($form->getPreferences());
|
2014-07-10 13:43:49 +02:00
|
|
|
Notification::success(t('Preferences updated successfully'));
|
2014-02-17 14:11:55 +01:00
|
|
|
// Recreate form to show new values
|
|
|
|
// TODO(el): It must sufficient to call $form->populate(...)
|
2013-08-21 09:54:40 +02:00
|
|
|
$form = new GeneralForm();
|
|
|
|
$form->setConfiguration(IcingaConfig::app());
|
|
|
|
$form->setRequest($this->getRequest());
|
2013-08-19 20:00:55 +02:00
|
|
|
} catch (Exception $e) {
|
2014-07-10 13:43:49 +02:00
|
|
|
Notification::error(sprintf(t('Failed to persist preferences. (%s)'), $e->getMessage()));
|
2013-08-19 20:00:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->view->form = $form;
|
2013-06-27 12:45:18 +02:00
|
|
|
}
|
2013-08-14 12:42:32 +02:00
|
|
|
}
|