/*
update the group assignment for the user. return true if at least one group was changed
@return boolean
549193
public static function UpdateAutoAssignToUserQuick($sUserid, $dOrderValue)
    {
        $sEscapedUserid = MySqlLegacySupport::getInstance()->real_escape_string($sUserid);
        // get all assigned groups that are NOT auto assigned
        $query = "SELECT `data_extranet_user_data_extranet_group_mlt`.`target_id`
                  FROM `data_extranet_user_data_extranet_group_mlt`
            INNER JOIN `data_extranet_group` ON `data_extranet_user_data_extranet_group_mlt`.`target_id` = `data_extranet_group`.`id`
                 WHERE `data_extranet_user_data_extranet_group_mlt`.`source_id` = '{$sEscapedUserid}'
                   AND `data_extranet_group`.`auto_assign_active` = '0'
               ";
        $aUserGroups = array();
        $tRes = MySqlLegacySupport::getInstance()->query($query);
        while ($aRow = MySqlLegacySupport::getInstance()->fetch_assoc($tRes)) {
            $aUserGroups[] = MySqlLegacySupport::getInstance()->real_escape_string($aRow['target_id']);
        }
        // now add groups set via auto assign
        $oGroups = TdbDataExtranetGroupList::GetAutoGroupsForValue($dOrderValue);
        while ($oGroup = $oGroups->Next()) {
            $aUserGroups[] = MySqlLegacySupport::getInstance()->real_escape_string($oGroup->id);
        }

        // update user
        // note: we use a query here to prevent overhead
        $query = "DELETE FROM `data_extranet_user_data_extranet_group_mlt`
                      WHERE `source_id` = '{$sEscapedUserid}'";
        MySqlLegacySupport::getInstance()->query($query);
        $iRecordsChanged = MySqlLegacySupport::getInstance()->affected_rows();
        if (count($aUserGroups) > 0) {
            $query = 'INSERT INTO `data_extranet_user_data_extranet_group_mlt` (`source_id`,`target_id`) VALUES ';
            $aInsertParts = array();
            foreach ($aUserGroups as $sGroupId) {
                $aInsertParts[] = "('{$sEscapedUserid}','{$sGroupId}')";
            }
            $query .= implode(', ', $aInsertParts);
            MySqlLegacySupport::getInstance()->query($query);
            $iRecordsChanged = $iRecordsChanged + MySqlLegacySupport::getInstance()->affected_rows();
        }
        if ($iRecordsChanged > 0) {
            TCacheManager::PerformeTableChange('data_extranet_user', $sUserid);
        }

        return $iRecordsChanged > 0;
    }
512040
public function update()
	{
		// Get group config
		$groupsConfig = \Component::params('com_groups');

		// Path to group folder
		$directory  = PATH_APP . DS . trim($groupsConfig->get('uploadpath', '/site/groups'), DS);
		$directory .= DS . $this->group->get('gidNumber');

		// Get task, defaults to update
		$task = ($this->arguments->getOpt(3)) ? $this->arguments->getOpt(3) : 'update';

		// Set our group directory & call update
		$this->arguments->setOpt('r', $directory);
		\App::get('client')->call('repository', $task, $this->arguments, $this->output);
	}
1028100
protected function assignGroup()
    {
        if (!$this->config()->get('grant_user_access')) {
            return;
        }

        $group = $this->getUserGroup();

        // Must check if the method exists or else an error occurs when changing page type
        if ($this->hasMethod('Editors')) {
            foreach ([$this->Editors(), $this->Writers(), $this->Contributors()] as $levels) {
                foreach ($levels as $user) {
                    if (!$user->inGroup($group)) {
                        $user->Groups()->add($group);
                    }
                }
            }
        }
    }
1317201
protected function update($step)
    {
        $userGroupCollection = $this->matchUserGroups('update', $step);

        if (count($userGroupCollection) > 1 && isset($step->dsl['references'])) {
            throw new \Exception("Can not execute Group update because multiple groups match, and a references section is specified in the dsl. References can be set when only 1 group matches");
        }

        $userService = $this->repository->getUserService();
        $contentService = $this->repository->getContentService();

        foreach ($userGroupCollection as $key => $userGroup) {

            /** @var $updateStruct \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct */
            $updateStruct = $userService->newUserGroupUpdateStruct();

            /** @var $contentUpdateStruct \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct */
            $contentUpdateStruct = $contentService->newContentUpdateStruct();

            if (isset($step->dsl['name'])) {
                $contentUpdateStruct->setField('name', $step->dsl['name']);
            }

            if (isset($step->dsl['remote_id'])) {
                $contentUpdateStruct->remoteId = $step->dsl['remote_id'];
            }

            if (isset($step->dsl['description'])) {
                $contentUpdateStruct->setField('description', $step->dsl['description']);
            }

            $updateStruct->contentUpdateStruct = $contentUpdateStruct;

            $userGroup = $userService->updateUserGroup($userGroup, $updateStruct);

            if (isset($step->dsl['parent_group_id'])) {
                $parentGroupId = $step->dsl['parent_group_id'];
                $parentGroupId = $this->referenceResolver->resolveReference($parentGroupId);
                $newParentGroup = $this->userGroupMatcher->matchOneByKey($parentGroupId);

                // Move group to new parent
                $userService->moveUserGroup($userGroup, $newParentGroup);

                // reload user group to be able to set refs correctly
                $userGroup = $userService->loadUserGroup($userGroup->id);
            }

            if (isset($step->dsl['section'])) {
                $this->setSection($userGroup, $step->dsl['section']);

                /// @todo if we allow to set references to the group's section, here we should reload it
            }

            $userGroupCollection[$key] = $userGroup;
        }

        $this->setReferences($userGroupCollection, $step);

        return $userGroupCollection;
    }
