Processes a message processor config form.

@param  int $userid the user id
@param  string $name the name of the processor
@param  array $formvalues the form values
@return external_description
@throws moodle_exception
@since 3.2
964546
public static function message_processor_config_form($userid, $name, $formvalues) {
        global $USER, $CFG;

        // Check if messaging is enabled.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $params = self::validate_parameters(
            self::message_processor_config_form_parameters(),
            array(
                'userid' => $userid,
                'name' => $name,
                'formvalues' => $formvalues,
            )
        );

        $user = self::validate_preferences_permissions($params['userid']);

        $processor = get_message_processor($params['name']);
        $preferences = [];
        $form = new stdClass();

        foreach ($params['formvalues'] as $formvalue) {
            // Curly braces to ensure interpretation is consistent between
            // php 5 and php 7.
            $form->{$formvalue['name']} = $formvalue['value'];
        }

        $processor->process_form($form, $preferences);

        if (!empty($preferences)) {
            set_user_preferences($preferences, $params['userid']);
        }
    }
1039821
private function setSuccessfulControlValues(array $formValues, $fields)
    {
        foreach ($fields as $key => $values) {
            if (isset($formValues[$key])) {
                if ($values['type'] === 'float') {
                    // We allow ',' and '.' as decimal point and need '.' internally
                    $formValues[$key] = str_replace(',', '.', $formValues[$key]);
                }
            } else {
                if ($values['type'] === 'select' && isset($values['multiple']) && $values['multiple'] === true) {
                    $formValues[$key] = [];
                } elseif ($values['type'] === 'checkbox') {
                    $formValues[$key] = 0;
                } elseif ($values['type'] === 'repeater' || $values['type'] === 'block') {
                    $formValues[$key] = [];
                }
            }
        }

        return $formValues;
    }
243646
public function alterFormValues(array $formValues)
    {
        foreach ($this->getMeta() as $key => $fieldMeta) {
            /** @var \stdClass $fieldMeta */
            if ($fieldMeta->type === 'checkbox') {
                if (isset($formValues[$key])) {
                    $prestaShopName = $fieldMeta->collection . '_' . $key;
                    $formValues[$prestaShopName] = $formValues[$key];
                }
            }
        }
        return $formValues;
    }
768117
public static function export_user_preferences(int $userid) {

        $perpage = get_user_preferences('workshop_perpage', null, $userid);

        if ($perpage !== null) {
            writer::export_user_preference('mod_workshop', 'workshop_perpage', $perpage,
                get_string('privacy:metadata:preference:perpage', 'mod_workshop'));
        }
    }
135142
public function onSubmit(FormRuntime $formRuntime, &$elementValue)
    {
        $fileTypeValidator = new FileTypeValidator(array('allowedExtensions' => $this->properties['allowedExtensions']));
        $this->addValidator($fileTypeValidator);
    }
335104
public static function export_user_preferences(int $userid) {

        $preference = get_user_preferences('filemanager_recentviewmode');

        if ($preference !== null) {
            switch ($preference) {
                case 1:
                    $value = get_string('displayasicons', 'core_repository');
                    break;
                case 2:
                    $value = get_string('displayastree', 'core_repository');
                    break;
                case 3:
                    $value = get_string('displaydetails', 'core_repository');
                    break;
                default:
                    $value = $preference;
            }

            $desc = get_string('privacy:preference:filemanager_recentviewmode', 'core_form', $value);
            writer::export_user_preference('core_form', 'filemanager_recentviewmode', $preference, $desc);
        }
    }
1110085
public static function unmute_conversations(int $userid, array $conversationids) {
        global $CFG, $USER;

        // Check if messaging is enabled.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        // Validate context.
        $context = context_system::instance();
        self::validate_context($context);

        $params = ['userid' => $userid, 'conversationids' => $conversationids];
        $params = self::validate_parameters(self::unmute_conversations_parameters(), $params);

        $capability = 'moodle/site:manageallmessaging';
        if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
            throw new required_capability_exception($context, $capability, 'nopermissions', '');
        }

        foreach ($params['conversationids'] as $conversationid) {
            \core_message\api::unmute_conversation($params['userid'], $conversationid);
        }

        return [];
    }
894183
public static function export_user_preferences(int $userid) {
        $preferences = get_user_preferences(null, null, $userid);
        foreach ($preferences as $name => $value) {
            if (
                (substr($name, 0, 16) == 'message_provider') ||
                ($name == 'message_blocknoncontacts') ||
                ($name == 'message_entertosend')
            ) {
                writer::export_user_preference(
                    'core_message',
                    $name,
                    $value,
                    get_string('privacy:request:preference:set', 'core_message', (object) [
                        'name' => $name,
                        'value' => $value,
                    ])
                );
            }
        }
    }
1306320
public static function & GetById ($formId) {
		if (isset(self::$instances[$formId])) {
			return self::$instances[$formId];
		} else {
			throw new \RuntimeException(
				'No form instance exists under form id `'.$formId.'`.'
				. ' Check if searched form instance has been already initialized'
				. ' or if form id has been already set.'
			);
		}
	}
945869
public function getUserPreferenceByUserIdAndName(int $userId, string $name): UserPreference
    {
        $userPreference = $this->mapper->extractUserPreferencesFromRows(
            $this->gateway->getUserPreferenceByUserIdAndName($userId, $name)
        );

        if (count($userPreference) < 1) {
            throw new NotFoundException('User Preference', $userId . ',' . $name);
        }

        return reset($userPreference);
    }
