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

	$arResult = null;

	$arDocFilter = array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y");
	$dbDoc = CIBlockElement::GetList(
		array(),
		$arDocFilter,
		false,
		false,
		array('IBLOCK_ID')
	);
	if ($arDoc = $dbDoc->Fetch())
	{
		$arDocFilter['IBLOCK_ID'] = $arDoc['IBLOCK_ID']; // required for iblock 2.0
	}
	
	$dbDocumentList = CIBlockElement::GetList(
		array(),
		$arDocFilter
	);
	if ($objDocument = $dbDocumentList->GetNextElement())
	{
		$arDocumentFields = $objDocument->GetFields();
		$arDocumentProperties = $objDocument->GetProperties();

		if($dfile = self::needProxyToDiskByDocProp($arDocumentProperties, $arDocumentFields))
		{
			return self::proxyToDisk(__FUNCTION__, array($dfile->getId(), $historyIndex, $update));
		}

		$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", "CIBlockDocumentWebdav", $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", "CIBlockDocumentWebdav", $documentId);

				$arResult['PROPERTIES'][$propertyKey] = CWebdavDocumentHistory::GetFileForHistory($arDocID, $propertyValue, $historyIndex);

				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", "CIBlockDocumentWebdav", $documentId),
						$propertyValue["VALUE"],
						$historyIndex
					),
					"DESCRIPTION" => $propertyValue["DESCRIPTION"]
				);
			}
			else
			{
				$arResult["PROPERTIES"][$propertyKey] = array(
					"VALUE" => $propertyValue["VALUE"],
					"DESCRIPTION" => $propertyValue["DESCRIPTION"]
				);
			}
		}
	}

	return $arResult;
}