437573
public function update($ids)
    {
        if (empty($ids)) {
            return false;
        } elseif (empty($this->_ids)) {
            $this->_ids = $ids;
            $change = true;
        } else {
            $change = false;
            foreach ($ids as $k => $v) {
                if (!isset($this->_ids[$k]) || ($this->_ids[$k] != $v)) {
                    $this->_ids[$k] = $v;
                    $change = true;
                }
            }
        }

        if ($change) {
            $this->_sorted = false;
        }

        return $change;
    }
1029366
public function updateGroup($groupId, Api\GroupUpdate $group)
    {
        $json = Serialize::groupUpdate($group);
        $result = $this->_post($this->_groupUrl($groupId), $json);
        return Deserialize::groupResponse($result);
    }
634251
public function updateGroup(GroupUpdateStruct $group)
    {
        try {
            return $this->innerGateway->updateGroup($group);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
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;
        }
    }
227991
public function inAllowedGroup()
    {
        if ($this->isCurrentUser() || (! $this->isStaff())) {
            // Always allow editing of non-staff user
            // for the time being
            return true;
        }

        $group  = $this->getGroupId();
        $groups = $this->util->getDbLookup()->getActiveStaffGroups();
        if (! isset($groups[$group])) {
            // Allow editing when the group does not exist or is no longer active.
            return true;
        }

        $allowedGroups = $this->userLoader->getCurrentUser()->getAllowedStaffGroups();
        if ($allowedGroups) {
            return (boolean) isset($allowedGroups[$group]);
        } else {
            return false;
        }
    }
1018721
public function changeGroup( $groupName, $recursive = FALSE )
	{
		if( !$groupName )
			throw new InvalidArgumentException( 'Group is missing' );
		$number	= (int) chgrp( $this->folderName, $groupName );

		if( !$recursive )
			return $number;
		$iterator = new RecursiveIteratorIterator(
			new RecursiveDirectoryIterator( $this->folderName ),
			RecursiveIteratorIterator::SELF_FIRST
		);
		foreach( $iterator as $item )
			$number += (int) chgrp( $item, $groupName );
		return $number;
	}
581382
public function setGroup($group)
	{
	    if ($this->options['group']) {
	        $group = str_replace('//', '/', $this->options['group'] . '/' . $group);
	    }
	    
	    return $this->setOption('group', $group);
	}
