• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/user.php
  • Класс: CAllSocNetUser
  • Вызов: CAllSocNetUser::CheckContext
static function CheckContext($currentUserId = false, $userId = false, $arContext = array())
{
	if (
		(int)$currentUserId <= 0
		|| (int)$userId <= 0
		|| !is_array($arContext)
		|| empty($arContext["ENTITY_TYPE"])
		|| empty($arContext["ENTITY_ID"])
	)
	{
		return false;
	}

	if ($arContext["ENTITY_TYPE"] === "LOG_ENTRY")
	{
		$dbRes = CSocNetLogRights::GetList(
			array(),
			array(
				"LOG_ID" => (int)$arContext["ENTITY_ID"]
			)
		);

		$arLogEntryUserId = $arSonetGroupId = $arDepartmentId = array();
		$bIntranetInstalled = ModuleManager::IsModuleInstalled('intranet');

		while ($arRes = $dbRes->Fetch())
		{
			if (preg_match('/^U(d+)$/', $arRes["GROUP_CODE"], $matches))
			{
				$arLogEntryUserId[] = $matches[1];
			}
			elseif (
				preg_match('/^SG(d+)$/', $arRes["GROUP_CODE"], $matches)
				|| preg_match('/^SG(d+)_'.SONET_ROLES_USER.'$/', $arRes["GROUP_CODE"], $matches)
				&& !in_array($matches[1], $arSonetGroupId)
			)
			{
				$arSonetGroupId[] = $matches[1];
			}
			elseif (
				$bIntranetInstalled
				&& preg_match('/^DR(d+)$/', $arRes["GROUP_CODE"], $matches)
				&& !in_array($matches[1], $arDepartmentId)
			)
			{
				$arDepartmentId[] = $matches[1];
			}
			elseif ($arRes["GROUP_CODE"] === 'G2')
			{
				if (!empty($arContext['SITE_ID']))
				{
					$arLogSite = array();
					$rsSite = CSocNetLog::GetSite((int)$arContext["ENTITY_ID"]);
					while ($arSite = $rsSite->Fetch())
					{
						$arLogSite[] = $arSite["SITE_ID"];
					}

					return in_array($arContext['SITE_ID'], $arLogSite);
				}
			}
		}

		if (
			in_array($currentUserId, $arLogEntryUserId)
			&& in_array($userId, $arLogEntryUserId)
		)
		{
			return true;
		}

		if (in_array($userId, $arLogEntryUserId))
		{
			if (!empty($arSonetGroupId))
			{
				foreach($arSonetGroupId as $groupId)
				{
					if (CSocNetUserToGroup::GetUserRole($currentUserId, $groupId) <= SONET_ROLES_USER)
					{
						return true;
					}
				}
			}

			if (
				!empty($arDepartmentId)
				&& Loader::includeModule('intranet')
			)
			{
				$arDepartmentUserId = array();

				$rsDepartmentUserId = BitrixIntranetUtil::getDepartmentEmployees(array(
					'DEPARTMENTS' => $arDepartmentId,
					'RECURSIVE' => 'Y',
					'ACTIVE' => 'Y',
					'CONFIRMED' => 'Y',
					'SELECT' => array('ID')
				));

				while ($arUser = $rsDepartmentUserId->Fetch())
				{
					$arDepartmentUserId[] = $arUser["ID"];
				}

				if (in_array($currentUserId, $arDepartmentUserId))
				{
					return true;
				}
			}
		}

		$rsLog = CSocNetLog::GetList(
			array(),
			array(
				"ID" => (int)$arContext["ENTITY_ID"]
			),
			false,
			false,
			array(
				"USER_ID"
			)
		);
		if ($arLog = $rsLog->Fetch())
		{
			return (
				(
					in_array($currentUserId, $arLogEntryUserId)
					&& ($userId == $arLog["USER_ID"])
				)
				|| (
					in_array($userId, $arLogEntryUserId)
					&& ($currentUserId == $arLog["USER_ID"])
				)
			);
		}
	}

	return false;
}