add accompanying period where the person is requestor + badge in results

This commit is contained in:
Julien Fastré 2021-10-01 09:50:13 +02:00
parent f1f13996f9
commit 0d5d4b3f05
6 changed files with 145 additions and 38 deletions

View File

@ -213,7 +213,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
private $scopes;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="accompanyingPeriodRequested")
* @ORM\JoinColumn(nullable=true)
*/
private $requestorPerson;

View File

@ -129,4 +129,9 @@ class AccompanyingPeriodParticipation
return $this;
}
public function isOpen(): bool
{
return $this->endDate === null;
}
}

View File

@ -28,9 +28,9 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Country;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\MaritalStatus;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\Address;
@ -329,6 +329,15 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*/
private $accompanyingPeriodParticipations;
/**
* The accompanying period requested by the Person
*
* @ORM\OneToMany(targetEntity=AccompanyingPeriod::class,
* mappedBy="requestorPerson")
* @var Collection|AccompanyingPeriod[]
*/
private Collection $accompanyingPeriodRequested;
/**
* A remark over the person
* @var string
@ -478,6 +487,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
$this->genderComment = new CommentEmbeddable();
$this->maritalStatusComment = new CommentEmbeddable();
$this->periodLocatedOn = new ArrayCollection();
$this->accompanyingPeriodRequested = new ArrayCollection();
}
/**
@ -605,6 +615,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Get AccompanyingPeriodParticipations Collection
*
* @return AccompanyingPeriodParticipation[]|Collection
*/
public function getAccompanyingPeriodParticipations(): Collection
{
@ -614,6 +626,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Return a collection of participation, where the participation
* is still opened, not a draft, and the period is still opened
*
* @return AccompanyingPeriodParticipation[]|Collection
*/
public function getOpenedParticipations(): Collection
{
@ -1650,6 +1664,84 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
/**
* @return AccompanyingPeriod[]|Collection
*/
public function getAccompanyingPeriodRequested(): Collection
{
return $this->accompanyingPeriodRequested;
}
/**
* Return a list of all accompanying period where the person is involved:
*
* * as requestor;
* * as participant, only for opened participation;
*
* @param bool $asParticipantOpen add participation which are still opened
* @param bool $asRequestor add accompanying period where the person is requestor
* @return AccompanyingPeriod[]|Collection
*/
public function getAccompanyingPeriodInvolved(
bool $asParticipantOpen = true,
bool $asRequestor = true
): Collection
{
$result = new ArrayCollection();
if ($asParticipantOpen) {
foreach ($this->getOpenedParticipations()
->map(fn (AccompanyingPeriodParticipation $app) =>
$app->getAccompanyingPeriod())
as $period
) {
if (!$result->contains($period)) {
$result->add($period);
}
}
}
if ($asRequestor) {
foreach ($this->accompanyingPeriodRequested as $period) {
if (!$result->contains($period)) {
$result->add($period);
}
}
}
return $result;
}
/**
* Handy method to get the AccompanyingPeriodParticipation
* matching a given AccompanyingPeriod.
*
* Used in template, to find the participation when iterating on a list
* of period.
*
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $period
* @return AccompanyingPeriodParticipation
*/
public function findParticipationForPeriod(AccompanyingPeriod $period): ?AccompanyingPeriodParticipation
{
$closeCandidates = [];
foreach ($this->getAccompanyingPeriodParticipations() as $participation) {
if ($participation->getAccompanyingPeriod() === $period) {
if ($participation->isOpen()) {
return $participation;
}
$closeCandidates[] = $participation;
}
}
if (0 < count($closeCandidates)) {
return $closeCandidates[0];
}
return null;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;

View File

@ -59,47 +59,51 @@
'customButtons': { 'after': _self.button_person(person) }
}) }}
{#- 'apps' is for AccompanyingPeriodParticipationS #}
{%- set apps = [] %}
{%- for app in person.openedParticipations %}
{%- if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', app.accompanyingPeriod) %}
{%- set apps = apps|merge([app]) %}
{#- 'acps' is for AcCompanyingPeriodS #}
{%- set acps = [] %}
{%- for acp in person.accompanyingPeriodInvolved %}
{%- if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', acp) %}
{%- set acps = acps|merge([acp]) %}
{%- endif %}
{%- endfor %}
{% if apps|length > 0 %}
{# add as requestor #}
{% if acps|length > 0 %}
<div class="item-row">
<div class="wrap-list periods-list">
{% for app in apps %}
{% for acp in acps %}
{% set app = person.findParticipationForPeriod(acp) %}
<div class="wl-row separator">
<div class="wl-col title">
<div class="date">
{% if acp.requestorPerson == person %}
<span class="as-requestor badge bg-info" title="{{ 'Requestor'|trans|e('html_attr') }}">
{{ 'Requestor'|trans({'gender': person.gender}) }}
</span>
{% endif %}
{% if app != null %}
{{ 'Since %date%'|trans({'%date%': app.startDate|format_date('medium') }) }}
{% endif %}
</div>
{% if app.accompanyingPeriod.user is not null %}
{% if acp.user is not null %}
<div class="user">
<abbr class="referrer" title="{{ 'Referrer'|trans }}">ref:</abbr>
{{ app.accompanyingPeriod.user|chill_entity_render_box }}
{{ acp.user|chill_entity_render_box }}
</div>
{% endif %}
</div>
<div class="wl-col list">
{% for issue in app.accompanyingPeriod.socialIssues %}
{% for issue in acp.socialIssues %}
{{ issue|chill_entity_render_box }}
{% endfor %}
{# ^^ display all socialIssues, or slice vv
|slice(0,2)
{% if app.accompanyingPeriod.socialIssues|length > 2 %}
<span class="more">{{ 'and %number% other'|transchoice(app.accompanyingPeriod.socialIssues|length-2) }}</span>
{% endif %}
#}
<ul class="record_actions">
<li>
<a href="{{ path('chill_person_accompanying_course_index', { 'accompanying_period_id': app.accompanyingPeriod.id }) }}"
<a href="{{ path('chill_person_accompanying_course_index', { 'accompanying_period_id': acp.id }) }}"
class="btn btn-sm btn-outline-primary" title="{{ 'See accompanying period'|trans }}">
<i class="fa fa-random fa-fw"></i>
</a>

View File

@ -5,6 +5,13 @@ Born the date: >-
other {Né·e le {birthdate}}
}
Requestor: >-
{gender, select,
man {Demandeur}
woman {Demandeuse}
other {Demandeur·euse}
}
household:
Household: Ménage
Household number: Ménage {household_num}

View File

@ -189,7 +189,6 @@ Create an accompanying course: Créer un parcours
This accompanying course is still a draft: Ce parcours est à l'état brouillon
Associated peoples: Usagers concernés
Resources: Interlocuteurs privilégiés
Requestor: Demandeur
Any requestor to this accompanying course: Aucun demandeur pour ce parcours
Social actions: Actions d'accompagnement
Social issues: Problématiques sociales