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

	$result = array();
	$element = array();
	$elementProperty = array();

	$queryElement = CIBlockElement::getList(array(),
		array('ID' => $documentId, 'SHOW_NEW'=>'Y', 'SHOW_HISTORY' => 'Y'));
	while($queryResult= $queryElement->fetch())
	{
		$element = $queryResult;
		$queryProperty = CIBlockElement::getProperty(
			$queryResult['IBLOCK_ID'],
			$queryResult['ID'],
			array('sort'=>'asc', 'id'=>'asc', 'enum_sort'=>'asc', 'value_id'=>'asc'),
			array('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'] = array();
				}
				$elementProperty[$propertyKey]['VALUE'][] = $property['VALUE'];
			}
			else
			{
				$elementProperty[$propertyKey] = $property;
			}
		}
	}

	foreach($element as $fieldId => $fieldValue)
	{
		$result[$fieldId] = $fieldValue;
		if (in_array($fieldId, array('MODIFIED_BY', 'CREATED_BY')))
		{
			$result[$fieldId] = 'user_'.$fieldValue;
			$result[$fieldId.'_PRINTABLE'] = $element[($fieldId == 'MODIFIED_BY')
				? 'USER_NAME' : 'CREATED_USER_NAME'];
		}
		elseif (in_array($fieldId, array('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'] = array($property['VALUE']);

				$listUsers = implode(' | ', $property['VALUE']);
				$userQuery = CUser::getList('ID', 'ASC',
					array('ID' => $listUsers) ,
					array('FIELDS' => array('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')
			{
				if (is_array($property['VALUE']))
				{
					$diskValues = current($property['VALUE']);
					$userType = CIBlockProperty::getUserType($property['USER_TYPE']);
					$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'], array($attachedId));
						if(!$fileId)
							continue;
						$printableUrl = '';
						if (array_key_exists('GetUrlAttachedFileElement', $userType))
							$printableUrl = call_user_func_array($userType['GetUrlAttachedFileElement'],
								array($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'],
								array($property, array('VALUE' => $moneyValue), array())
							);
						}
					}
				}
				else
				{
					$result['PROPERTY_'.$propertyId] = $property['VALUE'];
					if(array_key_exists('GetPublicViewHTML', $userType))
					{
						$result['PROPERTY_'.$propertyId.'_PRINTABLE'] = call_user_func_array(
							$userType['GetPublicViewHTML'],
							array($property, array('VALUE' => $property['VALUE']), array())
						);
					}
				}
			}
			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 = array();
			$propertyKeyArray = array();
			if(!is_array($property['VALUE']))
				$property['VALUE'] = array($property['VALUE']);
			foreach($property['VALUE'] as $enumId)
			{
				$enumsObject = CIBlockProperty::getPropertyEnum(
					$property['ID'],
					array('SORT' => 'asc'),
					array('ID' => $enumId)
				);
				while($enums = $enumsObject->fetch())
				{
					$propertyArray[] = $enums['VALUE'];
					$propertyKeyArray[] = (self::getVersion() > 1) ? $enums['XML_ID'] : $enums['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 = array($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;
}