/** * Save settings. * * @param AmForms_SettingModel * * @return bool */ public function saveSettings(AmForms_SettingModel $settings) { if (!$settings->id) { return false; } $settingsRecord = AmForms_SettingRecord::model()->findById($settings->id); if (!$settingsRecord) { throw new Exception(Craft::t('No settings exists with the ID “{id}”.', array('id' => $settings->id))); } // Set attributes $properSettings = $settings->value; if (is_array($properSettings)) { $properSettings = json_encode($settings->value); } $settingsRecord->setAttributes($settings->getAttributes(), false); $settingsRecord->setAttribute('value', $properSettings); // Validate $settingsRecord->validate(); $settings->addErrors($settingsRecord->getErrors()); // Save settings if (!$settings->hasErrors()) { // Save in database return $settingsRecord->save(); } return false; }