• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools.php
  • Класс: CSocNetLogComponent
  • Вызов: CSocNetLogComponent::getCommentByRequest
static function getCommentByRequest($commentId, $postId, $action = false, $checkPerms = true, $checkAdminSession = true)
{
	global $USER_FIELD_MANAGER;

	$commentId = (int)$commentId;
	$postId = (int)$postId;

	$arOrder = array();

	$rsLog = CSocNetLog::GetList(
		array(),
		array(
			"ID" => $postId
		),
		false,
		false,
		array("EVENT_ID", "SOURCE_ID", "ENTITY_ID")
	);

	if ($arLog = $rsLog->Fetch())
	{
		$hasSource = ComponentHelper::hasCommentSource(array(
			"LOG_EVENT_ID" => $arLog["EVENT_ID"],
			"LOG_ENTITY_ID" => $arLog["ENTITY_ID"]
		));

		$arCommentEvent = CSocNetLogTools::FindLogCommentEventByLogEventID($arLog["EVENT_ID"]);

		$arFilter = array(
			"EVENT_ID" => $arCommentEvent["EVENT_ID"]
		);

		if ($hasSource)
		{
			$arFilter["SOURCE_ID"] = $commentId; // forum etc.
		}
		else
		{
			$arFilter["ID"] = $commentId; // socialnetwork
		}

		$dbRes = CSocNetLogComments::GetList(
			$arOrder,
			$arFilter,
			false,
			false,
			array("ID", "EVENT_ID", "MESSAGE", "USER_ID", "SOURCE_ID", "LOG_SOURCE_ID", "UF_*")
		);

		if ($arRes = $dbRes->Fetch())
		{
			$arRes['MESSAGE'] = Emoji::decode($arRes['MESSAGE']);

			if ($checkPerms)
			{
				$bAllow = CSocNetLogComponent::canUserChangeComment(array(
					"ACTION" => $action,
					"LOG_ID" => $postId,
					"LOG_EVENT_ID" => $arLog["EVENT_ID"],
					"LOG_SOURCE_ID" => $arLog["SOURCE_ID"],
					"COMMENT_ID" => $arRes["ID"],
					"COMMENT_USER_ID" => $arRes["USER_ID"],
					"CHECK_ADMIN_SESSION" => ($checkAdminSession ? "Y" : "N")
				));
			}
			else
			{
				$bAllow = true;
			}

			if (!$bAllow)
			{
				$arRes = false;
			}
			else
			{
				if ($action === "edit") // data needed only for edit
				{
					$arUFMeta = $USER_FIELD_MANAGER->GetUserFields("SONET_COMMENT", 0, LANGUAGE_ID);
					$arRes["UF"] = array();

					foreach($arUFMeta as $field_name => $arUF)
					{
						if (
							array_key_exists($field_name, $arRes)
							&& !empty($arRes[$field_name])
						)
						{
							$arRes["UF"][$field_name] = $arUFMeta[$field_name];
							$arRes["UF"][$field_name]["VALUE"] = $arRes[$field_name];
							$arRes["UF"][$field_name]["ENTITY_VALUE_ID"] = $arRes["ID"];
							unset($arRes[$field_name]);
						}
					}
				}
			}
		}

		return $arRes;
	}

	return false;
}