Ejemplo n.º 1
0
 /**
  * Adjust preferences and persist them
  *
  * @see Form::onSuccess()
  */
 public function onSuccess()
 {
     $this->preferences = new Preferences($this->store ? $this->store->load() : array());
     $webPreferences = $this->preferences->get('icingaweb', array());
     foreach ($this->getValues() as $key => $value) {
         if ($value === null || $value === 'autodetect') {
             if (isset($webPreferences[$key])) {
                 unset($webPreferences[$key]);
             }
         } else {
             $webPreferences[$key] = $value;
         }
     }
     $this->preferences->icingaweb = $webPreferences;
     Session::getSession()->user->setPreferences($this->preferences);
     try {
         if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) {
             $this->save();
             Notification::success($this->translate('Preferences successfully saved'));
         } else {
             Notification::success($this->translate('Preferences successfully saved for the current session'));
         }
     } catch (Exception $e) {
         Logger::error($e);
         Notification::error($e->getMessage());
     }
 }
Ejemplo n.º 2
0
 /**
  * Adjust preferences and persist them
  *
  * @see Form::onSuccess()
  */
 public function onSuccess()
 {
     $this->preferences = new Preferences($this->store ? $this->store->load() : array());
     $oldTheme = $this->preferences->getValue('icingaweb', 'theme');
     $webPreferences = $this->preferences->get('icingaweb', array());
     foreach ($this->getValues() as $key => $value) {
         if ($value === '' || $value === 'autodetect' || $key === 'theme' && $value === Config::app()->get('themes', 'default', StyleSheet::DEFAULT_THEME)) {
             if (isset($webPreferences[$key])) {
                 unset($webPreferences[$key]);
             }
         } else {
             $webPreferences[$key] = $value;
         }
     }
     $this->preferences->icingaweb = $webPreferences;
     Session::getSession()->user->setPreferences($this->preferences);
     if (($theme = $this->getElement('theme')) !== null && ($theme = $theme->getValue()) !== $oldTheme) {
         $this->getResponse()->setReloadCss(true);
     }
     try {
         if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) {
             $this->save();
             Notification::success($this->translate('Preferences successfully saved'));
         } else {
             Notification::success($this->translate('Preferences successfully saved for the current session'));
         }
     } catch (Exception $e) {
         Logger::error($e);
         Notification::error($e->getMessage());
     }
 }
Ejemplo n.º 3
0
 /**
  * Retrieve the user's timezone
  *
  * If the user did not set a timezone, the default timezone set via config.ini is returned
  *
  * @return  DateTimeZone
  */
 public function getTimeZone()
 {
     $tz = $this->preferences->get('timezone');
     if ($tz === null) {
         $tz = date_default_timezone_get();
     }
     return new DateTimeZone($tz);
 }
Ejemplo n.º 4
0
 public function testWhetherPreferencesCanBeAccessed()
 {
     $prefs = new Preferences(array('key' => 'value'));
     $this->assertTrue($prefs->has('key'));
     $this->assertEquals('value', $prefs->get('key'));
 }