CCrmRestProxyBase::getFileData

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmRestProxyBase
  4. getFileData
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmRestProxyBase
  • Вызов: CCrmRestProxyBase::getFileData
static function getFileData($diskObjectId)
{
	$result = false;

	$diskObjectId = intval($diskObjectId);
	if ($diskObjectId <= 0)
	{
		return $result;
	}

	if ($fileModel = \Bitrix\Disk\File::getById($diskObjectId))
	{
		/** @var \Bitrix\Disk\File $fileModel */
		$contentType = 'file';
		$imageParams = false;
		if (\Bitrix\Disk\TypeFile::isImage($fileModel))
		{
			$contentType = 'image';
			$params = $fileModel->getFile();
			$imageParams = Array(
				'width' => (int)$params['WIDTH'],
				'height' => (int)$params['HEIGHT'],
			);
		}
		else if (\Bitrix\Disk\TypeFile::isVideo($fileModel->getName()))
		{
			$contentType = 'video';
			$params = $fileModel->getView()->getPreviewData();
			$imageParams = Array(
				'width' => (int)$params['WIDTH'],
				'height' => (int)$params['HEIGHT'],
			);
		}

		$isImage = \Bitrix\Disk\TypeFile::isImage($fileModel);
		$urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();

		$result = array(
			'id' => (int)$fileModel->getId(),
			'date' => $fileModel->getCreateTime(),
			'type' => $contentType,
			'name' => $fileModel->getName(),
			'size' => (int)$fileModel->getSize(),
			'image' => $imageParams,
			'authorId' => (int)$fileModel->getCreatedBy(),
			'authorName' => CUser::FormatName(CSite::getNameFormat(false), $fileModel->getCreateUser(), true, true),
			'urlPreview' => (
			$fileModel->getPreviewId()
				? $urlManager->getUrlForShowPreview($fileModel, [ 'width' => 640, 'height' => 640])
				: (
			$isImage
				? $urlManager->getUrlForShowFile($fileModel, [ 'width' => 640, 'height' => 640])
				: null
			)
			),
			'urlShow' => ($isImage ? $urlManager->getUrlForShowFile($fileModel) : $urlManager->getUrlForDownloadFile($fileModel)),
			'urlDownload' => $urlManager->getUrlForDownloadFile($fileModel)
		);
	}

	return $result;
}

Добавить комментарий