• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools.php
  • Класс: CSocNetLogTools
  • Вызов: CSocNetLogTools::GetDestinationFromRights
static function GetDestinationFromRights($arRights, $arParams)
{
	if (empty($arRights))
	{
		return array();
	}

	$arDestination = array();
	$arSonetGroups = array();

	$arRights = array_unique($arRights);

	$bAll = false;
	$arParams["DESTINATION_LIMIT"] = ((int)$arParams["DESTINATION_LIMIT"] <= 0 ? 3 : $arParams["DESTINATION_LIMIT"]);
	$bCheckPermissions = (!array_key_exists("CHECK_PERMISSIONS_DEST", $arParams) || $arParams["CHECK_PERMISSIONS_DEST"] !== 'N');

	foreach ($arRights as $right_tmp)
	{
		if ($right_tmp === "G1" && count($arRights) > 1)
		{
			continue;
		}

		if (in_array($right_tmp, array("G2", "AU")))
		{
			if ($bAll)
			{
				continue;
			}

			$arDestination[] = $right_tmp;
			$bAll = true;
		}
		elseif (preg_match('/^G(d+)$/', $right_tmp, $matches))
		{
			$arDestination[] = $matches[1];
		}
		elseif (preg_match('/^U(d+)$/', $right_tmp, $matches))
		{
			if (
				array_key_exists("CREATED_BY", $arParams)
				&& (int)$arParams["CREATED_BY"] > 0
				&& $arParams["CREATED_BY"] == $matches[1]
			)
			{
				continue;
			}

			$arDestination[] = $right_tmp;
		}
		elseif (
			preg_match('/^D(d+)$/', $right_tmp, $matches)
			|| preg_match('/^DR(d+)$/', $right_tmp, $matches)
		)
		{
			$arDestination[] = $right_tmp;
		}
		elseif (
			preg_match('/^SG(d+)_'.SONET_ROLES_USER.'$/', $right_tmp, $matches)
			|| preg_match('/^SG(d+)$/', $right_tmp, $matches)
		)
		{
			if (
				array_key_exists($matches[1], $arSonetGroups)
				&& is_array($arSonetGroups[$matches[1]])
				&& in_array(SONET_ROLES_USER, $arSonetGroups[$matches[1]], true)
			)
			{
				continue;
			}

			// already cached
			$arSonetGroup = CSocNetGroup::GetByID($matches[1], $bCheckPermissions);
			if ($arSonetGroup)
			{
				$arDestination[] = "SG".$matches[1];

				if (!array_key_exists($arSonetGroup["ID"], $arSonetGroups))
				{
					$arSonetGroups[$arSonetGroup["ID"]] = array();
				}
				$arSonetGroups[$arSonetGroup["ID"]][] = SONET_ROLES_USER;
			}
		}
		elseif (preg_match('/^SG(d+)_'.SONET_ROLES_MODERATOR.'$/', $right_tmp, $matches))
		{
			if (!in_array("SG".$matches[1]."_".SONET_ROLES_USER, $arRights))
			{
				$arSonetGroup = CSocNetGroup::GetByID($matches[1], $bCheckPermissions);
				if ($arSonetGroup)
				{
					$arDestination[] = "SG".$matches[1];

					if (!array_key_exists($arSonetGroup["ID"], $arSonetGroups))
					{
						$arSonetGroups[$arSonetGroup["ID"]] = [];
					}

					$arSonetGroups[$arSonetGroup["ID"]][] = SONET_ROLES_MODERATOR;
				}
			}
		}
		elseif (preg_match('/^SG(d+)_'.SONET_ROLES_OWNER.'$/', $right_tmp, $matches))
		{
			if (
				!in_array("SG" . $matches[1] . "_" . SONET_ROLES_USER, $arRights, true)
				&& !in_array("SG" . $matches[1] . "_" . SONET_ROLES_MODERATOR, $arRights, true)
			)
			{
				$arSonetGroup = CSocNetGroup::GetByID($matches[1], $bCheckPermissions);
				if ($arSonetGroup)
				{
					$arDestination[] = "SG".$matches[1];

					if (!array_key_exists($arSonetGroup["ID"], $arSonetGroups))
					{
						$arSonetGroups[$arSonetGroup["ID"]] = [];
					}

					$arSonetGroups[$arSonetGroup["ID"]][] = SONET_ROLES_OWNER;
				}
			}
		}
	}

	return $arDestination;
}