747616
public static function get_received_contact_requests_count(int $userid) {
        global $CFG, $USER;

        // Check if messaging is enabled.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        // Validate context.
        $context = context_system::instance();
        self::validate_context($context);

        $params = [
            'userid' => $userid,
        ];
        $params = self::validate_parameters(self::get_received_contact_requests_count_parameters(), $params);

        $capability = 'moodle/site:manageallmessaging';
        if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
            throw new required_capability_exception($context, $capability, 'nopermissions', '');
        }

        return \core_message\api::get_received_contact_requests_count($params['userid']);
    }
741653
protected function get_users_messages_for_conversation(int $conversationid, int $userid) : moodle_recordset {
        global $DB;

        $usernamefields = \user_picture::fields('u');
        $sql = "SELECT $usernamefields, m.*
                  FROM {messages} m
                  JOIN {user} u
                    ON u.id = m.useridfrom
                  JOIN {message_email_messages} mem
                    ON mem.messageid = m.id
                 WHERE mem.useridto = ?
                   AND mem.conversationid = ?
                   AND mem.id <= ?";

        return $DB->get_recordset_sql($sql, [$userid, $conversationid, $this->maxid]);
    }
332966
public function setUserPreference($userLogin, $preferenceName, $preferenceValue)
    {
        Piwik::checkUserHasSuperUserAccessOrIsTheUser($userLogin);
        Option::set($this->getPreferenceId($userLogin, $preferenceName), $preferenceValue);
    }
835525
public static function mute_conversations(int $userid, array $conversationids) {
        global $CFG, $USER;

        // Check if messaging is enabled.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        // Validate context.
        $context = context_system::instance();
        self::validate_context($context);

        $params = ['userid' => $userid, 'conversationids' => $conversationids];
        $params = self::validate_parameters(self::mute_conversations_parameters(), $params);

        $capability = 'moodle/site:manageallmessaging';
        if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
            throw new required_capability_exception($context, $capability, 'nopermissions', '');
        }

        foreach ($params['conversationids'] as $conversationid) {
            if (!\core_message\api::is_conversation_muted($params['userid'], $conversationid)) {
                \core_message\api::mute_conversation($params['userid'], $conversationid);
            }
        }

        return [];
    }
830570
public function alterFormValues(array $formValues)
    {
        foreach ($this->getMeta() as $key => $fieldMeta) {
            /** @var \stdClass $fieldMeta */
            if ($fieldMeta->type === 'checkbox') {
                if (!empty($formValues[$key])) {
                    // Check for empty() as the collection name may have
                    // been initialized with an empty string.
                    if (empty($formValues[$fieldMeta->collection])) {
                        $formValues[$fieldMeta->collection] = array();
                    }
                    $formValues[$fieldMeta->collection][] = $key;
                }
            }
        }
        return $formValues;
    }
445220
public function postProcessFormValues(array $formValues)
    {
        $driver = $formValues['gitDriver'];
        $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
            'Lightwerk.SurfCaptain.sources.default.driver', $driver);
        // reset
        $this->distributionSettings['Lightwerk']['SurfCaptain']['sources']['default']['mapping'] = [];
        switch ($driver) {
            case 'GitHub':
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.repositoryUrl', '{{ssh_url}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.webUrl', '{{url}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Commit.id', '{{sha}}');
                break;
            case 'GitLab':
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.repositoryUrl', '{{ssh_url_to_repo}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Commit.date', '{{committed_date}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Commit.committerName', '{{committer.name}}');
                break;
            case 'BitBucket':
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.webUrl', '{{links.html.href}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Repository.repositoryUrl', '{{links.clone.1.href}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.name', '{{branch}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.commit.id', '{{raw_node}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.commit.committerName', '{{author}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.commit.date', '{{timestamp}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Branch.commit.message', '{{message}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.name', '{{_KEY_}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.commit.id', '{{raw_node}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.commit.committerName', '{{author}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.commit.date', '{{timestamp}}');
                $this->distributionSettings = Arrays::setValueByPath($this->distributionSettings,
                    'Lightwerk.SurfCaptain.sources.default.mapping.Tag.commit.message', '{{message}}');
                break;
            default:
                throw new SetupException('unknown driver ' . $driver, 1427623122);
        }
        $this->configurationSource->save(FLOW_PATH_CONFIGURATION . ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
            $this->distributionSettings);
    }
1241817
protected function process_outcomes($userid, $formdata, $sourceuserid = null) {
        global $CFG, $USER;

        if (empty($CFG->enableoutcomes)) {
            return;
        }
        if ($this->grading_disabled($userid)) {
            return;
        }

        require_once($CFG->libdir.'/gradelib.php');

        $data = array();
        $gradinginfo = grade_get_grades($this->get_course()->id,
                                        'mod',
                                        'assign',
                                        $this->get_instance()->id,
                                        $userid);

        if (!empty($gradinginfo->outcomes)) {
            foreach ($gradinginfo->outcomes as $index => $oldoutcome) {
                $name = 'outcome_'.$index;
                $sourceuserid = $sourceuserid !== null ? $sourceuserid : $userid;
                if (isset($formdata->{$name}[$sourceuserid]) &&
                        $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$sourceuserid]) {
                    $data[$index] = $formdata->{$name}[$sourceuserid];
                }
            }
        }
        if (count($data) > 0) {
            grade_update_outcomes('mod/assign',
                                  $this->course->id,
                                  'mod',
                                  'assign',
                                  $this->get_instance()->id,
                                  $userid,
                                  $data);
        }
    }