[AccompanyingCourse location] Indicate course location on course index

page
This commit is contained in:
Julien Fastré 2021-08-18 10:52:13 +02:00
parent 75d3dfb830
commit a0afaa568d
5 changed files with 97 additions and 14 deletions

View File

@ -499,6 +499,17 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
return $collection->count() > 0 ? $collection->first() : NULL;
}
public function getOPenParticipations(): Collection
{
return $this
->getParticipations()
->filter(
static function(AccompanyingPeriodParticipation $participation): bool {
return null === $participation->getEndDate();
}
);
}
/**
* Return true if the accompanying period contains a person.
*
@ -974,6 +985,22 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
return $this->personLocation;
}
/**
* Get a list of person which have an adresse available for a valid location
*
* @return Collection|Person[]
*/
public function getAvailablePersonLocation(): Collection
{
return $this->getOPenParticipations()
->filter(function(AccompanyingPeriodParticipation $p) {
return $p->getPerson()->hasCurrentHouseholdAddress();
})
->map(function(AccompanyingPeriodParticipation $p) {
return $p->getPerson();
});
}
/**
* @Groups({"write"})
*/

View File

@ -103,7 +103,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*
* @ORM\Column(type="date", nullable=true)
*/
private $birthdate;
private $birthdate;
/**
* The person's deathdate
@ -736,8 +736,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
{
return $this->birthdate;
}
public function getAge(): ?int
public function getAge(): ?int
{
if ($this->birthdate instanceof \DateTimeInterface) {
return date_diff($this->birthdate, date_create('now'))->format("%y");
@ -1439,6 +1439,11 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
}
}
public function hasCurrentHouseholdAddress(?\DateTimeImmutable $at = null): bool
{
return null !== $this->getCurrentHouseholdAddress($at);
}
public function getGenderComment(): CommentEmbeddable
{
return $this->genderComment;

View File

@ -1,5 +1,38 @@
<div class="alert alert-danger alert-with-actions mb-0">
<div class="message">
{{ 'This course is located at a temporarily address. You should locate this course to an user'|trans }}
{%- set hasPersonLocation = accompanyingCourse.availablePersonLocation|length > 0 -%}
<div class="border border-danger">
<div class="alert alert-danger {% if hasPersonLocation %}alert-with-actions{% endif %} mb-0">
<div class="message">
{{ 'This course is located at a temporarily address. You should locate this course to an user'|trans }}
{% if not hasPersonLocation %}
{{ 'Associate at least one member with an household, and set an address to this household'|trans }}
{% endif %}
</div>
{% if hasPersonLocation %}
<ul class="record_actions">
<li>
<button class="btn btn-chill-pink" data-bs-toggle="collapse" href="#locateAtPerson">
<i class="fa fa-fw fa-caret-down"></i><span class="text-light">{{ 'Choose a person to locate by'|trans }}</span>
</button>
</li>
</ul>
{% endif %}
</div>
{% if hasPersonLocation %}
<div id="locateAtPerson">
<form method="GET" action="#">
<p>{{ 'Locate by'|trans }}:</p>
<ul>
{% for p in accompanyingCourse.availablePersonLocation %}
<li>
<input type="radio" name="persons[]" value="{{ p.id }}">
{{ p|chill_entity_render_box }}
</li>
{% endfor %}
</ul>
</form>
</div>
{% endif %}
</div>

View File

@ -27,11 +27,6 @@
</a>
</span>
</div>
{% if accompanyingCourse.locationStatus == 'address' or accompanyingCourse.locationStatus == 'none' %}
<div class="alert alert-danger">
{{ 'This course is located at a temporarily address. You should locate this course to an user'|trans }}
</div>
{% endif %}
{% endif %}
<h1>{{ 'Resume Accompanying Course'|trans }}</h1>
@ -54,12 +49,29 @@
{% if withoutHousehold|length > 0 %}
{% include '@ChillPerson/AccompanyingCourse/_join_household.html.twig' with {} %}
{% endif %}
{% if accompanyingCourse.locationStatus == 'address' or accompanyingCourse.locationStatus == 'none' %}
{% include '@ChillPerson/AccompanyingCourse/_warning_address.html.twig' with {} %}
{% endif %}
{% endif %}
</div>
<div class="location mb-5">
<h2 class="mb-3">{{ 'Accompanying course location'|trans }}</h2>
{% if accompanyingCourse.locationStatus == 'person' %}
<p>{{ 'This course is located by'|trans }}: {{ accompanyingCourse.personLocation|chill_entity_render_string }}</p>
{% elseif accompanyingCourse.locationStatus == 'address' %}
<p>{{ 'This course has a temporarily location'|trans }}</p>
{% endif %}
{% if accompanyingCourse.locationStatus != 'none' %}
{{ accompanyingCourse.location|chill_entity_render_box }}
{% endif %}
{% if accompanyingCourse.locationStatus == 'address' or accompanyingCourse.locationStatus == 'none' %}
{% include '@ChillPerson/AccompanyingCourse/_warning_address.html.twig' with {} %}
{% endif %}
</div>
<div class="requestor mb-5">
<h2 class="mb-3">{{ 'Requestor'|trans }}</h2>
{% if accompanyingCourse.requestorPerson is not empty %}

View File

@ -376,6 +376,12 @@ Edit Accompanying Course: Modifier le parcours
Create Accompanying Course: Créer un nouveau parcours
Drop Accompanying Course: Supprimer le parcours
This course is located at a temporarily address. You should locate this course to an user: Ce parcours est localisé à une adresse temporaire. Il devrait être localisé auprès d'un usager concerné.
Accompanying course location: Localisation du parcours
This course is located by: Ce parcours est localisé auprès de
This course has a temporarily location: Ce parcours a une localisation temporaire
Choose a person to locate by: Localiser auprès d'un usager concerné
Associate at least one member with an household, and set an address to this household: Associez au moins un membre du parcours à un ménage, et indiquez une adresse à ce ménage.
Locate by: Localiser auprès de
# Household
Household: Ménage