/*!
Sets all groups overwriting the current values
190833
function setGroups( $groupArray )
    {
        $resultArray = array();
        // Check for readOnly
        foreach ( $groupArray as $blockName => $blockVariables )
        {
            foreach ( $blockVariables as $variableName => $variableValue )
            {
                if ( !$this->isSettingReadOnly( $this->FileName, $blockName, $variableName ) )
                    continue;
                $resultArray[$blockName][$variableName] = $variableValue;
            }
        }
        $this->BlockValues = $resultArray;
    }
753742
public function setGroups($groups)
    {
        $this->hasGroupsProperty();

        $this->groups = $groups instanceof ArrayCollection ?
            $groups :
            new ArrayCollection($groups);
    }
622130
function startGroup(&$group, $required, $error){
        global $OUTPUT;

        // Make sure the element has an id.
        $group->_generateId();

        // Prepend 'fgroup_' to the ID we generated.
        $groupid = 'fgroup_' . $group->getAttribute('id');

        // Update the ID.
        $group->updateAttributes(array('id' => $groupid));
        $advanced = isset($this->_advancedElements[$group->getName()]);

        $html = $OUTPUT->mform_element($group, $required, $advanced, $error, false);
        $fromtemplate = !empty($html);
        if (!$fromtemplate) {
            if (method_exists($group, 'getElementTemplateType')) {
                $html = $this->_elementTemplates[$group->getElementTemplateType()];
            } else {
                $html = $this->_elementTemplates['default'];
            }

            if (isset($this->_advancedElements[$group->getName()])) {
                $html = str_replace(' {advanced}', ' advanced', $html);
                $html = str_replace('{advancedimg}', $this->_advancedHTML, $html);
            } else {
                $html = str_replace(' {advanced}', '', $html);
                $html = str_replace('{advancedimg}', '', $html);
            }
            if (method_exists($group, 'getHelpButton')) {
                $html = str_replace('{help}', $group->getHelpButton(), $html);
            } else {
                $html = str_replace('{help}', '', $html);
            }
            $html = str_replace('{id}', $group->getAttribute('id'), $html);
            $html = str_replace('{name}', $group->getName(), $html);
            $html = str_replace('{groupname}', 'data-groupname="'.$group->getName().'"', $html);
            $html = str_replace('{typeclass}', 'fgroup', $html);
            $html = str_replace('{type}', 'group', $html);
            $html = str_replace('{class}', $group->getAttribute('class'), $html);
            $emptylabel = '';
            if ($group->getLabel() == '') {
                $emptylabel = 'femptylabel';
            }
            $html = str_replace('{emptylabel}', $emptylabel, $html);
        }
        $this->_templates[$group->getName()] = $html;
        // Fix for bug in tableless quickforms that didn't allow you to stop a
        // fieldset before a group of elements.
        // if the element name indicates the end of a fieldset, close the fieldset
        if (in_array($group->getName(), $this->_stopFieldsetElements) && $this->_fieldsetsOpen > 0) {
            $this->_html .= $this->_closeFieldsetTemplate;
            $this->_fieldsetsOpen--;
        }
        if (!$fromtemplate) {
            parent::startGroup($group, $required, $error);
        } else {
            $this->_html .= $html;
        }
    }
587607
public static function SetGroupValue($group, $option, $value)
    {
        self::CheckBackend();

        self::$backend->SetGroupValue($group, $option, $value);
    }
1175523
public Setting set(String group, String key, String value) {
		this.put(group, key, value);
		return this;
	}
134784
public function group($group){
        if(is_array($group)){
            $this->group= 'GROUP BY ';
            foreach ($group as $value) {
                $this->group .= $value.',';
            }
            $this->group= rtrim($this->group, ',');
            $this->group.=' ';
        }else{
            $this->group= 'GROUP BY '.$group.' ';
        }
    }
769723
public static function update_groups($groups) {
        global $CFG, $DB;
        require_once("$CFG->dirroot/group/lib.php");

        $params = self::validate_parameters(self::update_groups_parameters(), array('groups' => $groups));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['groups'] as $group) {
            $group = (object)$group;

            if (trim($group->name) == '') {
                throw new invalid_parameter_exception('Invalid group name');
            }

            if (! $currentgroup = $DB->get_record('groups', array('id' => $group->id))) {
                throw new invalid_parameter_exception("Group $group->id does not exist");
            }

            // Check if the modified group name already exists in the course.
            if ($group->name != $currentgroup->name and
                    $DB->get_record('groups', array('courseid' => $currentgroup->courseid, 'name' => $group->name))) {
                throw new invalid_parameter_exception('A different group with the same name already exists in the course');
            }

            $group->courseid = $currentgroup->courseid;

            // Now security checks.
            $context = context_course::instance($group->courseid);
            try {
                self::validate_context($context);
            } catch (Exception $e) {
                $exceptionparam = new stdClass();
                $exceptionparam->message = $e->getMessage();
                $exceptionparam->courseid = $group->courseid;
                throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
            }
            require_capability('moodle/course:managegroups', $context);

            if (!empty($group->description)) {
                $group->descriptionformat = external_validate_format($group->descriptionformat);
            }

            groups_update_group($group);
        }

        $transaction->allow_commit();

        return null;
    }
541745
public void setCurrentGroup(int groupId){
        if(mCurrentGroup != groupId){
            int oldGroupId = mCurrentGroup;
            mCurrentGroup = groupId;
            mGroupChanged = true;
            dispatchOnToolbarGroupChanged(oldGroupId, mCurrentGroup);
            animateOut();
        }
    }
779548
protected function resetSubGroups()
    {
        $reset = false;
        foreach ($this->parent->getGroups() as $group) {
            if ($reset) {
                $group->reset();
            }

            if ($group === $this) {
                $reset = true;
            }
        }
    }
571303
public function set( $key, $value = null, $group = '' )
	{
		$this->checkLoaded();
		$this->modified = true;

		if ( is_array($key) ) {
			foreach ( $key as $k => $v ) {
				SettingsUtilities::set($this->storage, $k, $v);
			}
		} else {
			SettingsUtilities::set($this->storage, $key, $value);
		}
	}
539735
function setValue($value)
    {
        $this->_createElementsIfNotExist();
        foreach (array_keys($this->_elements) as $key) {
            if (!$this->_appendName) {
                $v = $this->_elements[$key]->_findValue($value);
                if (null !== $v) {
                    $this->_elements[$key]->onQuickFormEvent('setGroupValue', $v, $this);
                }

            } else {
                $elementName = $this->_elements[$key]->getName();
                $index       = strlen($elementName) ? $elementName : $key;
                if (is_array($value)) {
                    if (isset($value[$index])) {
                        $this->_elements[$key]->onQuickFormEvent('setGroupValue', $value[$index], $this);
                    }
                } elseif (isset($value)) {
                    $this->_elements[$key]->onQuickFormEvent('setGroupValue', $value, $this);
                }
            }
        }
    }
811909
public function change_group(): void
    {
        if (!userHasPermission('admin:auth:accounts:changeUserGroup') && !userHasPermission('admin:auth:accounts:changeOwnUserGroup')) {
            show404();
        }

        // --------------------------------------------------------------------------

        $oInput     = Factory::service('Input');
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $aUserIds   = explode(',', $oInput->get('users'));
        $aUsers     = $oUserModel->getByIds($aUserIds);

        if (empty($aUsers)) {
            show404();
        }

        $aRemovedUsers = [];
        foreach ($aUsers as &$oUser) {
            if (
                ($oUserModel->isSuperuser($oUser) && !$oUserModel->isSuperuser())
                || ($oUser->id === activeUser('id') && !userHasPermission('admin:auth:accounts:changeOwnUserGroup'))
                || ($oUser->id !== activeUser('id') && !userHasPermission('admin:auth:accounts:changeUserGroup'))
            ) {
                $aRemovedUsers[] = $oUser;
                $oUser           = null;
            }
        }

        $aUsers = array_filter($aUsers);
        $aUsers = array_values($aUsers);

        if (!empty($aRemovedUsers)) {
            $this->data['warning'] = 'You do not have permission to change the group of the following users: ' .
                implode(', ', array_map(function ($oUser) {
                    return '<br><strong>#' . $oUser->id . ' ' . $oUser->first_name . ' ' . $oUser->last_name . '</strong>';
                }, $aRemovedUsers));
        }

        if (empty($aUsers)) {
            $this->data['error'] = 'No users selected';
        }

        // --------------------------------------------------------------------------

        $oUserGroupModel = Factory::model('UserGroup', 'nails/module-auth');
        $aGroups         = $oUserGroupModel->getAll();

        if (!isSuperuser()) {
            foreach ($aGroups as &$oGroup) {
                if (!empty($oGroup->acl) && in_array('admin:superuser', $oGroup->acl)) {
                    $oGroup = null;
                }
            }
        }

        $aGroups     = array_filter($aGroups);
        $aGroups     = array_values($aGroups);
        $aUserGroups = [];
        foreach ($aGroups as $oGroup) {
            $aUserGroups[$oGroup->id] = $oGroup->label;
        }

        // --------------------------------------------------------------------------

        if ($oInput->post()) {
            if ($oUserGroupModel->changeUserGroup(arrayExtractProperty($aUsers, 'id'), (int) $oInput->post('group_id'))) {
                $oSession = Factory::service('Session', 'nails/module-auth');
                $oSession->setFlashData('success', 'User group was updated successfully.');
                redirect('admin/auth/accounts');
            } else {
                $this->data['error'] = 'Failed to update user group. ' . $oUserGroupModel->lastError();
            }
        }


        $this->data['aUsers']      = $aUsers;
        $this->data['aUserGroups'] = $aUserGroups;
        $this->data['page']->title = 'Change a user\'s group';

        // --------------------------------------------------------------------------

        //  Load views
        Helper::loadView('changeGroup');
    }
215995
function(data) {
			var key = hash_key(data[this.settings.optgroupValueField]);
			if (!key) return false;
	
			data.$order = data.$order || ++this.order;
			this.optgroups[key] = data;
			return key;
		}
781283
public function resetGroupBy()
    {
        $this->_groupby = '';
        $this->_groupfunc = SPH_GROUPBY_DAY;
        $this->_groupsort = '@group desc';
        $this->_groupdistinct = '';

        return $this;
    }
1030604
function set_group($group_id)
    {
        if ($group_id) {
            $this->group_id = $group_id;
            $this->group_data = $this->get_group_entry($group_id);
        }
        else {
            $this->group_id = 0;
            $this->group_data = null;
        }
    }
934111
public function setValue(string $key, $value, string $group = null): self
    {
        if (!empty($group)) {
            $this->values[$group][$key] = $value;
        } else {
            $this->values[$key] = $value;
        }

        return $this;
    }
84683
function groups()
    {
        if ( isset( self::$injectedSettings[$this->FileName] ) || isset( self::$injectedMergeSettings[$this->FileName] ) )
        {
            $result = $this->BlockValues;
            foreach ( $result as $blockName => $vars )
            {
                foreach ( $vars as $varName => $varValue )
                {
                    if ( isset( self::$injectedSettings[$this->FileName][$blockName][$varName] ) )
                    {
                        $result[$blockName][$varName] = self::$injectedSettings[$this->FileName][$blockName][$varName];
                    }
                    if ( isset( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
                    {
                        if ( !is_array( $result[$blockName][$varName] ) || !is_array( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
                        {
                            throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
                        }

                        $result[$blockName][$varName] = array_merge(
                            $varValue,
                            self::$injectedMergeSettings[$this->FileName][$blockName][$varName]
                        );
                    }
                }
            }
            foreach ( self::$injectedSettings[$this->FileName] as $blockName => $vars )
            {
                if ( !isset( $result[$blockName] ) )
                {
                    $result[$blockName] = $vars;
                }
            }
            return $result;
        }
        return $this->BlockValues;
    }