Beispiel #1
0
 public static function Delete($ID, $bSetSource = false)
 {
     global $DB;
     $ID = IntVal($ID);
     if ($ID <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GLC_WRONG_PARAMETER_ID"), "ERROR_NO_ID");
         return false;
     }
     $bSuccess = false;
     if ($arComment = CSocNetLogComments::GetByID($ID)) {
         if ($bSetSource) {
             if (strlen($arComment["EVENT_ID"]) > 0) {
                 $arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arComment["EVENT_ID"]);
                 if (!$arCommentEvent || !array_key_exists("DELETE_CALLBACK", $arCommentEvent) || !is_callable($arCommentEvent["DELETE_CALLBACK"])) {
                     $bSetSource = false;
                 }
             }
         }
         $bSuccess = true;
         if ($bSetSource) {
             $arSource = CSocNetLogComments::SetSource($arComment, "DELETE");
         }
         if (!$bSetSource || is_array($arSource) && (!isset($arSource["ERROR"]) || empty($arSource["ERROR"]))) {
             if ($bSuccess) {
                 $bSuccess = $DB->Query("DELETE FROM b_sonet_log_comment WHERE ID = " . $ID . "", true);
             }
             if ($bSuccess) {
                 $GLOBALS["USER_FIELD_MANAGER"]->Delete("SONET_COMMENT", $ID);
                 $db_events = GetModuleEvents("socialnetwork", "OnSocNetLogCommentDelete");
                 while ($arEvent = $db_events->Fetch()) {
                     ExecuteModuleEventEx($arEvent, array($ID));
                 }
                 if (intval($arComment["LOG_ID"]) > 0) {
                     CSocNetLogComments::UpdateLogData($arComment["LOG_ID"], false, true);
                     $cache = new CPHPCache();
                     $cache->CleanDir("/sonet/log/" . intval(intval($arComment["LOG_ID"]) / 1000) . "/" . $arComment["LOG_ID"] . "/comments/");
                 }
             }
         } elseif (is_array($arSource) && isset($arSource["ERROR"]) && is_string($arSource["ERROR"]) && !empty($arSource["ERROR"])) {
             $GLOBALS["APPLICATION"]->ThrowException($arSource["ERROR"], "ERROR_DELETE_SOURCE");
             $bSuccess = false;
         }
     }
     return $bSuccess;
 }
