diff --git a/src/Bundle/ChillMainBundle/Workflow/Templating/WorkflowEntityRender.php b/src/Bundle/ChillMainBundle/Workflow/Templating/WorkflowEntityRender.php new file mode 100644 index 000000000..9f51d03ad --- /dev/null +++ b/src/Bundle/ChillMainBundle/Workflow/Templating/WorkflowEntityRender.php @@ -0,0 +1,46 @@ +entityWorkflowManager->getHandler($entity); + + return $this->twig->render( + $handler->getTemplate($entity), + $handler->getTemplateData($entity) + ); + } + + public function renderString($entity, array $options): string + { + /** @var EntityWorkflow $entity */ + $handler = $this->entityWorkflowManager->getHandler($entity); + + return $handler->getEntityTitle($entity, $options); + } + + public function supports(object $entity, array $options): bool + { + return $entity instanceof EntityWorkflow; + } +} diff --git a/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml index 430d866ab..5c67b3eaa 100644 --- a/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillMainBundle/translations/messages+intl-icu.fr.yaml @@ -67,6 +67,12 @@ workflow: one {Signature demandée} other {Signatures demandées} } + pending_signatures: >- + {nb_signatures, plural, + =0 {Aucune signature demandée} + one {Une signature demandée} + other {# signatures demandées} + } send_external_message: document_available_until: Le lien sera valable jusqu'au {expiration, date, long} à {expiration, time, short}. explanation: '{sender} vous fait parvenir des documents.' diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 0b4b54681..5d24f3114 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -24,6 +24,8 @@ use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\Language; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum; +use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature; use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\HouseholdMember; @@ -39,6 +41,7 @@ use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; +use Doctrine\Common\Collections\ReadableCollection; use Doctrine\Common\Collections\Selectable; use Doctrine\ORM\Mapping as ORM; use libphonenumber\PhoneNumber; @@ -382,6 +385,12 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI #[ORM\ManyToOne(targetEntity: User::class)] private ?User $updatedBy = null; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: EntityWorkflowStepSignature::class, mappedBy: 'personSigner', orphanRemoval: true)] + private Collection $signatures; + /** * Person constructor. */ @@ -403,6 +412,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI $this->budgetCharges = new ArrayCollection(); $this->resources = new ArrayCollection(); $this->centerHistory = new ArrayCollection(); + $this->signatures = new ArrayCollection(); } public function __toString(): string @@ -474,6 +484,35 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this; } + public function addSignature(EntityWorkflowStepSignature $signature): self + { + if (!$this->signatures->contains($signature)) { + $this->signatures->add($signature); + } + + return $this; + } + + public function removeSignature(EntityWorkflowStepSignature $signature): self + { + $this->signatures->removeElement($signature); + + return $this; + } + + /** + * @return ReadableCollection + */ + public function getSignatures(): ReadableCollection + { + return $this->signatures; + } + + public function getSignaturesPending(): ReadableCollection + { + return $this->signatures->filter(fn (EntityWorkflowStepSignature $signature) => EntityWorkflowSignatureStateEnum::PENDING === $signature->getState()); + } + /** * Function used for validation that check if the accompanying periods of * the person are not collapsing (i.e. have not shared days) or having diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig index c48771aac..fa7a1b6ea 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig @@ -224,6 +224,33 @@ + {% if person.signaturesPending|length > 0 %} +
+
+
+
+

{{ 'workflow.pending_signatures'|trans({nb_signatures: person.signaturesPending|length}) }}

+
+
+ {% for signature in person.signaturesPending %} + {% set entityWorkflow = signature.step.entityWorkflow %} + {{ entityWorkflow|chill_entity_render_string }} + + {% endfor %} +
+
+
+
+ {% endif %} {% endmacro %}