• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/group_features_perms.php
  • Класс: CAllSocNetFeaturesPerms
  • Вызов: CAllSocNetFeaturesPerms::SetPerm
static function SetPerm($featureID, $operation, $perm)
{
	global $APPLICATION;

	$arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();

	$featureID = intval($featureID);
	$operation = Trim($operation);
	$perm = Trim($perm);

	$dbResult = CSocNetFeaturesPerms::GetList(
		array(),
		array(
			"FEATURE_ID" => $featureID,
			"OPERATION_ID" => $operation,
		),
		false,
		false,
		array("ID", "FEATURE_ENTITY_TYPE", "FEATURE_ENTITY_ID", "FEATURE_FEATURE", "OPERATION_ID", "ROLE")
	);

	if ($arResult = $dbResult->Fetch())
	{
		$r = CSocNetFeaturesPerms::Update($arResult["ID"], array("ROLE" => $perm));
	}
	else
	{
		$r = CSocNetFeaturesPerms::Add(array("FEATURE_ID" => $featureID, "OPERATION_ID" => $operation, "ROLE" => $perm));
	}

	if (!$r)
	{
		$errorMessage = "";
		if ($e = $APPLICATION->GetException())
		{
			$errorMessage = $e->GetString();
		}

		if ($errorMessage == '')
		{
			$errorMessage = GetMessage("SONET_GF_ERROR_SET").".";
		}

		$APPLICATION->ThrowException($errorMessage, "ERROR_SET_RECORD");
		return false;
	}

	if (!$arResult)
	{
		$arFeature = CSocNetFeatures::GetByID($featureID);
		$entity_type = $arFeature["ENTITY_TYPE"];
		$entity_id = $arFeature["ENTITY_ID"];
		$feature = $arFeature["FEATURE"];
	}
	else
	{
		$entity_type = $arResult["FEATURE_ENTITY_TYPE"];
		$entity_id = $arResult["FEATURE_ENTITY_ID"];
		$feature = $arResult["FEATURE_FEATURE"];
	}

	if(empty($arResult) || $arResult["ROLE"] != $perm)
	{
		CSocNetSearch::SetFeaturePermissions(
			$entity_type,
			$entity_id,
			$feature,
			(
				$arResult
				&& $arResult["ROLE"] != $perm
					? $arResult["OPERATION_ID"]
					: $operation
			),
			$perm
		);
	}

	if (
		!in_array($feature, array("tasks", "files", "blog"))
		&& is_array($arSocNetFeaturesSettings[$feature]["subscribe_events"] ?? null))
	{
		$arEventsTmp = array_keys($arSocNetFeaturesSettings[$feature]["subscribe_events"]);
		$rsLog = CSocNetLog::GetList(
			array(),
			array(
				"ENTITY_TYPE" => $entity_type,
				"ENTITY_ID" => $entity_id,
				"EVENT_ID" => $arEventsTmp
			),
			false,
			false,
			array("ID", "EVENT_ID")
		);
		while($arLog = $rsLog->Fetch())
		{
			CSocNetLogRights::DeleteByLogID($arLog["ID"]);
			CSocNetLogRights::SetForSonet(
				$arLog["ID"],
				$entity_type,
				$entity_id,
				$feature,
				$arSocNetFeaturesSettings[$feature]["subscribe_events"][$arLog["EVENT_ID"]]["OPERATION"]
			);
		}
	}


	return $r;
}