• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/user_group.php
  • Класс: CAllSocNetUserToGroup
  • Вызов: CAllSocNetUserToGroup::BanMember
static function BanMember($userID, $groupId, $relationIdList, $currentUserIsAdmin): bool
{
	global $APPLICATION;

	$userID = (int)$userID;
	if ($userID <= 0)
	{
		$APPLICATION->ThrowException(GetMessage("SONET_UR_EMPTY_USERID"), "ERROR_USERID");
		return false;
	}

	$groupId = (int)$groupId;
	if ($groupId <= 0)
	{
		$APPLICATION->ThrowException(GetMessage("SONET_UR_EMPTY_GROUPID"), "ERROR_GROUPID");
		return false;
	}

	if (!is_array($relationIdList))
	{
		return true;
	}

	$arGroup = CSocNetGroup::GetByID($groupId);
	if (!$arGroup || !is_array($arGroup))
	{
		$APPLICATION->ThrowException(GetMessage("SONET_UG_ERROR_NO_GROUP_ID"), "ERROR_NO_GROUP");
		return false;
	}

	$arUserPerms = CSocNetUserToGroup::InitUserPerms($userID, $arGroup, $currentUserIsAdmin);

	if (!$arUserPerms["UserCanModifyGroup"] && !$arUserPerms["UserCanModerateGroup"])
	{
		$APPLICATION->ThrowException(GetMessage("SONET_UG_ERROR_NO_PERMS"), "ERROR_NO_PERMS");
		return false;
	}

	$bSuccess = true;
	foreach ($relationIdList as $relationId)
	{
		$relationId = (int)$relationId;
		if ($relationId <= 0)
		{
			continue;
		}

		$arRelation = CSocNetUserToGroup::GetByID($relationId);
		if (!$arRelation)
		{
			continue;
		}

		if (
			(int)$arRelation["GROUP_ID"] !== $groupId
			|| $arRelation["ROLE"] !== UserToGroupTable::ROLE_USER
		)
		{
			continue;
		}

		$arFields = array(
			"ROLE" => UserToGroupTable::ROLE_BAN,
			"=DATE_UPDATE" => CDatabase::CurrentTimeFunction(),
		);
		if (CSocNetUserToGroup::Update($arRelation["ID"], $arFields))
		{
			$arMessageFields = array(
				"FROM_USER_ID" => $userID,
				"TO_USER_ID" => $arRelation["USER_ID"],
				"MESSAGE" => str_replace("#NAME#", $arGroup["NAME"], GetMessage("SONET_UG_BANMEMBER_MESSAGE")),
				"=DATE_CREATE" => CDatabase::CurrentTimeFunction(),
				"MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM
			);
			CSocNetMessages::Add($arMessageFields);
			CSocNetSubscription::DeleteEx($arRelation["USER_ID"], "SG".$arRelation["GROUP_ID"]);

			UserToGroup::addInfoToChat(array(
				'group_id' => $groupId,
				'user_id' => $arRelation["USER_ID"],
				'action' => UserToGroup::CHAT_ACTION_OUT
			));
		}
		else
		{
			$errorMessage = "";
			if ($e = $APPLICATION->GetException())
			{
				$errorMessage = $e->GetString();
			}
			if ($errorMessage === '')
			{
				$errorMessage = Loc::getMessage('SONET_UR_ERROR_CREATE_USER2GROUP');
			}

			$APPLICATION->ThrowException($errorMessage, "ERROR_BANMEMBER");
			$bSuccess = false;
		}
	}

	return $bSuccess;
}