Esempio n. 1
0
 public function run()
 {
     // Temporarily disable mass assignment restrictions
     Eloquent::unguard();
     DB::table('seat_settings')->truncate();
     SeatSetting::create(array('setting' => 'app_name', 'value' => 'SeAT'));
     SeatSetting::create(array('setting' => 'color_scheme', 'value' => 'blue'));
     SeatSetting::create(array('setting' => 'thousand_seperator', 'value' => ' '));
     SeatSetting::create(array('setting' => 'decimal_seperator', 'value' => '.'));
     SeatSetting::create(array('setting' => 'required_mask', 'value' => '176693568'));
     SeatSetting::create(array('setting' => 'registration_enabled', 'value' => 'true'));
 }
Esempio n. 2
0
 public static function setSetting($setting_name, $setting_value, $user_id = null)
 {
     // We are going to take the stance that all settings
     // should have a default value configured in the
     // SettingsHelper::$seat_default array(). If
     // this is not the case, throw an
     // exception.
     if (!array_key_exists($setting_name, SettingHelper::$seat_defaults)) {
         throw new \Exception('Attempting to set a foreign setting ' . $setting_name);
     }
     // If $user_id is not null, then we can assume the
     // attempt is being made to save a user setting.
     // To try and protect ourselves a little, we
     // also check that the setting_name is in
     // the array of settings that are to be
     // considered safe for users to set
     if (!is_null($user_id)) {
         if (!in_array($setting_name, SettingHelper::$user_settings)) {
             throw new \Exception('Attempting to set a illegal setting ' . $setting_name);
         }
         // Everything seems OK, lets find the setting if
         // it already exists, and update its value
         $user_setting = \SeatUserSetting::where('user_id', \Auth::User()->id)->where('setting', $setting_name)->first();
         // Check if this is a new value
         if (!$user_setting) {
             $user_setting = new \SeatUserSetting();
         }
         $user_setting->user_id = $user_id;
         $user_setting->setting = $setting_name;
         $user_setting->value = $setting_value;
         $user_setting->save();
         // cache this value forever to save on DB calls
         $cache_key = self::getUserSettingCacheKeyPrefix(\Auth::User()->id, $setting_name);
         \Cache::forever($cache_key, $setting_value);
         // Return as we are done
         return true;
     } else {
         // Assuming $user_id was null, we can assume the
         // value should be set globally. So lets get
         // right to it.
         $global_setting = \SeatSetting::where('setting', $setting_name)->first();
         if (!$global_setting) {
             $global_setting = new \SeatSetting();
         }
         $global_setting->setting = $setting_name;
         $global_setting->value = $setting_value;
         $global_setting->save();
         // cache this value forever to save on DB calls
         $cache_key = self::getSystemSettingCacheKeyPrefix($setting_name);
         \Cache::forever($cache_key, $setting_value);
         return true;
     }
     // If we were not able to do anything useful, return
     return false;
 }