Saves the new settings

@param mixed $data
@return string empty string or error message
186632
function write_setting($data) {
        $previous = $this->get_setting();

        if ($previous === null) {
            if ($data) {
                $this->regrade_all();
            }
        } else {
            if ($data != $previous) {
                $this->regrade_all();
            }
        }
        return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
    }
25929
public function write_setting($data) {
        if (!$this->load_choices() or empty($this->choices)) {
            return '';
        }
        if (!array_key_exists($data, $this->choices)) {
            return '';
        }

        // Calling it here without checking if it is ready because we check it below and show it as a controlled case.
        $selectedprocessor = \core_analytics\manager::get_predictions_processor($data, false);
        $isready = $selectedprocessor->is_ready();
        if ($isready !== true) {
            return get_string('errorprocessornotready', 'analytics', $isready);
        }

        $currentvalue = get_config('analytics', 'predictionsprocessor');
        if (!empty($currentvalue) && $currentvalue != str_replace('\\\\', '\\', $data)) {
            // Clear all models data.
            $models = \core_analytics\manager::get_all_models();
            foreach ($models as $model) {
                $model->clear();
            }
        }

        return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
    }
494562
public function saveSnippet($data) {
        $response=CodeBank_ClientAPI::responseBase();
        
        //Ensure logged in
        if(!Permission::check('CODE_BANK_ACCESS')) {
            $response['status']='EROR';
            $response['message']=_t('CodeBankAPI.PERMISSION_DENINED', '_Permission Denied');
            
            return $response;
        }
        
        
        try {
            $snippet=Snippet::get()->byID(intval($data->id));
            if(!empty($snippet) && $snippet!==false && $snippet->ID!=0) {
                $snippet->Title=$data->title;
                $snippet->Description=$data->description;
                $snippet->Text=$data->code;
                $snippet->Tags=$data->tags;
                
                //Ensure we're not assigning to another hidden language
                if($snippet->LanguageID!=$data->language) {
                    $lang=SnippetLanguage::get()->byID(intval($data->language));
                    if(!empty($lang) && $lang!==false && $lang->ID>0) {
                        if($lang->Hidden) {
                            $response['status']='EROR';
                            $response['message']=_t('CodeBankAPI.LANGUAGE_HIDDEN', '_You cannot assign this snippet to a hidden language');
                            
                            return $response;
                        }
                    }else {
                        throw new Exception('Language not found');
                    }
                }
                
                $snippet->LanguageID=$data->language;
                $snippet->LastEditorID=Member::currentUserID();
                $snippet->PackageID=$data->packageID;
                $snippet->write();
                
                
                $response['status']='HELO';
            }else {
                $response['status']='EROR';
                $response['message']=_t('CodeBankAPI.SNIPPET_NOT_FOUND', '_Snippet not found');
            }
        }catch(Exception $e) {
            $response['status']="EROR";
            $response['message']="Internal Server error occured";
        }
        
        
        return $response;
    }
18085
public function setFormValues($data = null)
    {
        if ($data === null) {
            $data = $this->getSaveData();
        }

        /*
         * Fill the model as if it were to be saved
         */
        $this->prepareModelsToSave($this->model, $data);

        /*
         * Data set differs from model
         */
        if ($this->data !== $this->model) {
            $this->data = (object) array_merge((array) $this->data, (array) $data);
        }

        /*
         * Set field values from data source
         */
        foreach ($this->allFields as $field) {
            $field->value = $this->getFieldValue($field);
        }

        return $data;
    }
1105896
public function write_setting($data) {
    // If all is selected, remove any explicit options.
        if (in_array('$@ALL@$', $data)) {
            $data = array('$@ALL@$');
        }
        // None never needs to be written to the DB.
        if (in_array('$@NONE@$', $data)) {
            unset($data[array_search('$@NONE@$', $data)]);
        }
        return parent::write_setting($data);
    }
882609
final public function save(array $data)
    {
        return array_key_exists('id', $data) ?
            $this->update($data) :
            $this->insert($data);
    }
1163072
protected static function saveExtraParams(array $data)
    {
        $final_data = array();
        if (count($data) > 0) {
            Logger::log('Saving extra configuration parameters');
            foreach ($data as $key => $value) {
                if (null !== $value || $value !== '') {
                    $final_data[$key] = $value;
                }
            }
        }
        return $final_data;
    }
