Save the setting passed in $data

@param string $data The setting to save
@return string empty or error message
767764
public function write_setting($data) {
        global $CFG;
        // do not change active CFG setting!
        $current = $CFG->{$this->name};
        $result = parent::write_setting($data);
        $CFG->{$this->name} = $current;
        return $result;
    }
160374
public function encode($data)
    {
        if ($data !== null) {
            $data = gzencode((string) $data, $this->options['level'], $this->options['mode']);
            if ($data === false) {
                $data = null;
                $this->error = error_get_last()['message'] ?? 'Unknown';
            }
        }

        return $data;
    }
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');
    }
586222
public function put($data)
    {
        $this->data = array_merge($this->data, $data);
        return $this->save();
    }
1340394
public function save($data = [])
    {
        if (!$data || count($data) == 0) {
            $data = $_POST;
        }
        $data += [
            'qsID' => null,
            'oldQsID' => null,
            'questions' => [],
        ];

        $b = $this->getBlockObject();
        $c = $b->getBlockCollectionObject();

        $db = Database::connection();
        if (intval($this->bID) > 0) {
            $q = "select count(*) as total from {$this->btTable} where bID = " . intval($this->bID);
            $total = $db->getOne($q);
        } else {
            $total = 0;
        }

        if (isset($_POST['qsID']) && $_POST['qsID']) {
            $data['qsID'] = $_POST['qsID'];
        }
        if (!$data['qsID']) {
            $data['qsID'] = time();
        }

        if (isset($data['questionSetId'])) {
            // This is specifically set when using the migration tool
            $data['qsID'] = $data['questionSetId'];
        }

        if (!$data['oldQsID']) {
            $data['oldQsID'] = $data['qsID'];
        }
        $data['bID'] = intval($this->bID);

        if (!empty($data['redirectCID'])) {
            $data['redirect'] = 1;
        } else {
            $data['redirect'] = 0;
            $data['redirectCID'] = 0;
        }

        if (empty($data['addFilesToSet'])) {
            $data['addFilesToSet'] = 0;
        }

        if (!isset($data['surveyName'])) {
            $data['surveyName'] = '';
        }

        if (!isset($data['submitText'])) {
            $data['submitText'] = '';
        }

        if (!isset($data['notifyMeOnSubmission'])) {
            $data['notifyMeOnSubmission'] = 0;
        }

        if (!isset($data['thankyouMsg'])) {
            $data['thankyouMsg'] = '';
        }

        if (!isset($data['displayCaptcha'])) {
            $data['displayCaptcha'] = 0;
        }

        $v = [$data['qsID'], $data['surveyName'], $data['submitText'], intval($data['notifyMeOnSubmission']), $data['recipientEmail'], $data['thankyouMsg'], intval($data['displayCaptcha']), intval($data['redirectCID']), intval($data['addFilesToSet']), intval($this->bID)];

        //is it new?
        if (intval($total) == 0) {
            $q = "insert into {$this->btTable} (questionSetId, surveyName, submitText, notifyMeOnSubmission, recipientEmail, thankyouMsg, displayCaptcha, redirectCID, addFilesToSet, bID) values (?, ?, ?, ?, ?, ?, ?, ?, ?,?)";
        } else {
            $v[] = $data['qsID'];
            $q = "update {$this->btTable} set questionSetId = ?, surveyName=?, submitText=?, notifyMeOnSubmission=?, recipientEmail=?, thankyouMsg=?, displayCaptcha=?, redirectCID=?, addFilesToSet=? where bID = ? AND questionSetId= ?";
        }

        $rs = $db->query($q, $v);

        //Add Questions (for programmatically creating forms, such as during the site install)
        if (count($data['questions']) > 0) {
            $miniSurvey = new MiniSurvey();
            foreach ($data['questions'] as $questionData) {
                $miniSurvey->addEditQuestion($questionData, 0);
            }
        }

        $this->questionVersioning($data);

        return true;
    }
1092268
public function send($data = null): ?MailSettings
    {
        try {
            $settings = $this->createSettings($data);

            $settings->hasRequiredSettings();

            $this->mailer->send(
                $this->createMailable($settings)
            );
        } catch (\Exception $e) {
            Log::error($e);

            $env = $this->config->get('app.env', 'production');

            if (!in_array($env, ['production', 'prod', 'live'])) {
                throw $e;
            }
        }

        return $settings ?? null;
    }
