From d163783ed3e4fa6f1d7261cb02ed792d287be7e9 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 28 Feb 2022 11:42:54 +0100 Subject: [PATCH 01/11] Person Document: add a PersonContext class --- .../Service/DocGenerator/PersonContext.php | 214 ++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php new file mode 100644 index 000000000..2b22d607c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php @@ -0,0 +1,214 @@ +documentCategoryRepository = $documentCategoryRepository; + $this->normalizer = $normalizer; + $this->translatableStringHelper = $translatableStringHelper; + $this->em = $em; + $this->baseContextData = $baseContextData; + } + + public function adminFormReverseTransform(array $data): array + { + if (array_key_exists('category', $data)) { + $data['category'] = [ + 'idInsideBundle' => $data['category']->getIdInsideBundle(), + 'bundleId' => $data['category']->getBundleId(), + ]; + } + + return $data; + } + + public function adminFormTransform(array $data): array + { + // $r = [ + // '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)) { + $r['category'] = array_key_exists('category', $data) ? + $this->documentCategoryRepository->find($data['category']) : null; + } + + return $r; + } + + public function buildAdminForm(FormBuilderInterface $builder): void + { + $builder + // ->add('mainPerson', CheckboxType::class, [ + // 'required' => false, + // 'label' => 'docgen.Ask for main person', + // ]) + // ->add('mainPersonLabel', TextType::class, [ + // 'label' => 'main person label', + // 'required' => true, + // ]) + // ->add('person1', CheckboxType::class, [ + // 'required' => false, + // 'label' => 'docgen.Ask for person 1', + // ]) + // ->add('person1Label', TextType::class, [ + // 'label' => 'person 1 label', + // 'required' => true, + // ]) + // ->add('person2', CheckboxType::class, [ + // 'required' => false, + // 'label' => 'docgen.Ask for person 2', + // ]) + // ->add('person2Label', TextType::class, [ + // 'label' => 'person 2 label', + // 'required' => true, + // ]) + ->add('category', EntityType::class, [ + 'placeholder' => 'Choose a document category', + 'class' => 'ChillDocStoreBundle:DocumentCategory', + 'query_builder' => static function (EntityRepository $er) { + return $er->createQueryBuilder('c') + ->where('c.documentClass = :docClass') + ->setParameter('docClass', PersonDocument::class); + }, + 'choice_label' => function ($entity = null) { + return $entity ? $this->translatableStringHelper->localize($entity->getName()) : ''; + }, + ]); + } + + public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array + { + if (!$entity instanceof Person) { + throw new UnexpectedTypeException($entity, Person::class); + } + $options = $template->getOptions(); + + $data = []; + $data = array_merge($data, $this->baseContextData->getData()); + $data['person'] = $this->normalizer->normalize($entity, 'docgen', [ + 'docgen:expects' => Person::class, + 'groups' => 'docgen:read' + ]); + + // foreach (['mainPerson', 'person1', 'person2'] as $k) { + // if ($options[$k]) { + // $data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', [ + // 'docgen:expects' => Person::class, + // 'groups' => 'docgen:read', + // 'docgen:person:with-household' => true, + // 'docgen:person:with-relations' => true, + // ]); + // } + // } + + return $data; + } + + public function getDescription(): string + { + return 'docgen.A basic context for person'; + } + + public function getEntityClass(): string + { + return Person::class; + } + + public function getFormData(DocGeneratorTemplate $template, $entity): array + { + return [ + 'person' => $entity, + ]; + } + + public static function getKey(): string + { + return self::class; + } + + public function getName(): string + { + return 'docgen.Person basic'; + } + + public function hasAdminForm(): bool + { + return true; + } + + /** + * @param Person $entity + */ + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void + { + $doc = new PersonDocument(); + $doc->setTemplate($template) + ->setTitle($this->translatableStringHelper->localize($template->getName())) + ->setDate(new DateTime()) + ->setDescription($this->translatableStringHelper->localize($template->getName())) + ->setPerson($entity) + ->setObject($storedObject); + + if (array_key_exists('category', $template->getOptions())) { + $doc + ->setCategory( + $this->documentCategoryRepository->find( + $template->getOptions()['category'] + ) + ); + } + + $this->em->persist($doc); + } +} \ No newline at end of file From 7aefa5014c5af9c0437080ef3f117a7041de012a Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 28 Feb 2022 12:33:38 +0100 Subject: [PATCH 02/11] Add docgen:read group on Person + 2 fields in PersonContext admin form --- .../ChillPersonBundle/Entity/Person.php | 15 ++++++++ .../Service/DocGenerator/PersonContext.php | 36 ++++++++++--------- .../translations/messages.fr.yml | 2 ++ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 49f7ae297..b51b4490c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -38,6 +38,7 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; use Exception; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; +use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; use function count; @@ -152,6 +153,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @ORM\Column(type="date", nullable=true) * @Birthdate + * @Groups({"docgen:read"}) */ private $birthdate; @@ -200,6 +202,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * sf4 check: option inversedBy="birthsIn" return error mapping !! * * @ORM\JoinColumn(nullable=true) + * @Groups({"docgen:read"}) */ private $countryOfBirth; @@ -237,6 +240,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @Assert\Date * @Assert\GreaterThanOrEqual(propertyPath="birthdate") * @Assert\LessThanOrEqual("today") + * @Groups({"docgen:read"}) */ private ?DateTimeImmutable $deathdate = null; @@ -249,6 +253,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @Assert\Email( * checkMX=true * ) + * @Groups({"docgen:read"}) */ private $email = ''; @@ -262,6 +267,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @Assert\Length( * max=255, * ) + * @Groups({"docgen:read"}) */ private $firstName; @@ -282,6 +288,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @ORM\Column(type="string", length=9, nullable=true) * @Assert\NotNull(message="The gender must be set") + * @Groups({"docgen:read"}) */ private $gender; @@ -339,6 +346,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\MaritalStatus") * @ORM\JoinColumn(nullable=true) + * @Groups({"docgen:read"}) */ private $maritalStatus; @@ -346,6 +354,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * Comment on marital status. * * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="maritalStatusComment_") + * @Groups({"docgen:read"}) */ private CommentEmbeddable $maritalStatusComment; @@ -356,6 +365,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @ORM\Column(type="date", nullable=true) * @Assert\Date + * @Groups({"docgen:read"}) */ private ?DateTime $maritalStatusDate = null; @@ -378,6 +388,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @PhonenumberConstraint( * type="mobile", * ) + * @Groups({"docgen:read"}) */ private string $mobilenumber = ''; @@ -391,6 +402,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * sf4 check: option inversedBy="nationals" return error mapping !! * * @ORM\JoinColumn(nullable=true) + * @Groups({"docgen:read"}) */ private $nationality; @@ -400,6 +412,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @var int * * @ORM\Column(type="integer", nullable=true) + * @Groups({"docgen:read"}) */ private ?int $numberOfChildren = null; @@ -436,6 +449,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @PhonenumberConstraint( * type="landline", * ) + * @Groups({"docgen:read"}) */ private string $phonenumber = ''; @@ -445,6 +459,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @var string * * @ORM\Column(type="string", length=255, name="place_of_birth") + * @Groups({"docgen:read"}) */ private $placeOfBirth = ''; diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php index 2b22d607c..30b020728 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php @@ -24,8 +24,11 @@ use DateTime; 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; @@ -41,11 +44,14 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface private TranslatableStringHelperInterface $translatableStringHelper; + private TranslatorInterface $translator; + public function __construct( DocumentCategoryRepository $documentCategoryRepository, NormalizerInterface $normalizer, TranslatableStringHelperInterface $translatableStringHelper, EntityManagerInterface $em, + TranslatorInterface $translator, BaseContextData $baseContextData ) { $this->documentCategoryRepository = $documentCategoryRepository; @@ -53,6 +59,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface $this->translatableStringHelper = $translatableStringHelper; $this->em = $em; $this->baseContextData = $baseContextData; + $this->translator = $translator; } public function adminFormReverseTransform(array $data): array @@ -69,14 +76,10 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface public function adminFormTransform(array $data): array { - // $r = [ - // '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'), - // ]; + $r = [ + 'mainPerson' => $data['mainPerson'] ?? false, + 'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'), + ]; if (array_key_exists('category', $data)) { $r['category'] = array_key_exists('category', $data) ? @@ -89,14 +92,14 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface public function buildAdminForm(FormBuilderInterface $builder): void { $builder - // ->add('mainPerson', CheckboxType::class, [ - // 'required' => false, - // 'label' => 'docgen.Ask for main person', - // ]) - // ->add('mainPersonLabel', TextType::class, [ - // 'label' => 'main person label', - // 'required' => true, - // ]) + ->add('mainPerson', CheckboxType::class, [ + 'required' => false, + 'label' => 'docgen.Ask for main person', + ]) + ->add('mainPersonLabel', TextType::class, [ + 'label' => 'main person label', + 'required' => true, + ]) // ->add('person1', CheckboxType::class, [ // 'required' => false, // 'label' => 'docgen.Ask for person 1', @@ -140,7 +143,6 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface 'docgen:expects' => Person::class, 'groups' => 'docgen:read' ]); - // foreach (['mainPerson', 'person1', 'person2'] as $k) { // if ($options[$k]) { // $data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', [ diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 3b1aea377..ba990125c 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -541,6 +541,8 @@ docgen: A basic context for accompanying period: Contexte pour les parcours A context for accompanying period work: Contexte pour les actions d'accompagnement A context for accompanying period work evaluation: Contexte pour les évaluations dans les actions d'accompagnement + Person basic: Personne (basique) + A basic context for person: Contexte pour les personnes period_notification: period_designated_subject: Vous êtes référent d'un parcours d'accompagnement From a187bac7b0d008f3e70ee852d234645c51bfb8ec Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 1 Mar 2022 15:48:32 +0100 Subject: [PATCH 03/11] DocGeneratorTemplateController: fix in case there is no public form --- .../Controller/DocGeneratorTemplateController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index 2aff33af0..d332f11c2 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -207,20 +207,21 @@ final class DocGeneratorTemplateController extends AbstractController $context instanceof DocGeneratorContextWithPublicFormInterface && $context->hasPublicForm($template, $entity) || $isTest ) { - if ($context instanceof DocGeneratorContextWithPublicFormInterface) { + if ($context instanceof DocGeneratorContextWithPublicFormInterface && $context->hasPublicForm($template, $entity)) { $builder = $this->createFormBuilder( array_merge( $context->getFormData($template, $entity), $isTest ? ['test_file' => null] : [] ) ); + + $context->buildPublicForm($builder, $template, $entity); } else { $builder = $this->createFormBuilder( ['test_file' => null] ); } - $context->buildPublicForm($builder, $template, $entity); if ($isTest) { $builder->add('test_file', FileType::class, [ From 88e9a96e0e21eca94e615425b6745c089a5999a2 Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 1 Mar 2022 15:51:34 +0100 Subject: [PATCH 04/11] Person document generation: clean build Admin form + add household and relations groups --- .../Service/DocGenerator/PersonContext.php | 39 +------------------ 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php index 30b020728..f84dd83c7 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php @@ -24,8 +24,6 @@ use DateTime; 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; @@ -92,30 +90,6 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface public function buildAdminForm(FormBuilderInterface $builder): void { $builder - ->add('mainPerson', CheckboxType::class, [ - 'required' => false, - 'label' => 'docgen.Ask for main person', - ]) - ->add('mainPersonLabel', TextType::class, [ - 'label' => 'main person label', - 'required' => true, - ]) - // ->add('person1', CheckboxType::class, [ - // 'required' => false, - // 'label' => 'docgen.Ask for person 1', - // ]) - // ->add('person1Label', TextType::class, [ - // 'label' => 'person 1 label', - // 'required' => true, - // ]) - // ->add('person2', CheckboxType::class, [ - // 'required' => false, - // 'label' => 'docgen.Ask for person 2', - // ]) - // ->add('person2Label', TextType::class, [ - // 'label' => 'person 2 label', - // 'required' => true, - // ]) ->add('category', EntityType::class, [ 'placeholder' => 'Choose a document category', 'class' => 'ChillDocStoreBundle:DocumentCategory', @@ -135,24 +109,13 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface if (!$entity instanceof Person) { throw new UnexpectedTypeException($entity, Person::class); } - $options = $template->getOptions(); $data = []; $data = array_merge($data, $this->baseContextData->getData()); $data['person'] = $this->normalizer->normalize($entity, 'docgen', [ 'docgen:expects' => Person::class, - 'groups' => 'docgen:read' + 'groups' => ['docgen:read', 'docgen:person:with-household', 'docgen:person:with-relations'] ]); - // foreach (['mainPerson', 'person1', 'person2'] as $k) { - // if ($options[$k]) { - // $data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', [ - // 'docgen:expects' => Person::class, - // 'groups' => 'docgen:read', - // 'docgen:person:with-household' => true, - // 'docgen:person:with-relations' => true, - // ]); - // } - // } return $data; } From 84478c651e14dd2037518d87ee7ff8b00d2d62eb Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 1 Mar 2022 15:54:36 +0100 Subject: [PATCH 05/11] Person: remove useless serialisation groups --- src/Bundle/ChillPersonBundle/Entity/Person.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index b51b4490c..49f7ae297 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -38,7 +38,6 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Mapping as ORM; use Exception; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; -use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; use function count; @@ -153,7 +152,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @ORM\Column(type="date", nullable=true) * @Birthdate - * @Groups({"docgen:read"}) */ private $birthdate; @@ -202,7 +200,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * sf4 check: option inversedBy="birthsIn" return error mapping !! * * @ORM\JoinColumn(nullable=true) - * @Groups({"docgen:read"}) */ private $countryOfBirth; @@ -240,7 +237,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @Assert\Date * @Assert\GreaterThanOrEqual(propertyPath="birthdate") * @Assert\LessThanOrEqual("today") - * @Groups({"docgen:read"}) */ private ?DateTimeImmutable $deathdate = null; @@ -253,7 +249,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @Assert\Email( * checkMX=true * ) - * @Groups({"docgen:read"}) */ private $email = ''; @@ -267,7 +262,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @Assert\Length( * max=255, * ) - * @Groups({"docgen:read"}) */ private $firstName; @@ -288,7 +282,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @ORM\Column(type="string", length=9, nullable=true) * @Assert\NotNull(message="The gender must be set") - * @Groups({"docgen:read"}) */ private $gender; @@ -346,7 +339,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\MaritalStatus") * @ORM\JoinColumn(nullable=true) - * @Groups({"docgen:read"}) */ private $maritalStatus; @@ -354,7 +346,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * Comment on marital status. * * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="maritalStatusComment_") - * @Groups({"docgen:read"}) */ private CommentEmbeddable $maritalStatusComment; @@ -365,7 +356,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @ORM\Column(type="date", nullable=true) * @Assert\Date - * @Groups({"docgen:read"}) */ private ?DateTime $maritalStatusDate = null; @@ -388,7 +378,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @PhonenumberConstraint( * type="mobile", * ) - * @Groups({"docgen:read"}) */ private string $mobilenumber = ''; @@ -402,7 +391,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * sf4 check: option inversedBy="nationals" return error mapping !! * * @ORM\JoinColumn(nullable=true) - * @Groups({"docgen:read"}) */ private $nationality; @@ -412,7 +400,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @var int * * @ORM\Column(type="integer", nullable=true) - * @Groups({"docgen:read"}) */ private ?int $numberOfChildren = null; @@ -449,7 +436,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @PhonenumberConstraint( * type="landline", * ) - * @Groups({"docgen:read"}) */ private string $phonenumber = ''; @@ -459,7 +445,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @var string * * @ORM\Column(type="string", length=255, name="place_of_birth") - * @Groups({"docgen:read"}) */ private $placeOfBirth = ''; From d6d7edf25d9067d6faa9928c1f89976e47f0c89f Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 1 Mar 2022 16:14:21 +0100 Subject: [PATCH 06/11] Add doc generation for PersonDocument form --- .../Resources/views/PersonDocument/index.html.twig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/index.html.twig b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/index.html.twig index b3d2baab6..e63538c22 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/index.html.twig +++ b/src/Bundle/ChillDocStoreBundle/Resources/views/PersonDocument/index.html.twig @@ -26,7 +26,17 @@ {% endblock %} {% block js %} + {{ parent() }} {{ encore_entry_script_tags('mod_async_upload') }} + {{ encore_entry_script_tags('mod_docgen_picktemplate') }} + {{ encore_entry_script_tags('mod_entity_workflow_pick') }} +{% endblock %} + +{% block css %} + {{ parent() }} + {{ encore_entry_link_tags('mod_async_upload') }} + {{ encore_entry_link_tags('mod_docgen_picktemplate') }} + {{ encore_entry_link_tags('mod_entity_workflow_pick') }} {% endblock %} {% block personcontent %} @@ -46,6 +56,8 @@ {{ chill_pagination(pagination) }} +
+ {% if is_granted('CHILL_PERSON_DOCUMENT_CREATE', person) %}
  • From 4406016f823fb01942d297f62bd4a3285d7a1131 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 3 Mar 2022 10:17:16 +0100 Subject: [PATCH 07/11] code fix for PersonContext --- .../Controller/DocGeneratorTemplateController.php | 1 - .../ChillPersonBundle/Service/DocGenerator/PersonContext.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index d332f11c2..000fcb03a 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -222,7 +222,6 @@ final class DocGeneratorTemplateController extends AbstractController ); } - if ($isTest) { $builder->add('test_file', FileType::class, [ 'label' => 'Template file', diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php index f84dd83c7..85ca1c161 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php @@ -114,7 +114,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface $data = array_merge($data, $this->baseContextData->getData()); $data['person'] = $this->normalizer->normalize($entity, 'docgen', [ 'docgen:expects' => Person::class, - 'groups' => ['docgen:read', 'docgen:person:with-household', 'docgen:person:with-relations'] + 'groups' => ['docgen:read', 'docgen:person:with-household', 'docgen:person:with-relations'], ]); return $data; @@ -176,4 +176,4 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface $this->em->persist($doc); } -} \ No newline at end of file +} From 23fd4be2e54b4b4aab2e8eb23cc7b3cae91fbe72 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 3 Mar 2022 10:17:29 +0100 Subject: [PATCH 08/11] upd CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b38afb37..7168e027f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to ## Unreleased +* [person] Add document generation in admin and in person/{id}/document (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/464) + * [docstore] Add an API entrypoint for StoredObject (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/466) * [person] Add the possibility of uploading existing documents to AccPeriodWorkEvaluationDocument (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/466) * [person] Add title to AccPeriodWorkEvaluationDocument (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/466) From bf4a3a2c91f69b23697815398c8ff23ac9f4efa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 3 Mar 2022 15:01:14 +0100 Subject: [PATCH 09/11] add id to docgen normalization fo a person --- .../Serializer/Normalizer/PersonDocGenNormalizer.php | 3 ++- .../Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php index 8eae2065d..c6d132992 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php @@ -74,6 +74,7 @@ class PersonDocGenNormalizer implements $data = [ 'type' => 'person', + 'id' => $person->getId(), 'isNull' => false, 'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])), 'firstName' => $person->getFirstName(), @@ -151,7 +152,7 @@ class PersonDocGenNormalizer implements $normalizer = new NormalizeNullValueHelper($this->normalizer, 'type', 'person'); $attributes = [ - 'firstName', 'lastName', 'age', 'altNames', 'text', + 'id', 'firstName', 'lastName', 'age', 'altNames', 'text', 'civility' => Civility::class, 'birthdate' => DateTimeInterface::class, 'deathdate' => DateTimeInterface::class, diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php index 817125422..c19533e08 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonDocGenNormalizerTest.php @@ -38,6 +38,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase use ProphecyTrait; private const BLANK = [ + 'id' => '', 'firstName' => '', 'lastName' => '', 'altNames' => '', From 9769aa1386aeeea90f9ccc41d501aaca8b47bd02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 3 Mar 2022 15:07:45 +0100 Subject: [PATCH 10/11] fix loading of residential address form type --- .../Controller/ResidentialAddressController.php | 2 +- src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php b/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php index f77a4150c..bdc6c1b5e 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php @@ -13,7 +13,7 @@ namespace Chill\PersonBundle\Controller; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person\ResidentialAddress; -use Chill\PersonBundle\Form\Type\ResidentialAddressType; +use Chill\PersonBundle\Form\ResidentialAddressType; use Chill\PersonBundle\Repository\ResidentialAddressRepository; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; diff --git a/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php b/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php index b34395daf..8efcf091a 100644 --- a/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php +++ b/src/Bundle/ChillPersonBundle/Form/ResidentialAddressType.php @@ -9,11 +9,12 @@ declare(strict_types=1); -namespace Chill\PersonBundle\Form\Type; +namespace Chill\PersonBundle\Form; use Chill\MainBundle\Form\Type\CommentType; use Chill\MainBundle\Form\Type\PickAddressType; use Chill\PersonBundle\Entity\Person\ResidentialAddress; +use Chill\PersonBundle\Form\Type\PickPersonDynamicType; use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\DateType; From 4ad65b616d3d828caf428f8282baeb29f498b904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 3 Mar 2022 15:20:21 +0100 Subject: [PATCH 11/11] fix tests for person json normalizer and residential address stuff --- .../Normalizer/PersonJsonNormalizer.php | 6 ++- .../Normalizer/PersonJsonNormalizerTest.php | 47 ++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index 1969fffa7..ae95c9321 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -33,6 +33,7 @@ use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait; use function array_key_exists; use function count; use function in_array; +use function is_string; /** * Serialize a Person entity. @@ -56,11 +57,11 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar private ResidentialAddressRepository $residentialAddressRepository; public function __construct( - ChillEntityRenderExtension $render, + ChillEntityRenderExtension $render, /* TODO: replace by PersonRenderInterface, as sthis is the only one required */ PersonRepository $repository, CenterResolverManagerInterface $centerResolverManager, ResidentialAddressRepository $residentialAddressRepository, - PhoneNumberHelperInterface $phoneNumberHelper + PhoneNumberHelperInterface $phoneNumberHelper /* TODO maybe not necessayr any more */ ) { $this->render = $render; $this->repository = $repository; @@ -189,6 +190,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar public function normalize($person, $format = null, array $context = []) { $groups = $context[AbstractNormalizer::GROUPS] ?? []; + if (is_string($groups)) { $groups = [$groups]; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonJsonNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonJsonNormalizerTest.php index 59cc0a564..13fa54178 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonJsonNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/PersonJsonNormalizerTest.php @@ -11,7 +11,15 @@ declare(strict_types=1); namespace Serializer\Normalizer; +use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface; +use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; +use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension; use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Repository\PersonRepository; +use Chill\PersonBundle\Repository\ResidentialAddressRepository; +use Chill\PersonBundle\Serializer\Normalizer\PersonJsonNormalizer; +use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -22,12 +30,27 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface; */ final class PersonJsonNormalizerTest extends KernelTestCase { - private NormalizerInterface $normalizer; + use ProphecyTrait; + + private PersonJsonNormalizer $normalizer; protected function setUp(): void { self::bootKernel(); - $this->normalizer = self::$container->get(NormalizerInterface::class); + + $residentialAddressRepository = $this->prophesize(ResidentialAddressRepository::class); + $residentialAddressRepository + ->findCurrentResidentialAddressByPerson(Argument::type(Person::class), Argument::any()) + ->willReturn([]); + + $this->normalizer = $this->buildPersonJsonNormalizer( + self::$container->get(ChillEntityRenderExtension::class), + self::$container->get(PersonRepository::class), + self::$container->get(CenterResolverManagerInterface::class), + $residentialAddressRepository->reveal(), + self::$container->get(PhoneNumberHelperInterface::class), + self::$container->get(NormalizerInterface::class) + ); } public function testNormalization() @@ -37,4 +60,24 @@ final class PersonJsonNormalizerTest extends KernelTestCase $this->assertIsArray($result); } + + private function buildPersonJsonNormalizer( + ChillEntityRenderExtension $render, + PersonRepository $repository, + CenterResolverManagerInterface $centerResolverManager, + ResidentialAddressRepository $residentialAddressRepository, + PhoneNumberHelperInterface $phoneNumberHelper, + NormalizerInterface $normalizer + ): PersonJsonNormalizer { + $personJsonNormalizer = new PersonJsonNormalizer( + $render, + $repository, + $centerResolverManager, + $residentialAddressRepository, + $phoneNumberHelper + ); + $personJsonNormalizer->setNormalizer($normalizer); + + return $personJsonNormalizer; + } }