Implement logic to save metadata to signature

This commit is contained in:
Julie Lenaerts 2024-07-10 12:49:05 +02:00
parent 52a9aab73f
commit 8a7b48b201
3 changed files with 53 additions and 13 deletions

View File

@ -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()
]
);
}
}

View File

@ -10,10 +10,15 @@
<div class="col-sm-6"><span>{{ s.getSigner.username }}</span></div>
{% endif %}
<div class="col-sm-6">
{% if signaturesByPerson %}
<a class="btn btn-show" href="{{ chill_path_add_return_path('chill_main_workflow_signature_metadata', { 'id': entity_workflow.id, 'signature_id': s.id}) }}">{{ 'workflow.signature_zone.button_sign'|trans }}</a>
{% else %}
<a class="btn btn-show" href="#">{{ 'workflow.signature_zone.button_sign'|trans }}</a>
{% if s.state is same as('signed') %}
<p class="updatedBy">{{ s.stateDate }}</p>
{% endif %}
{% endif %}
{% if s.state is same as('signed') %}
<p class="updatedBy">{{ s.stateDate }}</p>
{% endif %}
</div>
</div>
{% endfor %}

View File

@ -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