337460
public function store($data)
    {
        $modelName = $this->modelFullName;
        if($this->validate($data, $modelName::$rules))
        {
            $model = $modelName::create($data);
            return $model;
        }
    }
444953
public function setData(&$data)
    {
        /**
         * @var Cell\Cell $cell
         */
        foreach ($this->cells as $cell) {
            $cell->setData($data);
        }
        return $this;
    }
1291467
public function save($data)
    {
        if ($data instanceof Model) {
            $data = $data->getData();
        }
        // 保存关联表数据
        $pk = $this->parent->getPk();

        $model = new $this->model;

        $data[$this->morphKey]  = $this->parent->$pk;
        $data[$this->morphType] = $this->type;
        return $model->save($data) ? $model : false;
    }
624988
public function save($data = null)
    {
        if ($data !== null) {
            $this->data = $data;
        }

        return $this->getHandler()->renderPath($this->getPath(), $this->data);
    }
982982
public function save($data)
    {
        $argv = compact('data');
        $argv = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_PRE_SAVE, $this, $argv);

        $data = $argv['data'];

        if ($data instanceof ModelInterface) {
            $data = $this->getHydrator()->extract($data);
        }

        $pk = $this->getMapper()->getPrimaryKey();
        $id = $data[$pk];
        unset($data[$pk]);

        if (0 === $id || null === $id || '' === $id) {
            $result = $this->getMapper()->insert($data);
            $this->clearCacheTags();
        } else {
            if ($this->getById($id)) {
                $result = $this->getMapper()->update($data, [$pk => $id]);
            } else {
                throw new ServiceException('ID ' . $id . ' does not exist');
            }

            $this->removeCacheItem($id);
        }

        $argv = compact('data', 'result');
        $argv = $this->prepareEventArguments($argv);

        $this->getEventManager()->trigger(self::EVENT_POST_SAVE, $this, $argv);

        return $result;
    }
1225715
public static function save($data)
	{
		$instance = self::getInstance();

		// Merge and make sure values are unique
		$data = $instance->merge($instance->config->toArray(), $data);
		$data = $instance->unique($data);

		// Set data back to the instance
		$instance->config = new Registry($data);

		// Actually write out the data
		$instance->write();

		return true;
	}
1347890
public function setData($data)
    {
        // Format data
        $data = $this->format($data, $this->_format);
        // CI Output
        $this->ci->output->set_output($data);

        return $this;
    }
255363
public function setData($data)
    {
      if(!is_string($data) && strlen(trim($data)) == 0)
        throw new InvalidArgumentException(__METHOD__ . '; Invalid data, must be a non empty string');

      $this->data = $data;
    }
1166199
public function set_data( $data ) {
		if ( isset( $data[ $this->slug ] ) ) {
			if ( is_string( $data[ $this->slug ] ) ) {
				$is_json = json_decode( $data[ $this->slug ], ARRAY_A );
				if ( ! empty( $is_json ) ) {
					$data[ $this->slug ] = $is_json;
				} else {
					$data[ $this->slug ] = str_replace( '{{@root', '{{json @root', $data[ $this->slug ] );
				}
			}
			$this->data[ $this->id() ][ $this->slug ] = apply_filters( 'uix_' . $this->slug . '_sanitize_' . $this->type, $data[ $this->slug ], $this );
		}

	}
964373
public function write_setting($data) {
        global $CFG;

        $value  = $data['value'];
        $forced = empty($data['forced']) ? 0 : 1;
        $adv    = empty($data['adv'])    ? 0 : 2;
        $flag   = ($forced | $adv); //bitwise or

        if (!in_array($value, array_keys($this->choices))) {
            return 'Error setting ';
        }

        $oldvalue  = $this->config_read($this->name);
        $oldflag   = (int)$this->config_read($this->name.'_flag');
        $oldforced = (1 & $oldflag); // first bit

        $result1 = $this->config_write($this->name, $value);
        $result2 = $this->config_write($this->name.'_flag', $flag);

        // force regrade if needed
        if ($oldforced != $forced or ($forced and $value != $oldvalue)) {
            require_once($CFG->libdir.'/gradelib.php');
            grade_category::updated_forced_settings();
        }

        if ($result1 and $result2) {
            return '';
        } else {
            return get_string('errorsetting', 'admin');
        }
    }
358871
public function setData($data)
    {
        foreach ($data as $name => $value) {
            if ($this->has($name)) {
                $this->get($name)->setValue($value);
            }
        }
        return $this;
    }