mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
generate document with relatorio: config and driver
This commit is contained in:
@@ -21,22 +21,22 @@ use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
// TODO à mettre dans services
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
final class DocGeneratorTemplateController extends AbstractController
|
||||
@@ -47,6 +47,8 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private DriverInterface $driver;
|
||||
|
||||
private KernelInterface $kernel;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
@@ -55,8 +57,6 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
private TempUrlGeneratorInterface $tempUrlGenerator;
|
||||
|
||||
private DriverInterface $driver;
|
||||
|
||||
public function __construct(
|
||||
ContextManager $contextManager,
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
@@ -66,7 +66,6 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
TempUrlGeneratorInterface $tempUrlGenerator,
|
||||
KernelInterface $kernel,
|
||||
HttpClientInterface $client
|
||||
|
||||
) {
|
||||
$this->contextManager = $contextManager;
|
||||
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
|
||||
@@ -93,7 +92,7 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
$entity = $this->getDoctrine()->getRepository($entityClassName)->find($entityId);
|
||||
|
||||
if (null === $entity) {
|
||||
throw new NotFoundHttpException("Entity with classname $entityClassName and id $entityId is not found");
|
||||
throw new NotFoundHttpException("Entity with classname {$entityClassName} and id {$entityId} is not found");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -102,6 +101,8 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
throw new NotFoundHttpException($e->getMessage(), $e);
|
||||
}
|
||||
|
||||
$contextGenerationData = [];
|
||||
|
||||
if ($context->hasPublicForm($template, $entity)) {
|
||||
$builder = $this->createFormBuilder();
|
||||
$context->buildPublicForm($builder, $template, $entity);
|
||||
@@ -115,8 +116,6 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
return $this->render($template, $templateOptions);
|
||||
}
|
||||
} else {
|
||||
$contextGenerationData = [];
|
||||
}
|
||||
|
||||
$getUrlGen = $this->tempUrlGenerator->generate(
|
||||
@@ -137,11 +136,11 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
$dataDecrypted = openssl_decrypt($data->getContent(), $method, $keyGoodFormat, 1, $ivGoodFormat);
|
||||
|
||||
if (false === $dataDecrypted) {
|
||||
throw new \Exception('Error during Decrypt ', 1);
|
||||
throw new Exception('Error during Decrypt ', 1);
|
||||
}
|
||||
|
||||
if (false === $templateResource = fopen('php://memory', 'r+')) {
|
||||
$this->logger->error("Could not write data to memory");
|
||||
if (false === $templateResource = fopen('php://memory', 'r+b')) {
|
||||
$this->logger->error('Could not write data to memory');
|
||||
|
||||
throw new HttpException(500);
|
||||
}
|
||||
@@ -156,7 +155,7 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
fclose($templateResource);
|
||||
|
||||
$genDocName = 'doc_' . sprintf('%010d', mt_rand()).'odt';
|
||||
$genDocName = 'doc_' . sprintf('%010d', mt_rand()) . 'odt';
|
||||
|
||||
$getUrlGen = $this->tempUrlGenerator->generate(
|
||||
'PUT',
|
||||
@@ -181,7 +180,7 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
try {
|
||||
$context->storeGenerated($template, $storedObject, $entity, $contextGenerationData);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error('Could not store the associated document to entity', [
|
||||
'entityClassName' => $entityClassName,
|
||||
'entityId' => $entityId,
|
||||
@@ -202,7 +201,7 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw new \Exception('Unable to generate document.');
|
||||
throw new Exception('Unable to generate document.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user