当前位置: 首页>>代码示例>>PHP>>正文


PHP CSocNetUserRelations::Add方法代码示例

本文整理汇总了PHP中CSocNetUserRelations::Add方法的典型用法代码示例。如果您正苦于以下问题:PHP CSocNetUserRelations::Add方法的具体用法?PHP CSocNetUserRelations::Add怎么用?PHP CSocNetUserRelations::Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSocNetUserRelations的用法示例。


在下文中一共展示了CSocNetUserRelations::Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: BanUser

	function BanUser($senderUserID, $targetUserID)
	{
		global $APPLICATION, $DB;

		$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;
		}
		elseif (CSocNetUser::IsUserModuleAdmin($targetUserID, false))
		{
			$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UR_ERROR_CREATE_RELATION"), "ERROR_TARGET_USER_ID");
			return false;
		}

		$strSql =
			"SELECT UR.ID, UR.FIRST_USER_ID, UR.SECOND_USER_ID, UR.RELATION ".
			"FROM b_sonet_user_relations UR ".
			"WHERE UR.FIRST_USER_ID = ".$senderUserID." ".
			"	AND UR.SECOND_USER_ID = ".$targetUserID." ".
			"UNION ".
			"SELECT UR.ID, UR.FIRST_USER_ID, UR.SECOND_USER_ID, UR.RELATION ".
			"FROM b_sonet_user_relations UR ".
			"WHERE UR.FIRST_USER_ID = ".$targetUserID." ".
			"	AND UR.SECOND_USER_ID = ".$senderUserID." ";

		$dbResult = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
		if ($arResult = $dbResult->Fetch())
		{
			if ($arResult["RELATION"] != SONET_RELATIONS_BAN)
			{
				$arFields = array(
					"RELATION" => SONET_RELATIONS_BAN,
					"=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(),
				);
				if ($arResult["FIRST_USER_ID"] == $senderUserID)
					$arFields["INITIATED_BY"] = "F";
				else
					$arFields["INITIATED_BY"] = "S";

				if (CSocNetUserRelations::Update($arResult["ID"], $arFields))
				{
					$arMessageFields = array(
						"FROM_USER_ID" => $senderUserID,
						"TO_USER_ID" => $targetUserID,
						"MESSAGE" => GetMessage("SONET_UR_BANUSER_MESSAGE"),
						"=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(),
						"MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM
					);
					CSocNetMessages::Add($arMessageFields);

					if ($arResult["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 (StrLen($errorMessage) <= 0)
						$errorMessage = GetMessage("SONET_UR_ERROR_UPDATE_RELATION");

					$GLOBALS["APPLICATION"]->ThrowException($errorMessage, "ERROR_UPDATE_RELATION");
					return false;
				}
			}
			else
			{
				$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UR_ALREADY_BAN"), "ERROR_ALREADY_BAN");
				return false;
			}
		}
		else
		{
			$arFields = array(
				"FIRST_USER_ID" => $senderUserID,
				"SECOND_USER_ID" => $targetUserID,
				"RELATION" => SONET_RELATIONS_BAN,
				"=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(),
				"=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(),
				"INITIATED_BY" => "F",
			);
			if (CSocNetUserRelations::Add($arFields))
//.........这里部分代码省略.........
开发者ID:ASDAFF,项目名称:bitrix-5,代码行数:101,代码来源:user_relations.php


注:本文中的CSocNetUserRelations::Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。