• Модуль: documentgenerator
  • Путь к файлу: ~/bitrix/modules/documentgenerator/lib/rest/restmanager.php
  • Класс: BitrixDocumentGeneratorRestRestManager
  • Вызов: RestManager::download
static function download(array $query, $scope, CRestServer $restServer)
{
	if(isset($query['templateId']))
	{
		$template = Template::loadById($query['templateId']);
		if($template)
		{
			static::showFileContent($template->FILE_ID);
		}
		else
		{
			throw new RestException('Template not found', RestException::ERROR_NOT_FOUND);
		}
	}
	elseif(isset($query['documentId']) && isset($query['type']))
	{
		$document = Document::loadById($query['documentId']);
		if($document)
		{
			if($query['type'] === static::DOCUMENT_FILE_TYPE_FILE)
			{
				static::showFileContent($document->FILE_ID);
			}
			elseif($query['type'] === static::DOCUMENT_FILE_TYPE_PDF)
			{
				if($document->PDF_ID > 0)
				{
					static::showFileContent($document->PDF_ID);
				}
				else
				{
					throw new RestException('No pdf for document');
				}
			}
			elseif($query['type'] === static::DOCUMENT_FILE_TYPE_IMAGE)
			{
				if($document->IMAGE_ID > 0)
				{
					static::showFileContent($document->IMAGE_ID);
				}
				else
				{
					throw new RestException('No image for document');
				}
			}
		}
		else
		{
			throw new RestException('Document not found', RestException::ERROR_NOT_FOUND);
		}
	}

	throw new RestException('Wrong arguments', RestException::ERROR_ARGUMENT);
}