diff --git a/.changes/unreleased/Feature-20240718-151233.yaml b/.changes/unreleased/Feature-20240718-151233.yaml new file mode 100644 index 000000000..6e2666be8 --- /dev/null +++ b/.changes/unreleased/Feature-20240718-151233.yaml @@ -0,0 +1,5 @@ +kind: Feature +body: Metadata form added for person signatures +time: 2024-07-18T15:12:33.8134266+02:00 +custom: + Issue: "288" diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index 6898d87e4..cdd432cf7 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -13,9 +13,9 @@ namespace Chill\MainBundle\Controller; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; -use Chill\MainBundle\Entity\Workflow\EntityWorkflowComment; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep; -use Chill\MainBundle\Form\EntityWorkflowCommentType; +use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature; +use Chill\MainBundle\Form\WorkflowSignatureMetadataType; use Chill\MainBundle\Form\WorkflowStepType; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; @@ -289,6 +289,7 @@ class WorkflowController extends AbstractController $handler = $this->entityWorkflowManager->getHandler($entityWorkflow); $workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName()); $errors = []; + $signatures = $entityWorkflow->getCurrentStep()->getSignatures(); if (\count($workflow->getEnabledTransitions($entityWorkflow)) > 0) { // possible transition @@ -341,22 +342,6 @@ class WorkflowController extends AbstractController } } - /* - $commentForm = $this->createForm(EntityWorkflowCommentType::class, $newComment = new EntityWorkflowComment()); - $commentForm->handleRequest($request); - - if ($commentForm->isSubmitted() && $commentForm->isValid()) { - $this->entityManager->persist($newComment); - $this->entityManager->flush(); - - $this->addFlash('success', $this->translator->trans('workflow.Comment added')); - - return $this->redirectToRoute('chill_main_workflow_show', ['id' => $entityWorkflow->getId()]); - } elseif ($commentForm->isSubmitted() && !$commentForm->isValid()) { - $this->addFlash('error', $this->translator->trans('This form contains errors')); - } - */ - return $this->render( '@ChillMain/Workflow/index.html.twig', [ @@ -366,7 +351,7 @@ class WorkflowController extends AbstractController 'transition_form' => isset($transitionForm) ? $transitionForm->createView() : null, 'entity_workflow' => $entityWorkflow, 'transition_form_errors' => $errors, - // 'comment_form' => $commentForm->createView(), + 'signatures' => $signatures, ] ); } @@ -385,4 +370,47 @@ class WorkflowController extends AbstractController return $lines; } + + #[Route(path: '/{_locale}/main/workflow/signature/{signature_id}/metadata', name: 'chill_main_workflow_signature_metadata')] + public function addSignatureMetadata(int $signature_id, Request $request): Response + { + $signature = $this->entityManager->getRepository(EntityWorkflowStepSignature::class)->find($signature_id); + + if ($signature->getSigner() instanceof User) { + return $this->redirectToRoute('signature_route_user'); + } + + $metadataForm = $this->createForm(WorkflowSignatureMetadataType::class); + $metadataForm->add('submit', SubmitType::class, ['label' => $this->translator->trans('Save')]); + + $metadataForm->handleRequest($request); + + if ($metadataForm->isSubmitted() && $metadataForm->isValid()) { + $data = $metadataForm->getData(); + + $signature->setSignatureMetadata( + [ + 'base_signer' => [ + 'document_type' => $data['documentType'], + 'document_number' => $data['documentNumber'], + 'expiration_date' => $data['expirationDate'], + ], + ] + ); + + $this->entityManager->persist($signature); + $this->entityManager->flush(); + + // Todo should redirect to document for actual signing? To be adjusted still + return $this->redirectToRoute('chill_main_workflow_show', ['id' => $signature->getStep()->getEntityWorkflow()->getId()]); + } + + return $this->render( + '@ChillMain/Workflow/_signature_metadata.html.twig', + [ + 'metadata_form' => $metadataForm->createView(), + 'person' => $signature->getSigner(), + ] + ); + } } diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 4dde2076c..bf041b5b3 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -193,6 +193,11 @@ class ChillMainExtension extends Extension implements [] ); + $container->setParameter( + 'chill_main.id_document_kinds', + $config['id_document_kinds'] + ); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yaml'); $loader->load('services/doctrine.yaml'); diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 8bd3e35f4..9c890d9fe 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -151,6 +151,28 @@ class Configuration implements ConfigurationInterface ->append($this->addWidgetsConfiguration('homepage', $this->containerBuilder)) ->end() // end of widgets/children ->end() // end of widgets + ->arrayNode('id_document_kinds')->defaultValue([]) + ->arrayPrototype() + ->children() + ->scalarNode('key')->isRequired()->cannotBeEmpty() + ->info('the key stored in database') + ->example('id_card') + ->end() + ->arrayNode('labels')->isRequired()->requiresAtLeastOneElement() + ->arrayPrototype() + ->children() + ->scalarNode('lang')->isRequired()->cannotBeEmpty() + ->example('fr') + ->end() + ->scalarNode('label')->isRequired()->cannotBeEmpty() + ->example('Carte de séjour') + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() // end of document types ->arrayNode('cruds') ->defaultValue([]) ->arrayPrototype() diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowSignatureMetadataType.php b/src/Bundle/ChillMainBundle/Form/WorkflowSignatureMetadataType.php new file mode 100644 index 000000000..47be9b88c --- /dev/null +++ b/src/Bundle/ChillMainBundle/Form/WorkflowSignatureMetadataType.php @@ -0,0 +1,62 @@ +parameterBag->get('chill_main.id_document_kinds'); + + $choices = []; + + foreach ($documentTypeChoices as $documentType) { + $labels = []; + + foreach ($documentType['labels'] as $label) { + $labels[$label['lang']] = $label['label']; + } + + $localizedLabel = $this->translatableStringHelper->localize($labels); + if (null !== $localizedLabel) { + $choices[$localizedLabel] = $documentType['key']; + } + } + + $builder + ->add('documentType', ChoiceType::class, [ + 'label' => 'workflow.signature_zone.metadata.docType', + 'expanded' => false, + 'required' => true, + 'choices' => $choices, + ]) + ->add('documentNumber', TextType::class, [ + 'required' => true, + 'label' => 'workflow.signature_zone.metadata.docNumber', + ]) + ->add('expirationDate', ChillDateType::class, [ + 'required' => true, + 'input' => 'datetime_immutable', + 'label' => 'workflow.signature_zone.metadata.docExpiration', + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig new file mode 100644 index 000000000..a61808500 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig @@ -0,0 +1,19 @@ +

{{ 'workflow.signature_zone.title'|trans }}

+ +
+
+ {% for s in signatures %} +
+
{{ s.signer|chill_entity_render_box }}
+
+ {{ 'workflow.signature_zone.button_sign'|trans }} + {% if s.state is same as('signed') %} +

{{ s.stateDate }}

+ {% endif %} +
+
+ {% endfor %} +
+
+ + diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature_metadata.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature_metadata.html.twig new file mode 100644 index 000000000..5b828832d --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature_metadata.html.twig @@ -0,0 +1,24 @@ +{% extends '@ChillMain/layout.html.twig' %} + +{% block title %} + {{ 'Signature'|trans }} +{% endblock %} + +{% block content %} +
+

{{ 'workflow.signature_zone.metadata.sign_by'|trans({ '%name%' : person.firstname ~ ' ' ~ person.lastname}) }}

+ + {% if metadata_form is not null %} + {{ form_start(metadata_form) }} + {{ form_row(metadata_form.documentType) }} + {{ form_row(metadata_form.documentNumber) }} + {{ form_row(metadata_form.expirationDate) }} + + {{ form_end(metadata_form) }} + {% endif %} +
+{% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig index 782eae136..da4d073b2 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig @@ -57,6 +57,9 @@
{% include '@ChillMain/Workflow/_follow.html.twig' %}
+ {% if signatures|length > 0 %} +
{% include '@ChillMain/Workflow/_signature.html.twig' %}
+ {% endif %}
{% include '@ChillMain/Workflow/_decision.html.twig' %}
{#
{% include '@ChillMain/Workflow/_comment.html.twig' %}
#}
{% include '@ChillMain/Workflow/_history.html.twig' %}
diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/person_signature_form.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/person_signature_form.html.twig new file mode 100644 index 000000000..e69de29bb diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index ce303701c..f6b50cb57 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -133,6 +133,8 @@ services: Chill\MainBundle\Form\WorkflowStepType: ~ + Chill\MainBundle\Form\WorkflowSignatureMetadataType: ~ + Chill\MainBundle\Form\DataMapper\PrivateCommentDataMapper: autowire: true autoconfigure: true diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 421cac473..924ccec3a 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -528,6 +528,15 @@ workflow: This link grant any user to apply a transition: Le lien d'accès suivant permet d'appliquer une transition The workflow may be accssed through this link: Une transition peut être appliquée sur ce workflow grâce au lien d'accès suivant + signature_zone: + title: Appliquer les signatures électroniques + button_sign: Signer + metadata: + sign_by: 'Signature pour %name%' + docType: Type de document + docNumber: Numéro de document + docExpiration: Date d'expiration + Subscribe final: Recevoir une notification à l'étape finale Subscribe all steps: Recevoir une notification à chaque étape