public function moveUsersToAlternativeGroups($userIdGroupIdMapping)
    {
        $affectedUsers = 0;
        $affectedGroups = [];
        foreach ($userIdGroupIdMapping as $userId => $groupId) {
            $affectedUsers += $this->UsersGroups->updateAll([
                'group_id' => $groupId
            ], [
                'user_id' => $userId
            ]);
            if (!in_array($groupId, $affectedGroups)) {
                $affectedGroups[] = $groupId;
            }
        }
        if ($affectedUsers > 0 && !empty($affectedGroups)) {
            $this->updateUserCount($affectedGroups);
        }
        return $affectedUsers;
    }
public function moveUsersToAlternativeGroups($userIdGroupIdMapping)
    {
        $affectedUsers = 0;
        $affectedGroups = [];
        foreach ($userIdGroupIdMapping as $userId => $groupId) {
            $affectedUsers += $this->UsersGroups->updateAll([
                'group_id' => $groupId
            ], [
                'user_id' => $userId
            ]);
            if (!in_array($groupId, $affectedGroups)) {
                $affectedGroups[] = $groupId;
            }
        }
        if ($affectedUsers > 0 && !empty($affectedGroups)) {
            $this->updateUserCount($affectedGroups);
        }
        return $affectedUsers;
    }
public function moveUsersToAlternativeGroups ( $ userIdGroupIdMapping ) { $ affectedUsers = 0 ; $ affectedGroups = [ ] ; foreach ( $ userIdGroupIdMapping as $ userId => $ groupId ) { $ affectedUsers += $ this -> UsersGroups -> updateAll ( [ 'group_id' => $ groupId ] , [ 'user_id' => $ userId ] ) ; if ( ! in_array ( $ groupId , $ affectedGroups ) ) { $ affectedGroups [ ] = $ groupId ; } } if ( $ affectedUsers > 0 && ! empty ( $ affectedGroups ) ) { $ this -> updateUserCount ( $ affectedGroups ) ; } return $ affectedUsers ; }
Assign users to new groups.

@param array $userIdGroupIdMapping A mapping of user ids to their new group ids.
@return int number of affected user rows
Assign users to new groups .