• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/subscription.php
  • Класс: CAllSocNetSubscription
  • Вызов: CAllSocNetSubscription::IsUserSubscribed
static function IsUserSubscribed($userID, $code): bool
{
	global $CACHE_MANAGER;

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

	$code = trim($code);
	if ($code == '')
	{
		return false;
	}

	$cache = new CPHPCache;
	$cache_time = 31536000;
	$cache_id = "entity_".$code;
	$cache_path = "/sonet/subscription/";

	if ($cache->InitCache($cache_time, $cache_id, $cache_path))
	{
		$arCacheVars = $cache->GetVars();
		$arSubscriberID = $arCacheVars["arSubscriberID"];
	}
	else
	{
		$cache->StartDataCache($cache_time, $cache_id, $cache_path);
		$arSubscriberID = array();

		$rsSubscription = CSocNetSubscription::GetList(
			array(),
			array("CODE" => $code)
		);

		while ($arSubscription = $rsSubscription->Fetch())
			$arSubscriberID[] = $arSubscription["USER_ID"];

		if (defined("BX_COMP_MANAGED_CACHE"))
		{
			$CACHE_MANAGER->StartTagCache($cache_path);
			$CACHE_MANAGER->RegisterTag("sonet_subscription_".$code);
			$CACHE_MANAGER->RegisterTag("sonet_group");
		}

		$arCacheData = Array(
			"arSubscriberID" => $arSubscriberID
		);
		$cache->EndDataCache($arCacheData);

		if(defined("BX_COMP_MANAGED_CACHE"))
		{
			$CACHE_MANAGER->EndTagCache();
		}
	}

	return (in_array($userID, $arSubscriberID));
}