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 7b24eae0d..35fa6e319 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Generator/basic_form.html.twig @@ -2,6 +2,14 @@ {% block title 'docgen.Generate a document'|trans %} +{% block js %} + {{ encore_entry_script_tags('mod_pickentity_type') }} +{% endblock %} + +{% block css %} + {{ encore_entry_link_tags('mod_pickentity_type') }} +{% endblock %} + {% block content %}

{{ block('title') }}

diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php new file mode 100644 index 000000000..58a6b5863 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php @@ -0,0 +1,55 @@ +personContext = $personContext; + $this->normalizer = $normalizer; + } + + public function adminFormReverseTransform(array $data): array + { + return array_merge( + $this->personContext->adminFormReverseTransform($data), + ['label' => $data['label']] + ); + } + + public function adminFormTransform(array $data): array + { + return array_merge( + $this->personContext->adminFormTransform($data), + ['label' => $data['label'] ?? ''] + ); + } + + public function buildAdminForm(FormBuilderInterface $builder): void + { + $this->personContext->buildAdminForm($builder); + + $builder->add('label', TextType::class, [ + 'label' => 'docgen.Label for third party', + 'required' => true, + ]); + } + + public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void + { + $this->personContext->buildPublicForm($builder, $template, $entity); + + $builder->add('thirdParty', PickThirdpartyDynamicType::class, [ + 'multiple' => false, + 'label' => $template->getOptions()['label'] ?? 'ThirdParty', + 'validation_groups' => ['__none__'], + ]); + } + + public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array + { + $data = $this->personContext->getData($template, $entity, $contextGenerationData); + + $data['thirdParty'] = $this->normalizer->normalize( + $contextGenerationData['thirdParty'], + 'docgen', + ['docgen:expects' => ThirdParty::class, 'groups' => ['docgen:read']] + ); + + return $data; + } + + public function getDescription(): string + { + return 'docgen.A context for person with a third party (for sending mail)'; + } + + public function getEntityClass(): string + { + return $this->personContext->getEntityClass(); + } + + public function getFormData(DocGeneratorTemplate $template, $entity): array + { + return $this->personContext->getFormData($template, $entity); + } + + public static function getKey(): string + { + return self::class; + } + + public function getName(): string + { + return 'docgen.Person with third party'; + } + + public function hasAdminForm(): bool + { + return true; + } + + public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool + { + return true; + } + + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void + { + $this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextWithThirdPartyTest.php b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextWithThirdPartyTest.php new file mode 100644 index 000000000..a4f08e7c1 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Service/DocGenerator/PersonContextWithThirdPartyTest.php @@ -0,0 +1,93 @@ +buildPersonContextWithThirdParty(); + + $actual = $personContext->adminFormReverseTransform(['label' => 'bloup']); + + $this->assertArrayHasKey('category', $actual); + $this->assertArrayHasKey('label', $actual); + $this->assertEquals('bloup', $actual['label']); + } + + public function testAdminFormTransform() + { + $personContext = $this->buildPersonContextWithThirdParty(); + + $actual = $personContext->adminFormTransform(['label' => 'bloup']); + + $this->assertArrayHasKey('from_person', $actual); + $this->assertArrayHasKey('label', $actual); + $this->assertEquals('bloup', $actual['label']); + } + + public function testGetData() + { + $personContext = $this->buildPersonContextWithThirdParty(); + + $actual = $personContext->getData( + (new DocGeneratorTemplate())->setOptions(['label' => 'bloup']), + new Person(), + ['thirdParty' => $tp = new ThirdParty()] + ); + + $this->assertArrayHasKey('person', $actual); + $this->assertArrayHasKey('thirdParty', $actual); + $this->assertEquals(spl_object_hash($tp), $actual['thirdParty']['hash']); + } + + private function buildPersonContextWithThirdParty(): PersonContextWithThirdParty + { + $normalizer = $this->prophesize(NormalizerInterface::class); + $normalizer->normalize(Argument::type(ThirdParty::class), 'docgen', Argument::type('array')) + ->will(static function ($args): array { + return ['class' => '3party', 'hash' => spl_object_hash($args[0])]; + }); + + $personContext = $this->prophesize(PersonContextInterface::class); + + $personContext->adminFormReverseTransform(Argument::type('array'))->willReturn( + ['category' => ['idInsideBundle' => 1, 'bundleId' => 'abc']] + ); + $personContext->adminFormTransform(Argument::type('array'))->willReturn( + ['from_person' => 'kept'] + ); + $personContext->getData(Argument::type(DocGeneratorTemplate::class), Argument::type(Person::class), Argument::type('array')) + ->willReturn(['person' => 'data']); + + return new PersonContextWithThirdParty( + $personContext->reveal(), + $normalizer->reveal() + ); + } +} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 6ad3737b7..dc2e5020f 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -858,6 +858,10 @@ docgen: 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 + Person with third party: Personne avec choix d'un tiers + A context for person with a third party (for sending mail): Un contexte d'une personne avec un tiers (pour envoyer un courrier à ce tiers, par exemple) + Label for third party: Label à afficher aux utilisateurs + Document title: Titre du document généré period_notification: period_designated_subject: Vous êtes référent d'un parcours d'accompagnement diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 119afff11..2e8cebfb6 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -214,7 +214,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface /** * @ORM\Column(name="kind", type="string", length="20", options={"default": ""}) - * @Groups({"write"}) + * @Groups({"write", "docgen:read", "docgen:read:3party:parent"}) */ private ?string $kind = '';