• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/controller/item.php
  • Класс: Bitrix\Crm\Controller\Item
  • Вызов: Item::getFileAction
public function getFileAction(
	int $entityTypeId,
	int $id,
	string $fieldName,
	int $fileId
): ?BFile
{
	$factory = $this->getFactory($entityTypeId);
	if (!$factory)
	{
		return null;
	}

	$item = $factory->getItem($id);
	if (!$item)
	{
		$this->addError(new Error(
			Loc::getMessage('CRM_TYPE_ITEM_NOT_FOUND'),
			ErrorCode::NOT_FOUND
		));
		return null;
	}
	if (!Container::getInstance()->getUserPermissions()->canReadItem($item))
	{
		$this->addError(new Error(
			Loc::getMessage('CRM_COMMON_READ_ACCESS_DENIED'),
			ErrorCode::ACCESS_DENIED
		));
		return null;
	}

	$field = $factory->getFieldsCollection()->getField($fieldName);
	if (!$field || !$field->isFileUserField())
	{
		$this->addError(new Error('Field ' . $fieldName . ' is not a file field'));
		return null;
	}
	$value = $item->get($fieldName);
	if ((int)$value === $fileId && $fileId > 0)
	{
		return BFile::createByFileId($fileId);
	}
	if (is_array($value))
	{
		Collection::normalizeArrayValuesByInt($value);
		if (in_array($fileId, $value, true))
		{
			return BFile::createByFileId($fileId);
		}
	}

	return null;
}