1089169
public function save($data) {
        if ($data instanceof SimplePie) {
            $data = $data->data;
        }
        $response = $this->cache->set($this->name, serialize($data));
        if ($this->options['expire']) {
            $this->cache->expire($this->name, $this->options['expire']);
        }

        return $response;
    }
520447
public function write_setting($data) {
        if ($this->paramtype === PARAM_INT and $data === '') {
            // Do not complain if '' used instead of 0.
            $data = 0;
        }

        // Try to convert any non-ascii domains to ACE prior to validation - we can't modify anything in validate!
        if (function_exists('idn_to_ascii')) {
            $data = $this->ace_encode($data);
        }

        $validated = $this->validate($data);
        if ($validated !== true) {
            return $validated;
        }
        return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
    }
448293
protected function saveReseller( $data ) {
		$reseller = array();

		// @todo Check if a known key exists before deleting and skip reading/writing option.

		// Clear out any previous reseller entries.
		delete_option( 'boldgrid_reseller' );

		// Loop through the transient data being saved.
		foreach ( $data as $key => $value ) {

			// Check the data for matching keys.
			if ( 1 === preg_match( '/^reseller_/', $key ) ) {

				// Set the reseller transient data in the reseller array.
				$reseller[ $key ] = $data->$key;
			}
		}

		// Check if reseller data was extracted from the transient being saved.
		if ( ! empty( $reseller ) ) {
			update_site_option( 'boldgrid_reseller', $reseller );
		}

		// Return back the transient data object.
		return $data;
	}
305212
public function save($data)
    {
        if (empty($data['_id'])) {
            return $this->insert($data);
        }

        $id = $data['_id'];

        unset($data['_id']);

        $bucketName = $this->db->quoteBucketName($this->name);

        $this->update($data, ["META($bucketName).id" => $id]);

        return $id;
    }
862706
public function save(array $data = [], array $dirt = [])
    {
        foreach ($dirt as $field => $data) {
            switch ($data['type']) {
                case 'created':
                    $this->createSetting($field, $data['value']);
                    break;
                case 'updated':
                    $this->updateSetting($field, $data['value']);
                    break;
                case 'deleted':
                    $this->deleteSetting($field);
                    break;
            }
        }
    }
331029
protected function createSettings($data = null): MailSettings
    {
        if (method_exists($this, 'getPayload')) {
            $data = $this->getPayload($data);
        }

        if ($data instanceof MailSettings) {
            return $data;
        }

        return new $this->settings($data);
    }
698156
public function write_setting($data) {
        global $DB, $SITE, $COURSE;
        if (!in_array($data, array_keys($this->choices))) {
            return get_string('errorsetting', 'admin');
        }
        $record = new stdClass();
        $record->id           = SITEID;
        $temp                 = $this->name;
        $record->$temp        = $data;
        $record->timemodified = time();

        course_get_format($SITE)->update_course_format_options($record);
        $DB->update_record('course', $record);

        // Reset caches.
        $SITE = $DB->get_record('course', array('id'=>$SITE->id), '*', MUST_EXIST);
        if ($SITE->id == $COURSE->id) {
            $COURSE = $SITE;
        }
        format_base::reset_course_cache($SITE->id);

        return '';

    }
379391
public function write_setting($data) {
        if ($this->paramtype === PARAM_INT and $data === '') {
            // do not complain if '' used instead of 0
            $data = 0;
        }

        // $data is a string
        $validated = $this->validate($data);
        if ($validated !== true) {
            return $validated;
        }
        if ($this->lowercase) {
            $data = core_text::strtolower($data);
        }
        if (!$this->enabled) {
            return '';
        }
        return ($this->config_write($this->name, trim($data)) ? '' : get_string('errorsetting', 'admin'));
    }
1149744
public function write_setting($data) {
        if (!is_array($data)) {
            return ''; // ignore it
        }
        if (!$this->load_choices() or empty($this->choices)) {
            return '';
        }
        unset($data['xxxxx']);
        $result = array();
        foreach ($data as $key => $value) {
            if ($value and array_key_exists($key, $this->choices)) {
                $result[] = $key;
            }
        }
        return $this->config_write($this->name, implode(',', $result)) ? '' : get_string('errorsetting', 'admin');
    }
363305
public function write_setting($data) {
        if (!$this->load_choices() or empty($this->choices)) {
            return '';
        }
        if (!array_key_exists($data, $this->choices)) {
            return ''; // ignore it
        }

        return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
    }