Show pending signatures in the person's search results

This commit is contained in:
Julien Fastré 2024-10-15 15:15:32 +02:00
parent d8ded80582
commit 9fe20b5e81
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Workflow\Templating;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Workflow\EntityWorkflowManager;
use Twig\Environment;
final readonly class WorkflowEntityRender implements ChillEntityRenderInterface
{
public function __construct(private EntityWorkflowManager $entityWorkflowManager, private Environment $twig) {}
public function renderBox($entity, array $options): string
{
/** @var EntityWorkflow $entity */
$handler = $this->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;
}
}

View File

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

View File

@ -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<int, EntityWorkflowStepSignature>
*/
#[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<int, EntityWorkflowStepSignature>
*/
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

View File

@ -224,6 +224,33 @@
</ul>
</div>
</div>
{% if person.signaturesPending|length > 0 %}
<div class="item-row separator">
<div class="wrap-list periods-list">
<div class="wl-row">
<div class="wl-col title">
<h3>{{ 'workflow.pending_signatures'|trans({nb_signatures: person.signaturesPending|length}) }}</h3>
</div>
<div class="wl-col list">
{% for signature in person.signaturesPending %}
{% set entityWorkflow = signature.step.entityWorkflow %}
{{ entityWorkflow|chill_entity_render_string }}
<ul class="record_actions small slim">
<li>
<a href="{{ chill_path_add_return_path('chill_main_workflow_signature_metadata', {signature_id: signature.id}) }}" class="btn btn-misc">
<i class="fa fa-pencil"></i>
</a>
</li>
<li>
<a href="{{ chill_path_add_return_path('chill_main_workflow_show', {id: entityWorkflow.id}) }}" class="btn btn-show"></a>
</li>
</ul>
{% endfor %}
</div>
</div>
</div>
</div>
{% endif %}
{% endmacro %}
<div class="list-with-period">