• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log.php
  • Класс: CAllSocNetLog
  • Вызов: CAllSocNetLog::SendEvent
static function SendEvent(
	$ID,
	$mailTemplate = "SONET_NEW_EVENT",
	$tmpId = 0,
	$bAgent = false
)
{
	global $APPLICATION;

	$arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();

	$ID = (int)$ID;

	if ($ID <= 0)
	{
		return false;
	}

	$arFilter = array("ID" => $ID);

	$dbLog = CSocNetLog::GetList(
		array(),
		$arFilter,
		false,
		false,
		array("ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "EVENT_ID", "LOG_DATE", "TITLE_TEMPLATE", "TITLE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID", "CALLBACK_FUNC", "SITE_ID", "PARAMS", "SOURCE_ID", "GROUP_NAME", "CREATED_BY_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_LOGIN", "LOG_SOURCE_ID"),
		array("MIN_ID_JOIN" => true)
	);
	$arLog = $dbLog->Fetch();
	if (!$arLog)
	{
		return $bAgent;
	}

	if (MakeTimeStamp($arLog["LOG_DATE"]) > (time() + CTimeZone::GetOffset()))
	{
		$agent = "CSocNetLog::SendEventAgent(".$ID.", '".CUtil::addslashes($mailTemplate)."');";
		$rsAgents = CAgent::GetList(array("ID"=>"DESC"), array("NAME" => $agent));
		if(!$rsAgents->Fetch())
		{
			$res = CAgent::AddAgent($agent, "socialnetwork", "N", 0, $arLog["LOG_DATE"], "Y", $arLog["LOG_DATE"]);
			if(!$res)
			{
				$APPLICATION->ResetException();
			}
		}
		elseif ($bAgent)
		{
			CAgent::RemoveAgent($agent, "socialnetwork");
			CAgent::AddAgent($agent, "socialnetwork", "N", 0, $arLog["LOG_DATE"], "Y", $arLog["LOG_DATE"]);
			return true;
		}
		return false;
	}

	$arEvent = CSocNetLogTools::FindLogEventByID($arLog["EVENT_ID"], $arLog["ENTITY_TYPE"]);
	if (
		$arEvent
		&& isset($arEvent["CLASS_FORMAT"], $arEvent["METHOD_FORMAT"])
	)
	{
		$dbSiteCurrent = CSite::GetByID(SITE_ID);
		if (
			($arSiteCurrent = $dbSiteCurrent->Fetch())
			&& $arSiteCurrent["LANGUAGE_ID"] !== LANGUAGE_ID
		)
		{
			$arLog["MAIL_LANGUAGE_ID"] = $arSiteCurrent["LANGUAGE_ID"];
		}

		$arLog["FIELDS_FORMATTED"] = call_user_func(array($arEvent["CLASS_FORMAT"], $arEvent["METHOD_FORMAT"]), $arLog, array(), true);
	}

	if (
		isset(
			$arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["HAS_MY"],
			$arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["CLASS_OF"],
			$arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["METHOD_OF"]
		)
		&& $arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["HAS_MY"] === "Y"
		&& $arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["CLASS_OF"] !== ''
		&& $arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["METHOD_OF"] !== ''
		&& method_exists(
			$arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["CLASS_OF"],
			$arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["METHOD_OF"]
		)
	)
	{
		$arOfEntities = call_user_func(array($arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["CLASS_OF"], $arSocNetAllowedSubscribeEntityTypesDesc[$arLog["ENTITY_TYPE"]]["METHOD_OF"]), $arLog["ENTITY_ID"]);
	}
	else
	{
		$arOfEntities = false;
	}

	$hasAccessAll = false;


	$arUserIdToPush = ($arFields["USERS_TO_PUSH"] ?? []);

	CSocNetLog::CounterIncrement(array(
		'ENTITY_ID' => $arLog["ID"],
		'EVENT_ID' => $arLog["EVENT_ID"],
		'OF_ENTITIES' => $arOfEntities,
		'TYPE' => CSocNetLogCounter::TYPE_LOG_ENTRY,
		'FOR_ALL_ACCESS' => $hasAccessAll,
		'USERS_TO_PUSH' => (
			$hasAccessAll
			|| empty($arUserIdToPush)
			|| count($arUserIdToPush) > 20
				? []
				: $arUserIdToPush
		)
	));

	return true;
}