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