From 8a7b48b201f3dcf51887c938a885bc509c352af7 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 10 Jul 2024 12:49:05 +0200 Subject: [PATCH] Implement logic to save metadata to signature --- .../Controller/WorkflowController.php | 50 +++++++++++++++---- .../views/Workflow/_signature.html.twig | 11 ++-- .../translations/messages.fr.yml | 5 ++ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index 6cf5e763e..44c620213 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -15,7 +15,9 @@ 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\Entity\Workflow\EntityWorkflowStepSignature; use Chill\MainBundle\Form\EntityWorkflowCommentType; +use Chill\MainBundle\Form\WorkflowSignatureMetadataType; use Chill\MainBundle\Form\WorkflowStepType; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; @@ -36,6 +38,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\TransitionBlocker; +use Symfony\Component\Workflow\Workflow; use Symfony\Contracts\Translation\TranslatorInterface; class WorkflowController extends AbstractController @@ -284,16 +287,6 @@ class WorkflowController extends AbstractController if (!$signatures->isEmpty()) { $signaturesByPerson = $signatures[0]->getSigner() instanceof Person; } -/* $personSignatures = []; - $userSignatures = [];*/ - -/* foreach ($signatures as $signature) { - if ($signature->getSigner() instanceof Person) { - $personSignatures[] = $signature->getSigner(); - } else { - $userSignatures[] = $signature->getSigner(); - } - }*/ if (\count($workflow->getEnabledTransitions($entityWorkflow)) > 0) { // possible transition @@ -385,4 +378,41 @@ class WorkflowController extends AbstractController return $lines; } + + #[Route(path: '/{_locale}/main/workflow/{id}/signature/{signature_id}/metadata', name: 'chill_main_workflow_signature_metadata')] + public function addSignatureMetadata(EntityWorkflow $entityWorkflow, EntityWorkflowStepSignature $signature, Request $request): Response + { + $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( + [ + 'documentType' => $data['documentType'], + 'documentNumber' => $data['documentNumber'], + 'expirationDate' => $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' => $entityWorkflow->getId()]); + } + + + return $this->render( + '@ChillMain/Workflow/_signature_metadata.html.twig', + [ + 'metadata_form' => $metadataForm->createView(), + 'person' => $signature->getSigner() + ] + ); + } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig index 644d540a1..325868fc2 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig @@ -10,10 +10,15 @@
{{ s.getSigner.username }}
{% endif %}
+ {% if signaturesByPerson %} + {{ 'workflow.signature_zone.button_sign'|trans }} + {% else %} {{ 'workflow.signature_zone.button_sign'|trans }} - {% if s.state is same as('signed') %} -

{{ s.stateDate }}

- {% endif %} + {% endif %} + + {% if s.state is same as('signed') %} +

{{ s.stateDate }}

+ {% endif %}
{% endfor %} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index b39cf4bff..b47c34a88 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -531,6 +531,11 @@ workflow: signature_zone: title: Appliquer les signatures éléctroniques 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