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

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

	$relationID = (int)$relationID;
	if ($relationID <= 0)
	{
		$APPLICATION->ThrowException(GetMessage("SONET_UR_EMPTY_RELATIONID"), "ERROR_RELATION_ID");
		return false;
	}

	$dbResult = CSocNetUserToGroup::GetList(
		array(),
		array(
			"ID" => $relationID,
			"USER_ID" => $targetUserID,
			"ROLE" => UserToGroupTable::ROLE_REQUEST,
			"INITIATED_BY_TYPE" => SONET_INITIATED_BY_GROUP
		),
		false,
		false,
		array("ID", "USER_ID", "GROUP_ID", "GROUP_SITE_ID", "INITIATED_BY_USER_ID", "GROUP_NAME")
	);

	if ($arResult = $dbResult->Fetch())
	{
		if (!empty($arResult['GROUP_NAME']))
		{
			$arResult['GROUP_NAME'] = Emoji::decode($arResult['GROUP_NAME']);
		}

		if (CSocNetUserToGroup::Delete($arResult["ID"]))
		{
			$events = GetModuleEvents("socialnetwork", "OnSocNetUserRejectRequestToBeMember");
			while ($arEvent = $events->Fetch())
			{
				ExecuteModuleEventEx($arEvent, array($arResult["ID"], $arResult));
			}

			if (Loader::includeModule('im'))
			{
				$groupSiteId = CSocNetGroup::GetDefaultSiteId($arResult["GROUP_ID"], $arResult["GROUP_SITE_ID"]);
				$groupUrl = str_replace(
					[ "#group_id#", "#GROUP_ID#" ],
					$arResult["GROUP_ID"],
					Path::get('group_path_template', $groupSiteId)
				);
				$arTmp = CSocNetLogTools::ProcessPath(
					array(
						"GROUP_URL" => $groupUrl
					),
					$arResult["INITIATED_BY_USER_ID"],
					$groupSiteId
				);
				$url = $arTmp["URLS"]["GROUP_URL"];
				$serverName = (
				mb_strpos($url, "http://") === 0
					|| mb_strpos($url, "https://") === 0
						? ""
						: $arTmp["SERVER_NAME"]
				);
				$domainName = (
				mb_strpos($url, "http://") === 0
					|| mb_strpos($url, "https://") === 0
						? ""
						: (
							isset($arTmp["DOMAIN"])
							&& !empty($arTmp["DOMAIN"])
								? "//".$arTmp["DOMAIN"]
								: ""
						)
				);

				$arMessageFields = array(
					"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
					"TO_USER_ID" => $arResult["INITIATED_BY_USER_ID"],
					"FROM_USER_ID" => $arResult['USER_ID'],
					"NOTIFY_TYPE" => IM_NOTIFY_FROM,
					"NOTIFY_MODULE" => "socialnetwork",
					"NOTIFY_EVENT" => "invite_group",
					"NOTIFY_TAG" => "SOCNET|INVITE_GROUP_REJECT|" . (int)$arResult["GROUP_ID"],
					"NOTIFY_MESSAGE" => str_replace(
						"#NAME#",
						"".$arResult["GROUP_NAME"]."",
						GetMessage("SONET_UG_REJECT_MEMBER_MESSAGE")
					),
					"NOTIFY_MESSAGE_OUT" => str_replace(
						"#NAME#",
						$arResult["GROUP_NAME"],
						GetMessage("SONET_UG_REJECT_MEMBER_MESSAGE")." (".$serverName.$url.")"
					)
				);
				CIMNotify::Add($arMessageFields);
			}
		}
		else
		{
			$errorMessage = "";
			if ($e = $APPLICATION->GetException())
			{
				$errorMessage = $e->GetString();
			}
			if ($errorMessage === '')
			{
				$errorMessage = Loc::getMessage('SONET_UR_ERROR_CREATE_USER2GROUP');
			}

			$APPLICATION->ThrowException($errorMessage, "ERROR_DELETE_RELATION");
			return false;
		}
	}
	else
	{
		$APPLICATION->ThrowException(GetMessage("SONET_NO_USER2GROUP"), "ERROR_NO_MEMBER_REQUEST");
		return false;
	}

	CSocNetUserToGroup::__SpeedFileCheckMessages($targetUserID);

	return true;
}