diff --git a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php index 894bf058c..e207cfb25 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php +++ b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php @@ -23,12 +23,12 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext */ public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void; + public function getFormData(DocGeneratorTemplate $template, $entity): array; + /** * has form. * * @param mixed $entity */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; - - public function getFormData(DocGeneratorTemplate $template, $entity): array; } diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php index e41c0c186..f1db9e16f 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php @@ -59,4 +59,23 @@ class AdminDocGeneratorTemplateController extends CRUDController return $entity; } + + function generateTemplateParameter(string $action, $entity, Request $request, array $defaultTemplateParameters = []) + { + switch ($action) { + case 'new': + $context = $this->contextManager->getContextByKey($request->get('context')); + break; + case 'edit': + $context = $this->contextManager->getContextByDocGeneratorTemplate($entity); + break; + default: + return parent::generateTemplateParameter($action, $entity, $request, $defaultTemplateParameters); // TODO: Change the autogenerated stub + } + + return array_merge( + $defaultTemplateParameters, + ['context' => $context] + ); + } } diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index 1f729e066..02f164a78 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -113,10 +113,11 @@ final class DocGeneratorTemplateController extends AbstractController 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]; + $templatePath = '@ChillDocGenerator/Generator/basic_form.html.twig'; + $templateOptions = ['entity' => $entity, 'form' => $form->createView(), + 'template' => $template, 'context' => $context]; - return $this->render($template, $templateOptions); + return $this->render($templatePath, $templateOptions); } } diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue b/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue index 1052fe75f..f1fb6c84b 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue @@ -1,21 +1,39 @@ @@ -106,6 +124,15 @@ export default { window.location.assign(url); }, }, + i18n: { + messages: { + fr: { + generate_document: 'Générer un document', + select_a_template: 'Choisir un gabarit', + choose_a_template: 'Choisir', + } + } + } } diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/edit.html.twig b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/edit.html.twig index 77c9f3e10..93b08f688 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/edit.html.twig +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/edit.html.twig @@ -1,11 +1,15 @@ {% extends '@ChillDocGenerator/Admin/layout.html.twig' %} -{% block title %} - {% include('@ChillMain/CRUD/_edit_title.html.twig') %} -{% endblock %} +{% block title 'docgen.Edit template'|trans %} {% block layout_wvm_content %} {% embed '@ChillMain/CRUD/_edit_content.html.twig' %} + + {% block crud_content_header %} +

{{ 'docgen.Edit template'|trans }}

+

{{ 'docgen.With context %name%'|trans({'%name%': context.name|trans }) }}

+ {% endblock crud_content_header %} + {% block content_form_actions_view %}{% endblock %} {% block content_form_actions_save_and_show %}{% endblock %} {% endembed %} diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/new.html.twig b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/new.html.twig index baf409800..fe4991ffa 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/new.html.twig +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/new.html.twig @@ -1,12 +1,17 @@ {% extends '@ChillDocGenerator/Admin/layout.html.twig' %} -{% block title %} - {% include('@ChillMain/CRUD/_new_title.html.twig') %} -{% endblock %} +{% block title 'docgen.New template'|trans %} {% block layout_wvm_content %} {% embed '@ChillMain/CRUD/_new_content.html.twig' %} + + {% block crud_content_header %} +

{{ 'docgen.New template'|trans }}

+

{{ 'docgen.With context %name%'|trans({'%name%': context.name|trans }) }}

+ {% endblock crud_content_header %} + {% block content_form_actions_save_and_show %}{% endblock %} + {% endembed %} {% endblock %} diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig index 58d4b059f..7b24eae0d 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig @@ -1,10 +1,11 @@ {% extends 'ChillMainBundle::layout.html.twig' %} -{% block title 'Generate document'|trans %} +{% block title 'docgen.Generate a document'|trans %} {% block content %}

{{ block('title') }}

+

{{ template.name|localize_translatable_string }}

{{ form_start(form, { 'attr': { 'id': 'generate_doc_form' }}) }} {{ form(form) }} @@ -12,8 +13,8 @@ diff --git a/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php b/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php index c081a63c2..0a29af940 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php +++ b/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php @@ -99,7 +99,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte } $type = $reflection->getProperty($attribute->getName())->getType(); - } elseif ($reflection->hasMethod($method = 'get'.ucfirst($attribute->getName()))) { + } elseif ($reflection->hasMethod($method = 'get' . ucfirst($attribute->getName()))) { if (!$reflection->getMethod($method)->hasReturnType()) { throw new \LogicException(sprintf( 'Could not determine how the content is determined for the attribute %s. Add a return type on the method', @@ -108,7 +108,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte } $type = $reflection->getMethod($method)->getReturnType(); - } elseif ($reflection->hasMethod($method = 'is'.ucfirst($attribute->getName()))) { + } elseif ($reflection->hasMethod($method = 'is' . ucfirst($attribute->getName()))) { if (!$reflection->getMethod($method)->hasReturnType()) { throw new \LogicException(sprintf( 'Could not determine how the content is determined for the attribute %s. Add a return type on the method', @@ -168,12 +168,14 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte switch ($type) { case 'array': return []; + case 'bool': case 'double': case 'float': case 'int': case 'resource': return null; + case 'string': return ''; diff --git a/src/Bundle/ChillDocGeneratorBundle/translations/messages.fr.yml b/src/Bundle/ChillDocGeneratorBundle/translations/messages.fr.yml index e69de29bb..ebfe5320f 100644 --- a/src/Bundle/ChillDocGeneratorBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillDocGeneratorBundle/translations/messages.fr.yml @@ -0,0 +1,3 @@ +docgen: + Generate a document: Génerer un document + Generate: Génerer diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php index 29b00cf4f..ddd3445a4 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php @@ -15,7 +15,6 @@ use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Serializer\Model\Collection; -use Chill\MainBundle\Serializer\Normalizer\CollectionNormalizer; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; use Chill\PersonBundle\Entity\SocialWork\Evaluation; use Symfony\Component\HttpFoundation\JsonResponse; @@ -23,15 +22,17 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\SerializerInterface; +use function count; +use function in_array; class AccompanyingPeriodWorkEvaluationApiController { private DocGeneratorTemplateRepository $docGeneratorTemplateRepository; - private SerializerInterface $serializer; - private PaginatorFactory $paginatorFactory; + private SerializerInterface $serializer; + public function __construct( DocGeneratorTemplateRepository $docGeneratorTemplateRepository, SerializerInterface $serializer, @@ -44,21 +45,22 @@ class AccompanyingPeriodWorkEvaluationApiController /** * @Route("/api/1.0/person/docgen/template/by-evaluation/{id}.{_format}", - * requirements={"format": "json"}) + * requirements={"format": "json"}) */ public function listTemplateByEvaluation(Evaluation $evaluation, string $_format): JsonResponse { if ('json' !== $_format) { - throw new BadRequestHttpException("format not supported"); + throw new BadRequestHttpException('format not supported'); } $evaluations = array_filter( $this->docGeneratorTemplateRepository ->findByEntity(AccompanyingPeriodWorkEvaluation::class), - function (DocGeneratorTemplate $t) use ($evaluation) { + static function (DocGeneratorTemplate $t) use ($evaluation) { $ids = $t->getOptions()['evaluations'] ?? []; - return in_array($evaluation->getId(), $ids); + + return in_array($evaluation->getId(), $ids, true); } ); @@ -66,8 +68,10 @@ class AccompanyingPeriodWorkEvaluationApiController $paginator->setItemsPerPage(count($evaluations)); return new JsonResponse($this->serializer->serialize( - new Collection($evaluations, $paginator), 'json', [ - AbstractNormalizer::GROUPS => ['read'] + new Collection($evaluations, $paginator), + 'json', + [ + AbstractNormalizer::GROUPS => ['read'], ] ), JsonResponse::HTTP_OK, [], true); } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php index d5f883e75..479bbfb87 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php @@ -239,11 +239,6 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU return $this->updatedBy; } - public function getWarningInterval(): ?DateInterval - { - return $this->warningInterval; - } - /** * @Serializer\Groups({"docgen:read"}) */ @@ -256,6 +251,11 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU return $this->getEndDate()->sub($this->getWarningInterval()); } + public function getWarningInterval(): ?DateInterval + { + return $this->warningInterval; + } + public function removeDocument(AccompanyingPeriodWorkEvaluationDocument $document): self { $this->documents->removeElement($document); diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php index fd846fbe9..4c21cd348 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php @@ -28,7 +28,7 @@ class Evaluation * @ORM\Column(type="dateinterval", nullable=true, options={"default": null}) * @Serializer\Groups({"read"}) */ - private ?\DateInterval $delay = null; + private ?DateInterval $delay = null; /** * @ORM\Id @@ -42,7 +42,7 @@ class Evaluation * @ORM\Column(type="dateinterval", nullable=true, options={"default": null}) * @Serializer\Groups({"read"}) */ - private ?\DateInterval $notificationDelay = null; + private ?DateInterval $notificationDelay = null; /** * @ORM\ManyToOne( diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue index b7a137de2..0bdb91ab5 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue @@ -195,15 +195,17 @@
- - - +
+ + + +

{{ $t('fix_these_errors') }}

diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php index cab195530..136cb751b 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Service\DocGenerator; -use Chill\DocGeneratorBundle\Context\DocGeneratorContextInterface; use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface; use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface; use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException; @@ -29,8 +28,10 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Contracts\Translation\TranslatorInterface; use function array_key_exists; class AccompanyingPeriodContext implements @@ -47,28 +48,26 @@ class AccompanyingPeriodContext implements private TranslatableStringHelperInterface $translatableStringHelper; + private TranslatorInterface $translator; + public function __construct( DocumentCategoryRepository $documentCategoryRepository, NormalizerInterface $normalizer, TranslatableStringHelperInterface $translatableStringHelper, EntityManagerInterface $em, - PersonRender $personRender + PersonRender $personRender, + TranslatorInterface $translator ) { $this->documentCategoryRepository = $documentCategoryRepository; $this->normalizer = $normalizer; $this->translatableStringHelper = $translatableStringHelper; $this->em = $em; $this->personRender = $personRender; + $this->translator = $translator; } public function adminFormReverseTransform(array $data): array { - $data = [ - 'mainPerson' => $data['mainPerson'], - 'person1' => $data['person1'], - 'person2' => $data['person2'], - ]; - if (array_key_exists('category', $data)) { $data['category'] = [ 'idInsideBundle' => $data['category']->getIdInsideBundle(), @@ -83,8 +82,11 @@ class AccompanyingPeriodContext implements { $data = [ 'mainPerson' => $data['mainPerson'] ?? false, + 'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'), 'person1' => $data['person1'] ?? false, + 'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'), 'person2' => $data['person2'] ?? false, + 'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'), ]; if (array_key_exists('category', $data)) { @@ -100,12 +102,27 @@ class AccompanyingPeriodContext implements $builder ->add('mainPerson', CheckboxType::class, [ 'required' => false, + 'label' => 'Ask for main person', + ]) + ->add('mainPersonLabel', TextType::class, [ + 'label' => 'main person label', + 'required' => true, ]) ->add('person1', CheckboxType::class, [ 'required' => false, + 'label' => 'Ask for person 1' + ]) + ->add('person1Label', TextType::class, [ + 'label' => 'person 1 label', + 'required' => true, ]) ->add('person2', CheckboxType::class, [ 'required' => false, + 'label' => 'Ask for person 2' + ]) + ->add('person2Label', TextType::class, [ + 'label' => 'person 2 label', + 'required' => true, ]) ->add('category', EntityType::class, [ 'placeholder' => 'Choose a document category', @@ -138,6 +155,7 @@ class AccompanyingPeriodContext implements 'choice_label' => function (Person $p) { return $this->personRender->renderString($p, []); }, 'multiple' => false, 'expanded' => true, + 'label' => $options[$key.'Label'], ]); } } @@ -175,7 +193,7 @@ class AccompanyingPeriodContext implements public function getFormData(DocGeneratorTemplate $template, $entity): array { return [ - 'course' => $entity + 'course' => $entity, ]; } diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php index 3ade3ac4f..5041d9180 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php @@ -51,6 +51,8 @@ class AccompanyingPeriodWorkContext implements public function buildAdminForm(FormBuilderInterface $builder): void { $this->periodContext->buildAdminForm($builder); + + $builder->remove('category'); } /** diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php index e1aeed231..2ffcaf818 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -100,7 +100,6 @@ class AccompanyingPeriodWorkEvaluationContext implements /** * @param AccompanyingPeriodWorkEvaluation $entity - * @return void */ public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void { @@ -141,8 +140,10 @@ class AccompanyingPeriodWorkEvaluationContext implements */ public function getFormData(DocGeneratorTemplate $template, $entity): array { - return $this->accompanyingPeriodWorkContext->getFormData($template, - $entity->getAccompanyingPeriodWork()); + return $this->accompanyingPeriodWorkContext->getFormData( + $template, + $entity->getAccompanyingPeriodWork() + ); } public static function getKey(): string diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 904ec8811..f2125d5c6 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -448,3 +448,8 @@ Household addresses: Adresses de domicile Insert an address: Insérer une adresse see social issues: Voir les problématiques sociales see persons associated: Voir les usagers concernés + +docgen: + Main person: Personne principale + person 1: Première personne + person 2: Deuxième personne