• Модуль: lists
  • Путь к файлу: ~/bitrix/modules/lists/lib/bizprocdocument.php
  • Класс: BizprocDocument
  • Вызов: BizprocDocument::getDocument
static function getDocument($documentId)
{
	$documentId = intval($documentId);
	if ($documentId <= 0)
	{
		throw new CBPArgumentNullException('documentId');
	}

	$result = [];
	$element = [];
	$elementProperty = [];

	$queryElement = CIBlockElement::getList(
		[],
		['ID' => $documentId, 'SHOW_NEW' => 'Y', 'SHOW_HISTORY' => 'Y']
	);
	while ($queryResult = $queryElement->fetch())
	{
		$element = $queryResult;
		$queryProperty = CIBlockElement::getProperty(
			$queryResult['IBLOCK_ID'],
			$queryResult['ID'],
			['sort' => 'asc', 'id' => 'asc', 'enum_sort' => 'asc', 'value_id' => 'asc'],
			['ACTIVE' => 'Y', 'EMPTY' => 'N']
		);
		while ($property = $queryProperty->fetch())
		{
			$propertyKey = 'PROPERTY_' . $property['ID'];
			if ($property['MULTIPLE'] == 'Y')
			{
				if (!array_key_exists($propertyKey, $elementProperty))
				{
					$elementProperty[$propertyKey] = $property;
					$elementProperty[$propertyKey]['VALUE'] = [];
				}
				$elementProperty[$propertyKey]['VALUE'][] = $property['VALUE'];
			}
			else
			{
				$elementProperty[$propertyKey] = $property;
			}
		}
	}

	foreach ($element as $fieldId => $fieldValue)
	{
		$result[$fieldId] = $fieldValue;
		if (in_array($fieldId, ['MODIFIED_BY', 'CREATED_BY']))
		{
			$result[$fieldId] = 'user_' . $fieldValue;
			$result[$fieldId . '_PRINTABLE'] =
				$element[($fieldId == 'MODIFIED_BY')
					? 'USER_NAME'
					: 'CREATED_USER_NAME']
			;
		}
		elseif (in_array($fieldId, ['PREVIEW_TEXT', 'DETAIL_TEXT']))
		{
			if ($element[$fieldId . '_TYPE'] == 'html')
			{
				$result[$fieldId] = HTMLToTxt($fieldValue);
			}
		}
	}
	foreach ($elementProperty as $propertyId => $property)
	{
		if (trim($property['CODE']) <> '')
		{
			$propertyId = $property['CODE'];
		}
		else
		{
			$propertyId = $property['ID'];
		}

		if (!empty($property['USER_TYPE']))
		{
			if (
				$property['USER_TYPE'] == 'UserID'
				|| $property['USER_TYPE'] == 'employee'
				&& (COption::getOptionString('bizproc', 'employee_compatible_mode', 'N') != 'Y')
			)
			{
				if (empty($property['VALUE']))
				{
					continue;
				}
				if (!is_array($property['VALUE']))
				{
					$property['VALUE'] = [$property['VALUE']];
				}

				$listUsers = implode(' | ', $property['VALUE']);
				$userQuery = CUser::getList(
					'ID',
					'ASC',
					['ID' => $listUsers],
					[
						'FIELDS' => ['ID', 'LOGIN', 'NAME', 'LAST_NAME'],
					]
				);
				while ($user = $userQuery->fetch())
				{
					if ($property['MULTIPLE'] == 'Y')
					{
						$result = self::setArray($result, 'PROPERTY_' . $propertyId);
						$result = self::setArray($result, 'PROPERTY_' . $propertyId . '_PRINTABLE');
						$result['PROPERTY_' . $propertyId][] = 'user_' . intval($user['ID']);
						$result['PROPERTY_' . $propertyId . '_PRINTABLE'][] = '(' . $user['LOGIN'] . ')' .
							(($user['NAME'] <> '' || $user['LAST_NAME'] <> '') ? ' ' : '') . $user['NAME'] .
							(($user['NAME'] <> '' && $user['LAST_NAME'] <> '') ? ' ' : '') . $user['LAST_NAME'];
					}
					else
					{
						$result['PROPERTY_' . $propertyId] = 'user_' . intval($user['ID']);
						$result['PROPERTY_' . $propertyId . '_PRINTABLE'] = '(' . $user['LOGIN'] . ')' .
							(($user['NAME'] <> '' || $user['LAST_NAME'] <> '') ? ' ' : '') . $user['NAME'] .
							(($user['NAME'] <> '' && $user['LAST_NAME'] <> '') ? ' ' : '') . $user['LAST_NAME'];
					}
				}
			}
			elseif ($property['USER_TYPE'] == 'DiskFile')
			{
				$diskValues = current($property['VALUE']);
				$userType = CIBlockProperty::getUserType($property['USER_TYPE']);
				if (is_array($diskValues))
				{
					$result = self::setArray($result, 'PROPERTY_' . $propertyId);
					$result = self::setArray($result, 'PROPERTY_' . $propertyId . '_PRINTABLE');
					foreach ($diskValues as $attachedId)
					{
						$fileId = null;
						if (array_key_exists('GetObjectId', $userType))
						{
							$fileId = call_user_func_array($userType['GetObjectId'], [$attachedId]);
						}
						if (!$fileId)
						{
							continue;
						}
						$printableUrl = '';
						if (array_key_exists('GetUrlAttachedFileElement', $userType))
						{
							$printableUrl = call_user_func_array(
								$userType['GetUrlAttachedFileElement'],
								[$documentId, $fileId]
							);
						}

						$result['PROPERTY_' . $propertyId][$attachedId] = $fileId;
						$result['PROPERTY_' . $propertyId . '_PRINTABLE'][$attachedId] = $printableUrl;
					}
				}
				else
				{
					continue;
				}
			}
			elseif ($property['USER_TYPE'] == 'HTML')
			{
				if (CBPHelper::isAssociativeArray($property['VALUE']))
				{
					if ($property['VALUE']['TYPE'] == 'HTML')
					{
						$result['PROPERTY_' . $propertyId] = HTMLToTxt($property['VALUE']['TEXT']);
					}
					else
					{
						$result['PROPERTY_' . $propertyId] = $property['VALUE']['TEXT'];
					}
				}
				else
				{
					$result = self::setArray($result, 'PROPERTY_' . $propertyId);
					foreach ($property['VALUE'] as $htmlValue)
					{
						if ($htmlValue['TYPE'] == 'HTML')
						{
							$result['PROPERTY_' . $propertyId][] = HTMLToTxt($htmlValue['TEXT']);
						}
						else
						{
							$result['PROPERTY_' . $propertyId][] = $htmlValue['TEXT'];
						}
					}
				}
			}
			elseif ($property['USER_TYPE'] == 'Money')
			{
				$userType = CIBlockProperty::getUserType($property['USER_TYPE']);
				if (is_array($property['VALUE']))
				{
					$result = self::setArray($result, 'PROPERTY_' . $propertyId);
					$result = self::setArray($result, 'PROPERTY_' . $propertyId . '_PRINTABLE');
					foreach ($property['VALUE'] as $moneyValue)
					{
						$result['PROPERTY_' . $propertyId][] = $moneyValue;
						if (array_key_exists('GetPublicViewHTML', $userType))
						{
							$result['PROPERTY_' . $propertyId . '_PRINTABLE'][] = call_user_func_array(
								$userType['GetPublicViewHTML'],
								[$property, ['VALUE' => $moneyValue], []]
							);
						}
					}
				}
				else
				{
					$result['PROPERTY_' . $propertyId] = $property['VALUE'];
					if (array_key_exists('GetPublicViewHTML', $userType))
					{
						$result['PROPERTY_' . $propertyId . '_PRINTABLE'] = call_user_func_array(
							$userType['GetPublicViewHTML'],
							[$property, ['VALUE' => $property['VALUE']], []]
						);
					}
				}
			}
			else
			{
				$result['PROPERTY_' . $propertyId] = $property['VALUE'];
			}
		}
		elseif ($property['PROPERTY_TYPE'] == 'L')
		{
			$result = self::setArray($result, 'PROPERTY_' . $propertyId);
			//$result = self::setArray($result, 'PROPERTY_'.$propertyId.'_PRINTABLE');
			$propertyArray = [];
			$propertyKeyArray = [];
			if (!is_array($property['VALUE']))
			{
				$property['VALUE'] = [$property['VALUE']];
			}
			foreach ($property['VALUE'] as $enumId)
			{
				$enumsObject = CIBlockProperty::getPropertyEnum(
					$property['ID'],
					['SORT' => 'asc'],
					['ID' => $enumId]
				);
				while ($enums = $enumsObject->fetch())
				{
					$propertyArray[] = $enums['VALUE'];
					$propertyKeyArray[] = $enums['XML_ID'];
				}
			}
			for ($i = 0, $cnt = count($propertyArray); $i < $cnt; $i++)
			{
				$result['PROPERTY_' . $propertyId][$propertyKeyArray[$i]] = $propertyArray[$i];
			}
		}
		elseif ($property['PROPERTY_TYPE'] == 'F')
		{
			$result = self::setArray($result, 'PROPERTY_' . $propertyId);
			$result = self::setArray($result, 'PROPERTY_' . $propertyId . '_PRINTABLE');
			$propertyArray = $property['VALUE'];
			if (!is_array($propertyArray))
			{
				$propertyArray = [$propertyArray];
			}

			foreach ($propertyArray as $v)
			{
				$fileArray = CFile::getFileArray($v);
				if ($fileArray)
				{
					$result['PROPERTY_' . $propertyId][] = intval($v);
					$result['PROPERTY_' . $propertyId . '_PRINTABLE'][] =
						"[url=/bitrix/tools/bizproc_show_file.php?f=" .
						urlencode($fileArray["FILE_NAME"]) . "&i=" . $v . "&h=" . md5($fileArray["SUBDIR"]) . "]" .
						htmlspecialcharsbx($fileArray["ORIGINAL_NAME"]) . "[/url]";
				}
			}
		}
		else
		{
			$result['PROPERTY_' . $propertyId] = $property['VALUE'];
		}
	}

	if (!empty($result))
	{
		$documentFields = static::getDocumentFields(static::getDocumentType($documentId));
		foreach ($documentFields as $fieldKey => $field)
		{
			if (!array_key_exists($fieldKey, $result))
			{
				$result[$fieldKey] = null;
			}
		}
	}

	return $result;
}