Beispiel #2
0
 public static function Delete($ID, $bSetSource = false)
 {
     global $DB;
     $ID = IntVal($ID);
     if ($ID <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GLC_WRONG_PARAMETER_ID"), "ERROR_NO_ID");
         return false;
     }
     $bSuccess = false;
     if ($arComment = CSocNetLogComments::GetByID($ID)) {
         if ($bSetSource) {
             if (strlen($arComment["EVENT_ID"]) > 0) {
                 $arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arComment["EVENT_ID"]);
                 if (!$arCommentEvent || !array_key_exists("DELETE_CALLBACK", $arCommentEvent) || !is_callable($arCommentEvent["DELETE_CALLBACK"])) {
                     $bSetSource = false;
                 }
             }
         }
         $bSuccess = true;
         if ($bSetSource) {
             $arSource = CSocNetLogComments::SetSource($arComment, "DELETE");
         }
         if (!$bSetSource || is_array($arSource) && (!isset($arSource["ERROR"]) || empty($arSource["ERROR"]))) {
             if ($bSuccess) {
                 $bSuccess = $DB->Query("DELETE FROM b_sonet_log_comment WHERE ID = " . $ID . "", true);
             }
             if ($bSuccess) {
                 $GLOBALS["USER_FIELD_MANAGER"]->Delete("SONET_COMMENT", $ID);
             }
             if ($bSuccess && intval($arComment["LOG_ID"]) > 0) {
                 CSocNetLogComments::UpdateLogData($arComment["LOG_ID"], false, true);
             }
             if ($bSuccess && defined("BX_COMP_MANAGED_CACHE")) {
                 $GLOBALS["CACHE_MANAGER"]->ClearByTag("SONET_LOG_COMMENT_" . $ID);
             }
         } elseif (is_array($arSource) && isset($arSource["ERROR"]) && is_string($arSource["ERROR"]) && !empty($arSource["ERROR"])) {
             $GLOBALS["APPLICATION"]->ThrowException($arSource["ERROR"], "ERROR_DELETE_SOURCE");
             $bSuccess = false;
         }
     }
     return $bSuccess;
 }
	function Update($ID, $arFields, $bSetSource = false)
	{
		global $DB;

		$ID = IntVal($ID);
		if ($ID <= 0)
		{
			$GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_LC_WRONG_PARAMETER_ID"), "ERROR_NO_ID");
			return false;
		}

		if ($bSetSource)
		{
			if (strlen($arFields["EVENT_ID"]) > 0)
			{
				$arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arFields["EVENT_ID"]);
				if (
					!$arCommentEvent
					|| !array_key_exists("UPDATE_CALLBACK", $arCommentEvent)
					|| !is_callable($arCommentEvent["UPDATE_CALLBACK"])
				)
				{
					$bSetSource = false;
				}
			}

			if (
				!isset($arFields["SOURCE_ID"])
				|| !isset($arFields["LOG_ID"])
			)
			{
				$rsRes = CSocNetLogComments::GetList(
					array(),
					array("ID" => $ID),
					false,
					false,
					array("LOG_ID", "SOURCE_ID")
				);
				if ($arRes = $rsRes->Fetch())
				{
					$arFields["SOURCE_ID"] = $arRes["SOURCE_ID"];
					$arFields["LOG_ID"] = $arRes["LOG_ID"];
				}
			}
			
			if (!isset($arFields["SOURCE_ID"]))
			{
				$bSetSource = false;
			}
		}

		$arFields1 = array();
		foreach ($arFields as $key => $value)
		{
			if (substr($key, 0, 1) == "=")
			{
				$arFields1[substr($key, 1)] = $value;
				unset($arFields[$key]);
			}
		}

		if ($bSetSource)
		{
			$arSource = CSocNetLogComments::SetSource($arFields, "UPDATE");

			if (
				isset($arSource["NO_SOURCE"]) 
				&& $arSource["NO_SOURCE"] == "Y"
			)
			{
				$bSetSource = false;
			}
			elseif (
				is_array($arSource)
				&& (
					isset($arSource["ERROR"])
					&& !empty($arSource["ERROR"])
				)
			)
			{
				return array(
					"ID" => false,
					"MESSAGE" => $arSource["ERROR"]
				);
			}
			else
			{
				if (
					isset($arSource["MESSAGE"]) 
					&& strlen($arSource["MESSAGE"]) > 0
				)
				{
					$arFields["MESSAGE"] = $arSource["MESSAGE"];
				}

				if (
					isset($arSource["TEXT_MESSAGE"]) 
					&& strlen($arSource["TEXT_MESSAGE"]) > 0
				)
				{
					$arFields["TEXT_MESSAGE"] = $arSource["TEXT_MESSAGE"];
				}

				if (
					isset($arSource["UF"]) 
					&& isset($arSource["UF"]["FILE"])
				)
				{
					if (!is_array($arSource["UF"]["FILE"]))
					{
						$arSource["UF"]["FILE"] = array($arSource["UF"]["FILE"]);
					}

					$arFields["UF_SONET_COM_FILE"] = $arSource["UF"]["FILE"];
				}

				if (
					isset($arSource["UF"]) 
					&& isset($arSource["UF"]["DOC"])
				)
				{
					if (!is_array($arSource["UF"]["DOC"]))
					{
						$arSource["UF"]["DOC"] = array($arSource["UF"]["DOC"]);
					}

					$arFields["UF_SONET_COM_DOC"] = $arSource["UF"]["DOC"];
				}
			}
		}

		if (!CSocNetLogComments::CheckFields("UPDATE", $arFields, $ID))
		{
			return false;
		}

		if (
			!$bSetSource
			|| (
				is_array($arSource)
				&& (
					!isset($arSource["ERROR"])
					|| empty($arSource["ERROR"])
				)
			)
		)
		{
			$strUpdate = $DB->PrepareUpdate("b_sonet_log_comment", $arFields);

			foreach ($arFields1 as $key => $value)
			{
				if (strlen($strUpdate) > 0)
					$strUpdate .= ", ";
				$strUpdate .= $key."=".$value." ";
			}

			if (strlen($strUpdate) > 0)
			{
				$strSql =
					"UPDATE b_sonet_log_comment SET ".
					"	".$strUpdate." ".
					"WHERE ID = ".$ID." ";
				$DB->Query($strSql, False, "File: ".__FILE__."<br>Line: ".__LINE__);

				$GLOBALS["USER_FIELD_MANAGER"]->Update("SONET_COMMENT", $ID, $arFields);

				if(defined("BX_COMP_MANAGED_CACHE"))
				{
					$GLOBALS["CACHE_MANAGER"]->ClearByTag("SONET_LOG_COMMENT_".$ID);
				}
			}
			elseif (!$GLOBALS["USER_FIELD_MANAGER"]->Update("SONET_COMMENT", $ID, $arFields))
			{
				$ID = False;
			}
		}
		else
		{
			$ID = False;
		}

		return $ID;
	}
 function Add($arFields, $bSetSource = false, $bSendEvent = true, $bSetLogUpDate = true)
 {
     global $DB;
     $arFields1 = array();
     foreach ($arFields as $key => $value) {
         if (substr($key, 0, 1) == "=") {
             $arFields1[substr($key, 1)] = $value;
             unset($arFields[$key]);
         }
     }
     if (!CSocNetLogComments::CheckFields("ADD", $arFields)) {
         return false;
     }
     $arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arFields["EVENT_ID"]);
     if (!$arCommentEvent || !array_key_exists("ADD_CALLBACK", $arCommentEvent) || !is_callable($arCommentEvent["ADD_CALLBACK"])) {
         $bSetSource = false;
     }
     $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetLogCommentAdd");
     while ($arEvent = $db_events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
             return false;
         }
     }
     if ($bSetSource) {
         $arSource = CSocNetLogComments::SetSource($arFields);
         if (intval($arSource["SOURCE_ID"]) > 0) {
             $arFields["SOURCE_ID"] = $arSource["SOURCE_ID"];
             if (array_key_exists("RATING_ENTITY_ID", $arSource) && array_key_exists("RATING_TYPE_ID", $arSource) && intval($arSource["RATING_ENTITY_ID"]) > 0 && strlen($arSource["RATING_TYPE_ID"]) > 0) {
                 $arFields["RATING_TYPE_ID"] = $arSource["RATING_TYPE_ID"];
                 $arFields["RATING_ENTITY_ID"] = $arSource["RATING_ENTITY_ID"];
             }
             if (isset($arSource["MESSAGE"]) && strlen($arSource["MESSAGE"]) > 0) {
                 $arFields["MESSAGE"] = $arSource["MESSAGE"];
             }
             if (isset($arSource["TEXT_MESSAGE"]) && strlen($arSource["TEXT_MESSAGE"]) > 0) {
                 $arFields["TEXT_MESSAGE"] = $arSource["TEXT_MESSAGE"];
             }
         } else {
             $strMessage = array_key_exists("ERROR", $arSource) && strlen($arSource["ERROR"]) > 0 ? $arSource["ERROR"] : (array_key_exists("NOTES", $arSource) && strlen($arSource["NOTES"]) > 0 ? $arSource["NOTES"] : "");
         }
     }
     if (!$bSetSource || is_array($arSource) && array_key_exists("SOURCE_ID", $arFields) && intval($arFields["SOURCE_ID"]) > 0) {
         $arInsert = $DB->PrepareInsert("b_sonet_log_comment", $arFields);
         foreach ($arFields1 as $key => $value) {
             if (strlen($arInsert[0]) > 0) {
                 $arInsert[0] .= ", ";
             }
             $arInsert[0] .= $key;
             if (strlen($arInsert[1]) > 0) {
                 $arInsert[1] .= ", ";
             }
             $arInsert[1] .= $value;
         }
         $ID = false;
         if (strlen($arInsert[0]) > 0) {
             $strSql = "INSERT INTO b_sonet_log_comment(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
             $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             $ID = IntVal($DB->LastID());
             if ($ID > 0) {
                 if (!array_key_exists("RATING_TYPE_ID", $arFields) || empty($arFields["RATING_TYPE_ID"])) {
                     CSocNetLogComments::Update($ID, array("RATING_TYPE_ID" => "LOG_COMMENT", "RATING_ENTITY_ID" => $ID));
                 }
                 CSocNetLogFollow::Set($arFields["USER_ID"], "L" . $arFields["LOG_ID"], "Y");
                 $rsLog = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array("ID", "USER_ID"));
                 if (($arLog = $rsLog->Fetch()) && intval($arLog["USER_ID"]) > 0) {
                     $default_follow = CSocNetLogFollow::GetDefaultValue($arLog["USER_ID"]);
                     if ($default_follow != "Y") {
                         $rsLogFollow = CSocNetLogFollow::GetList(array("USER_ID" => $arLog["USER_ID"], "CODE" => "L" . $arFields["LOG_ID"]), array("TYPE"));
                         $arLogFoillow = $rsLogFollow->Fetch();
                         if (!$arLogFoillow) {
                             CSocNetLogFollow::Set($arLog["USER_ID"], "L" . $arFields["LOG_ID"], "Y");
                         }
                     }
                 }
                 if ($bSendEvent) {
                     CSocNetLogComments::SendEvent($ID, "SONET_NEW_EVENT");
                 }
                 CSocNetLogComments::UpdateLogData($arFields["LOG_ID"], $bSetLogUpDate);
                 $db_events = GetModuleEvents("socialnetwork", "OnAfterSocNetLogCommentAdd");
                 while ($arEvent = $db_events->Fetch()) {
                     ExecuteModuleEventEx($arEvent, array($ID, $arFields));
                 }
                 if (defined("BX_COMP_MANAGED_CACHE")) {
                     $GLOBALS["CACHE_MANAGER"]->ClearByTag("SONET_LOG_" . $arFields["LOG_ID"]);
                 }
             }
         }
         CSocNetLogTools::SetCacheLastLogID("comment", $ID);
         return $ID;
     } elseif ($bSetSource && strlen($strMessage) > 0) {
         return array("ID" => false, "MESSAGE" => $strMessage);
     } else {
         return false;
     }
 }