194039
public function updateGroup($groupId, $fields = array()) {
        if (empty($fields)) {
            $this->throwException(__METHOD__, 'Set fields for group');
        }

        $group = new \CGroup;
        if ($group->Update($groupId, $this->prepareFields($fields))) {
            return intval($groupId);
        }

        $this->throwException(__METHOD__, $group->LAST_ERROR);
    }
411391
public function updateGroup(array $groups)
    {
        $groups = json_encode($groups, JSON_UNESCAPED_UNICODE);

        return $this->auth(function () use ($groups) {
            return $this->http->postJson(
                $this->baseUrl . 'cgi-bin/groups/update?access_token=' . $this->accessToken,
                $groups
            );
        });
    }
1066960
public function updateGroup($groupid,$name){
        if (!$this->access_token && !$this->checkAuth()) return false;
        $data = array(
                'group'=>array('id'=>$groupid,'name'=>$name)
        );
        $result = $this->http_post(self::API_URL_PREFIX.self::GROUP_UPDATE_URL.'access_token='.$this->access_token,self::json_encode($data));
        if ($result)
        {
            $json = json_decode($result,true);
            if (!$json || !empty($json['errcode'])) {
                $this->errCode = $json['errcode'];
                $this->errMsg = $json['errmsg'];
                return false;
            }
            return $json;
        }
        return false;
    }
1289725
public static function assign_grouping($assignments) {
        global $CFG, $DB;
        require_once("$CFG->dirroot/group/lib.php");

        $params = self::validate_parameters(self::assign_grouping_parameters(), array('assignments'=>$assignments));

        $transaction = $DB->start_delegated_transaction();
        foreach ($params['assignments'] as $assignment) {
            // Validate params.
            $groupingid = $assignment['groupingid'];
            $groupid = $assignment['groupid'];

            $grouping = groups_get_grouping($groupingid, 'id, courseid', MUST_EXIST);
            $group = groups_get_group($groupid, 'id, courseid', MUST_EXIST);

            if ($DB->record_exists('groupings_groups', array('groupingid'=>$groupingid, 'groupid'=>$groupid))) {
                // Continue silently if the group is yet assigned to the grouping.
                continue;
            }

            // Now security checks.
            $context = context_course::instance($grouping->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);

            groups_assign_grouping($groupingid, $groupid);
        }

        $transaction->allow_commit();
    }
1317775
public function UpdateAutoAssignAllUsers()
    {
        // get all users that no longer apply
        $query = "DELETE FROM `data_extranet_user_data_extranet_group_mlt` WHERE `data_extranet_user_data_extranet_group_mlt`.`target_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'";
        MySqlLegacySupport::getInstance()->query($query);

        // now add group to every one with the corrseponding value
        $query = "SELECT `data_extranet_user`.`id` AS source_id, '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."' AS target_id
                  FROM `data_extranet_user`
             LEFT JOIN `shop_order` ON `data_extranet_user`.`id` = `shop_order`.`data_extranet_user_id`
                   AND (`shop_order`.`id` IS NULL OR `shop_order`.`canceled` = '0')
              GROUP BY `data_extranet_user` .`id`
                HAVING
                       (SUM(`shop_order`.`value_total`) >= {$this->fieldAutoAssignOrderValueStart}
               ";
        if ($this->fieldAutoAssignOrderValueEnd > 0) {
            $query .= "AND SUM(`shop_order`.`value_total`) < {$this->fieldAutoAssignOrderValueEnd}";
        }
        $query .= ')';
        if (0.01 == $this->fieldAutoAssignOrderValueEnd) {
            $query .= ' OR SUM(  `shop_order`.`value_total` ) IS NULL';
        } // allow users that have no orders
        $query = 'INSERT INTO `data_extranet_user_data_extranet_group_mlt` (`source_id`,`target_id`) '.$query;
        MySqlLegacySupport::getInstance()->query($query);

        return MySqlLegacySupport::getInstance()->affected_rows();
    }
222841
public function updateUsersGroup(array $data)
    {
        $result = $this->httpRaw(self::WECHAT_USERS_GROUP_UPDATE_PREFIX, $data, [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok';
    }