* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team * */ // {{{ICINGA_LICENSE_HEADER}}} 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; /** * Application wide preference controller for user preferences */ class PreferenceController extends BasePreferenceController { /** * Create tabs for this preference controller * * @return array * * @see BasePreferenceController::createProvidedTabs() */ public static function createProvidedTabs() { return array( 'preference' => new Tab( array( 'name' => 'general', 'title' => 'General settings', 'url' => Url::fromPath('/preference') ) ) ); } /** * General settings for date and time */ public function indexAction() { $form = new GeneralForm(); $form->setConfiguration(IcingaConfig::app()); $form->setRequest($this->getRequest()); if ($form->isSubmittedAndValid()) { $preferences = $form->getPreferences(); $userPreferences = $this->getRequest()->getUser()->getPreferences(); $userPreferences->startTransaction(); foreach ($preferences as $key => $value) { if (!$value) { $userPreferences->remove($key); } else { $userPreferences->set($key, $value); } } try { $userPreferences->commit(); $this->view->successMessage = "Preferences Updated Successfully"; // recreate form to show new values $form = new GeneralForm(); $form->setConfiguration(IcingaConfig::app()); $form->setRequest($this->getRequest()); } catch (Exception $e) { $this->view->exceptionMessage = $e->getMessage(); } } $this->view->form = $form; } } // @codingStandardsIgnoreEnd