예제 #1
0
파일: SettingsForm.php 프로젝트: vsguts/crm
 public function saveSettings()
 {
     $settings = [];
     foreach (Setting::findAll($this->attributes()) as $setting) {
         $settings[$setting->name] = $setting;
     }
     foreach ($this->attributes() as $attribute) {
         if (!empty($settings[$attribute])) {
             if ($settings[$attribute]->value != $this->{$attribute}) {
                 $settings[$attribute]->value = $this->{$attribute};
                 $settings[$attribute]->save();
             }
         } else {
             $setting = new Setting();
             $setting->name = $attribute;
             $setting->value = $this->{$attribute};
             $setting->save();
         }
     }
     // GC
     foreach (Setting::find()->where(['not in', 'name', $this->attributes()])->all() as $setting) {
         $setting->delete();
     }
 }