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\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
|
|
|
{
|
2014-03-07 18:02:43 +01:00
|
|
|
$this->getTabs()->activate('general');
|
2014-07-21 10:20:04 +02:00
|
|
|
|
|
|
|
$form = new GeneralForm();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->isPost()) {
|
|
|
|
if ($form->isValid($request->getPost())) {
|
|
|
|
try {
|
|
|
|
$this->savePreferences($form->getPreferences()->toArray());
|
|
|
|
Notification::success($this->translate('Preferences updated successfully'));
|
|
|
|
$this->redirectNow('preference');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
Notification::error(
|
|
|
|
sprintf(
|
|
|
|
$this->translate('Failed to persist preferences. (%s)'),
|
|
|
|
$e->getMessage()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2013-08-19 20:00:55 +02:00
|
|
|
}
|
2014-07-21 10:20:04 +02:00
|
|
|
} else {
|
|
|
|
$form->setPreferences($request->getUser()->getPreferences());
|
2013-08-19 20:00:55 +02:00
|
|
|
}
|
2014-07-21 10:20:04 +02:00
|
|
|
|
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
|
|
|
}
|