• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Service/Factory.php
  • Класс: Bitrix\Crm\Service\Factory
  • Вызов: Factory::getFieldValueCaption
public function getFieldValueCaption(string $commonFieldName, $fieldValue): string
{
	$field = $this->getFieldsCollection()->getField($commonFieldName);
	if (!$field)
	{
		return (string)$fieldValue;
	}

	if ($commonFieldName === Item::FIELD_NAME_IS_MANUAL_OPPORTUNITY)
	{
		return $fieldValue ?
			Loc::getMessage('CRM_COMMON_IS_MANUAL_OPPORTUNITY_TRUE')
			:
			Loc::getMessage('CRM_COMMON_IS_MANUAL_OPPORTUNITY_FALSE');
	}

	if ($field->getType() === Field::TYPE_STRING)
	{
		return $fieldValue ? (string)$fieldValue : Loc::getMessage('CRM_COMMON_EMPTY');
	}
	if ($field->getType() === Field::TYPE_USER)
	{
		return Container::getInstance()->getUserBroker()->getName((int)$fieldValue) ?? Loc::getMessage('CRM_COMMON_EMPTY');
	}
	if ($field->getType() === Field::TYPE_BOOLEAN)
	{
		if (!is_bool($fieldValue) && empty($fieldValue))
		{
			return Loc::getMessage('CRM_COMMON_EMPTY');
		}

		return $fieldValue ? Loc::getMessage('CRM_COMMON_YES') : Loc::getMessage('CRM_COMMON_NO');
	}
	if($field->getType() === Field::TYPE_CRM_STATUS)
	{
		$statusId = (string)$fieldValue;
		if ($statusId === '')
		{
			return Loc::getMessage('CRM_COMMON_EMPTY');
		}

		if ($commonFieldName === Item::FIELD_NAME_STAGE_ID || $commonFieldName === Item::FIELD_NAME_PREVIOUS_STAGE_ID)
		{
			$stage = $this->getStage($statusId);

			return $stage ? $stage->getName() : $statusId;
		}

		$entityId = $field->getCrmStatusType();

		return (StatusTable::getStatusesList($entityId)[$statusId] ?? $statusId);
	}
	if ($field->getType() === Field::TYPE_CRM_CURRENCY)
	{
		return Currency::getCurrencyCaption((string)$fieldValue) ?? Loc::getMessage('CRM_COMMON_EMPTY');
	}
	if ($field->getType() === Field::TYPE_CRM_COMPANY)
	{
		return
			Container::getInstance()->getCompanyBroker()->getTitle((int)$fieldValue)
			?? Loc::getMessage('CRM_COMMON_EMPTY')
		;
	}
	if ($field->getType() === Field::TYPE_CRM_CONTACT)
	{
		return
			Container::getInstance()->getContactBroker()->getFormattedName((int)$fieldValue)
			?? Loc::getMessage('CRM_COMMON_EMPTY')
		;
	}
	if($field instanceof Field\Category)
	{
		$category = $this->getCategory((int)$fieldValue);
		if($category)
		{
			return $category->getName();
		}
	}
	if ($field->getType() === Field::TYPE_LOCATION)
	{
		return \CCrmLocations::getLocationStringByCode($fieldValue);
	}

	return (string)$fieldValue;
}