• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/user_group.php
  • Класс: CAllSocNetUserToGroup
  • Вызов: CAllSocNetUserToGroup::NotifyImToModerators
static function NotifyImToModerators($arNotifyParams): void
{
	if (!Loader::includeModule('im'))
	{
		return;
	}

	if (
		!is_array($arNotifyParams)
		|| !isset(
			$arNotifyParams["TYPE"],
			$arNotifyParams["USER_ID"],
			$arNotifyParams["GROUP_ID"],
			$arNotifyParams["RELATION_ID"],
			$arNotifyParams["GROUP_NAME"]
		)
		|| (int)$arNotifyParams["USER_ID"] <= 0
		|| (int)$arNotifyParams["GROUP_ID"] <= 0
		|| (int)$arNotifyParams["RELATION_ID"] <= 0
		|| (string)$arNotifyParams["GROUP_NAME"] === ''
		|| !in_array($arNotifyParams["TYPE"], [
			"join",
			"unjoin",
			"exclude",
			"moderate",
			"unmoderate",
			"owner"
		], true)
	)
	{
		return;
	}

	$fromUserId = false;
	$messageCode = false;
	$schemaCode = false;
	$notifyTag = false;

	switch ($arNotifyParams["TYPE"])
	{
		case "join":
			$fromUserId = $arNotifyParams["USER_ID"];
			$messageCode = "SONET_UG_IM_JOIN";
			$schemaCode = "inout_group";
			$notifyTag = "INOUT_GROUP";
			break;
		case "unjoin":
			$fromUserId = $arNotifyParams["USER_ID"];
			$messageCode = "SONET_UG_IM_UNJOIN";
			$schemaCode = "inout_group";
			$notifyTag = "INOUT_GROUP";
			break;
		case "exclude":
			$fromUserId = $arNotifyParams["USER_ID"];
			$messageCode = "SONET_UG_IM_EXCLUDE";
			$schemaCode = "inout_group";
			$notifyTag = "INOUT_GROUP";
			break;
		case "moderate":
			$fromUserId = $arNotifyParams["USER_ID"];
			$messageCode = "SONET_UG_IM_MODERATE";
			$schemaCode = "moderators_group";
			$notifyTag = "MOD_GROUP";
			break;
		case "unmoderate":
			$fromUserId = $arNotifyParams["USER_ID"];
			$messageCode = "SONET_UG_IM_UNMODERATE";
			$schemaCode = "moderators_group";
			$notifyTag = "MOD_GROUP";
			break;
		case "owner":
			$fromUserId = $arNotifyParams["USER_ID"];
			$messageCode = "SONET_UG_IM_OWNER";
			$schemaCode = "owner_group";
			$notifyTag = "OWNER_GROUP";
			break;
		default:
	}

	$gender_suffix = "";
	$rsUser = CUser::GetByID($arNotifyParams["USER_ID"]);
	if ($arUser = $rsUser->Fetch())
	{
		switch ($arUser["PERSONAL_GENDER"])
		{
			case "M":
				$gender_suffix = "_M";
				break;
			case "F":
				$gender_suffix = "_F";
				break;
			default:
				$gender_suffix = "";
		}
	}

	$arToUserID = [];

	$rsUserToGroup = CSocNetUserToGroup::GetList(
		array(),
		array(
			"GROUP_ID" => $arNotifyParams["GROUP_ID"],
			"USER_ACTIVE" => "Y",
			"<=ROLE" => UserToGroupTable::ROLE_MODERATOR,
		),
		false,
		false,
		array("USER_ID")
	);
	while ($arUserToGroup = $rsUserToGroup->Fetch())
	{
		$arToUserID[] = (int)$arUserToGroup["USER_ID"];
	}

	$arMessageFields = array(
		"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
		"FROM_USER_ID" => $fromUserId,
		"NOTIFY_TYPE" => IM_NOTIFY_FROM,
		"NOTIFY_MODULE" => "socialnetwork",
		"NOTIFY_EVENT" => $schemaCode,
		"NOTIFY_TAG" => "SOCNET|" . $notifyTag . "|" . (int)$arNotifyParams["USER_ID"]
			. "|" . (int)$arNotifyParams["GROUP_ID"] . "|" . (int)$arNotifyParams["RELATION_ID"],
	);

	$groups_path = COption::GetOptionString("socialnetwork", "workgroups_page", SITE_DIR."workgroups/");
	$group_url_template = str_replace(
		$groups_path,
		"#GROUPS_PATH#",
		Path::get('group_path_template')
	);

	$groupUrl = str_replace(
		"#group_id#",
		$arNotifyParams["GROUP_ID"],
		$group_url_template
	);

	foreach ($arToUserID as $to_user_id)
	{
		if (
			$to_user_id === (int)$fromUserId
			|| (
				is_array($arNotifyParams["EXCLUDE_USERS"] ?? null)
				&& in_array($to_user_id, $arNotifyParams["EXCLUDE_USERS"])
			)
		)
		{
			continue;
		}

		$arMessageFields["TO_USER_ID"] = $to_user_id;
		$arTmp = CSocNetLogTools::ProcessPath(
			array(
				"GROUP_PAGE" => $groupUrl
			),
			$to_user_id,
			SITE_ID
		);

		$arMessageFields["NOTIFY_MESSAGE"] = GetMessage($messageCode.$gender_suffix, Array(
			"#group_name#" => "".$arNotifyParams["GROUP_NAME"]."",
		));

		$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage($messageCode.$gender_suffix, Array(
			"#group_name#" => $arNotifyParams["GROUP_NAME"],
		))." (".$arTmp["SERVER_NAME"].$arTmp["URLS"]["GROUP_PAGE"].")";

		CIMNotify::Add($arMessageFields);
	}
}