mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add form to doc generation and custom form to admin template configuration
This commit is contained in:
@@ -30,6 +30,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
// TODO à mettre dans services
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
@@ -83,6 +84,35 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
int $entityId,
|
||||
Request $request
|
||||
): Response {
|
||||
$entity = $this->getDoctrine()->getRepository($entityClassName)->find($entityId);
|
||||
|
||||
if (null === $entity) {
|
||||
throw new NotFoundHttpException("Entity with classname $entityClassName and id $entityId is not found");
|
||||
}
|
||||
|
||||
try {
|
||||
$context = $this->contextManager->getContextByDocGeneratorTemplate($template);
|
||||
} catch (ContextNotFoundException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage(), $e);
|
||||
}
|
||||
|
||||
if ($context->hasPublicForm($template, $entity)) {
|
||||
$builder = $this->createFormBuilder();
|
||||
$context->buildPublicForm($builder, $template, $entity);
|
||||
$form = $builder->getForm()->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$contextGenerationData = $form->getData();
|
||||
} elseif (!$form->isSubmitted() || ($form->isSubmitted() && !$form->isValid())) {
|
||||
$template = '@ChillDocGenerator/Generator/basic_form.html.twig';
|
||||
$templateOptions = ['entity' => $entity, 'form' => $form->createView(), 'template' => $template];
|
||||
|
||||
return $this->render($template, $templateOptions);
|
||||
}
|
||||
} else {
|
||||
$contextGenerationData = [];
|
||||
}
|
||||
|
||||
$getUrlGen = $this->tempUrlGenerator->generate(
|
||||
'GET',
|
||||
$template->getFile()->getFilename()
|
||||
@@ -107,30 +137,22 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
$tmpfnameDeCrypted = tempnam($this->kernel->getCacheDir(), 'DECRYPT_DOC_TEMPLATE'); // plus ou moins
|
||||
|
||||
if (!$handle = fopen($tmpfnameDeCrypted, 'ab')) {
|
||||
echo "Cannot open file ({$tmpfnameDeCrypted})";
|
||||
$this->logger->error("Cannot open file ({$tmpfnameDeCrypted})");
|
||||
|
||||
exit;
|
||||
throw new HttpException(500);
|
||||
}
|
||||
|
||||
if (false === $ftemplate = fwrite($handle, $dataDecrypted)) {
|
||||
echo "Cannot write to file ({$tmpfnameDeCrypted})";
|
||||
$this->logger->error("Cannot write to file ({$tmpfnameDeCrypted})");
|
||||
|
||||
exit;
|
||||
throw new HttpException(500);
|
||||
}
|
||||
|
||||
dump("Success, wrote (to file ({$tmpfnameDeCrypted})");
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$entity = $this->getDoctrine()->getRepository($entityClassName)->find($entityId);
|
||||
|
||||
try {
|
||||
$context = $this->contextManager->getContextByDocGeneratorTemplate($template);
|
||||
} catch (ContextNotFoundException $e) {
|
||||
throw new NotFoundHttpException($e->getMessage(), $e);
|
||||
}
|
||||
|
||||
$datas = $context->getData($entity);
|
||||
$datas = $context->getData($template, $entity, $contextGenerationData);
|
||||
|
||||
dump('process the data', $datas);
|
||||
|
||||
@@ -182,7 +204,7 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
$em->persist($storedObject);
|
||||
|
||||
try {
|
||||
$context->storeGenerated($template, $storedObject, $entity);
|
||||
$context->storeGenerated($template, $storedObject, $entity, $contextGenerationData);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Could not store the associated document to entity', [
|
||||
'entityClassName' => $entityClassName,
|
||||
|
Reference in New Issue
Block a user