• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/user_relations.php
  • Класс: CAllSocNetUserRelations
  • Вызов: CAllSocNetUserRelations::DeleteRelation
static function DeleteRelation($senderUserID, $targetUserID)
{
	global $APPLICATION;

	$senderUserID = intval($senderUserID);
	if ($senderUserID <= 0)
	{
		$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UR_EMPTY_SENDER_USER_ID"), "ERROR_SENDER_USER_ID");
		return false;
	}

	$targetUserID = intval($targetUserID);
	if ($targetUserID <= 0)
	{
		$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UR_EMPTY_TARGET_USER_ID"), "ERROR_TARGET_USER_ID");
		return false;
	}

	$arRelation = CSocNetUserRelations::GetByUserID($senderUserID, $targetUserID);
	if (!$arRelation)
	{
		$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UR_RELATION_NOT_FOUND"), "ERROR_RELATION_NOT_FOUND");
		return false;
	}

	if (CSocNetUserRelations::Delete($arRelation["ID"]))
	{
		if (CModule::IncludeModule("im"))
		{
			$rsUser = CUser::GetByID($senderUserID);
			if ($arUser = $rsUser->Fetch())
			{
				switch ($arUser["PERSONAL_GENDER"])
				{
					case "M":
						$gender_suffix = "_M";
						break;
					case "F":
						$gender_suffix = "_F";
							break;
					default:
						$gender_suffix = "";
				}
			}

			$arMessageFields = array(
				"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
				"FROM_USER_ID" => $senderUserID,
				"TO_USER_ID" => $targetUserID,
				"NOTIFY_TYPE" => IM_NOTIFY_FROM,
				"NOTIFY_MODULE" => "socialnetwork",
				"NOTIFY_EVENT" => "inout_user",
				"NOTIFY_TAG" => "SOCNET|FRIENDS|".intval($arRelation["ID"]),
				"NOTIFY_MESSAGE" => GetMessage("SONET_UR_IM_UNFRIEND".$gender_suffix),
			);
			CIMNotify::Add($arMessageFields);
		}

		if ($arRelation["RELATION"] == SONET_RELATIONS_FRIEND)
			$GLOBALS["DB"]->Query("DELETE FROM b_sonet_event_user_view WHERE
				ENTITY_TYPE = '".SONET_ENTITY_USER."'
				AND (
					(USER_ID = ".$arRelation["FIRST_USER_ID"]." AND ENTITY_ID = ".$arRelation["SECOND_USER_ID"].")
					OR (USER_ID = ".$arRelation["SECOND_USER_ID"]." AND ENTITY_ID = ".$arRelation["FIRST_USER_ID"].")
					OR (ENTITY_ID = ".$arRelation["FIRST_USER_ID"]." AND USER_IM_ID = ".$arRelation["SECOND_USER_ID"].")
					OR (ENTITY_ID = ".$arRelation["SECOND_USER_ID"]." AND USER_IM_ID = ".$arRelation["FIRST_USER_ID"].")
					OR (USER_ID = ".$arRelation["FIRST_USER_ID"]." AND USER_IM_ID = ".$arRelation["SECOND_USER_ID"].")
					OR (USER_ID = ".$arRelation["SECOND_USER_ID"]." AND USER_IM_ID = ".$arRelation["FIRST_USER_ID"].")
				)", true);
	}
	else
	{
		$errorMessage = "";
		if ($e = $APPLICATION->GetException())
			$errorMessage = $e->GetString();
		if ($errorMessage == '')
			$errorMessage = GetMessage("SONET_UR_RELATION_DELETE_ERROR");

		$GLOBALS["APPLICATION"]->ThrowException($errorMessage, "ERROR_DELETE_RELATION");
		return false;
	}

	CSocNetUserRelations::__SpeedFileCheckMessages($senderUserID);

	return true;
}