• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/iblocksocnetbizproc.php
  • Класс: CIBlockDocumentWebdavSocnet
  • Вызов: CIBlockDocumentWebdavSocnet::GetDocumentForHistory
static function GetDocumentForHistory($documentId, $historyIndex, $update = false)
{
	$documentId = intval($documentId);
	if ($documentId <= 0)
		throw new CBPArgumentNullException("documentId");

	$diskId = self::processGetDiskIdByDocId($documentId);
	if($diskId !== null)
	{
		return self::proxyToDisk(__FUNCTION__, array($diskId, $historyIndex, $update));
	}

	$arResult = null;

	$dbDocumentList = CIBlockElement::GetList(
		array(),
		array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y")
	);
	if ($objDocument = $dbDocumentList->GetNextElement())
	{
		$arDocumentFields = $objDocument->GetFields();
		$arDocumentProperties = $objDocument->GetProperties();

		$arResult["NAME"] = $arDocumentFields["~NAME"];

		$arResult["FIELDS"] = array();
		foreach ($arDocumentFields as $fieldKey => $fieldValue)
		{
			if ($fieldKey == "~PREVIEW_PICTURE" || $fieldKey == "~DETAIL_PICTURE")
			{
				$arResult["FIELDS"][mb_substr($fieldKey, 1)] = CBPDocument::PrepareFileForHistory(
					array("webdav", "CIBlockDocumentWebdavSocnet", $documentId),
					$fieldValue,
					$historyIndex
				);
			}
			elseif (mb_substr($fieldKey, 0, 1) == "~")
			{
				$arResult["FIELDS"][mb_substr($fieldKey, 1)] = $fieldValue;
			}
		}

		$arResult["PROPERTIES"] = array();
		foreach ($arDocumentProperties as $propertyKey => $propertyValue)
		{
			if ($propertyValue["USER_TYPE"] <> '')
			{
				$arResult["PROPERTIES"][$propertyKey] = array(
					"VALUE" => $propertyValue["VALUE"],
					"DESCRIPTION" => $propertyValue["DESCRIPTION"]
				);
			}
			elseif ($propertyValue["PROPERTY_TYPE"] == "L")
			{
				$arResult["PROPERTIES"][$propertyKey] = array(
					"VALUE" => $propertyValue["VALUE_ENUM_ID"],
					"DESCRIPTION" => $propertyValue["DESCRIPTION"]
				);
			}
			elseif ($propertyValue["PROPERTY_TYPE"] == "F" && $propertyKey == 'FILE') // primary webdav file
			{
				$arDocID = $documentId;
				if (!is_array($documentId))
					$arDocID = array("webdav", "CIBlockDocumentWebdavSocnet", $documentId);

				$arResult['PROPERTIES'][$propertyKey] = CWebdavDocumentHistory::GetFileForHistory($arDocID, $propertyValue, $historyIndex);
				$arResult['OLD_FILE_ID'] = $propertyValue['VALUE']; //for historical comment.

				if ($update)
					$historyGlueState = CWebdavDocumentHistory::GetHistoryState($arDocID, null, null, array('CHECK_TIME'=>'Y'));
				else
					$historyGlueState = CWebdavDocumentHistory::GetHistoryState($arDocID, null, null, array('NEW'=>'Y', 'CHECK_TIME'=>'Y'));

				$arResult['PROPERTIES'][$propertyKey]['HISTORYGLUE'] = $historyGlueState;
			}
			elseif ($propertyValue["PROPERTY_TYPE"] == "F")
			{
				$arResult["PROPERTIES"][$propertyKey] = array(
					"VALUE" => CBPDocument::PrepareFileForHistory(
						array("webdav", "CIBlockDocumentWebdavSocnet", $documentId),
						$propertyValue["VALUE"],
						$historyIndex
					),
					"DESCRIPTION" => $propertyValue["DESCRIPTION"]
				);
			}
			else
			{
				$arResult["PROPERTIES"][$propertyKey] = array(
					"VALUE" => $propertyValue["VALUE"],
					"DESCRIPTION" => $propertyValue["DESCRIPTION"]
				);
			}
		}
	}

	return $arResult;
}