• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/rest.php
  • Класс: CSocNetLogRestService
  • Вызов: CSocNetLogRestService::updateGroupUsers
static function updateGroupUsers($arFields): array
{
	$groupId = $arFields['GROUP_ID'] ?? null;
	$userIdList = $arFields['USER_ID'] ?? null;
	$role = $arFields['ROLE'] ?? null;

	if ((int)$groupId <= 0)
	{
		throw new ArgumentException('Wrong group ID');
	}

	if (!self::isCurrentUserAdmin())
	{
		throw new AccessDeniedException('No permissions to update users role');
	}

	if (!in_array($role, [ UserToGroupTable::ROLE_MODERATOR, UserToGroupTable::ROLE_USER ], true))
	{
		throw new ArgumentException('Incorrect role code');
	}

	if (
		(!is_array($userIdList) && (int)$userIdList <= 0)
		|| (is_array($userIdList) && count($userIdList) <= 0)
	)
	{
		throw new ArgumentException('Wrong user IDs');
	}

	if (!is_array($userIdList))
	{
		$userIdList = [ $userIdList ];
	}

	$res = CSocNetGroup::getList(array(), array(
		"ID" => $groupId
	));
	$groupFields = $res->fetch();
	if (!is_array($groupFields))
	{
		throw new ObjectNotFoundException('Socialnetwork group not found');
	}

	$successUserId = [];

	$resRelation = UserToGroupTable::getList(array(
		'filter' => array(
			'GROUP_ID' => $groupId,
			'@USER_ID' => $userIdList
		),
		'select' => array('ID', 'USER_ID', 'ROLE')
	));
	while ($relation = $resRelation->fetch())
	{
		if (
			$relation['ROLE'] === $role
			|| $relation['ROLE'] === UserToGroupTable::ROLE_OWNER
		)
		{
			continue;
		}

		if (CSocNetUserToGroup::update($relation['ID'], [
			"ROLE" => $role,
			"=DATE_UPDATE" => CDatabase::currentTimeFunction(),
		]))
		{
			$successUserId[] = $relation['USER_ID'];
		}
	}

	return $successUserId;
}