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\Url;
|
2014-09-05 10:21:24 +02:00
|
|
|
use Icinga\Web\Widget\Tab;
|
|
|
|
use Icinga\Application\Config;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\PreferenceForm;
|
2014-09-05 10:21:24 +02:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
|
|
|
use Icinga\User\Preferences\PreferencesStore;
|
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-11-13 18:08:30 +01:00
|
|
|
'preferences' => new Tab(
|
2013-08-12 15:58:26 +02:00
|
|
|
array(
|
2014-11-13 18:08:30 +01:00
|
|
|
'title' => t('Preferences'),
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-05 10:21:24 +02:00
|
|
|
* Show form to adjust user preferences
|
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-09-05 10:21:24 +02:00
|
|
|
$storeConfig = Config::app()->preferences;
|
|
|
|
if ($storeConfig === null) {
|
|
|
|
throw new ConfigurationError(t('You need to configure how to store preferences first.'));
|
2013-08-19 20:00:55 +02:00
|
|
|
}
|
2014-07-21 10:20:04 +02:00
|
|
|
|
2014-09-05 10:21:24 +02:00
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
$form = new PreferenceForm();
|
|
|
|
$form->setPreferences($user->getPreferences());
|
|
|
|
$form->setStore(PreferencesStore::create($storeConfig, $user));
|
|
|
|
$form->handleRequest();
|
|
|
|
|
2013-08-19 20:00:55 +02:00
|
|
|
$this->view->form = $form;
|
2014-11-13 18:08:30 +01:00
|
|
|
$this->getTabs()->activate('preferences');
|
2013-06-27 12:45:18 +02:00
|
|
|
}
|
2013-08-14 12:42:32 +02:00
|
|
|
}
|