diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 830a9e48e..1c375d051 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -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"}) */ diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index cf00eb9f1..084a24ca3 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -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; diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_warning_address.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_warning_address.html.twig index d56ed6442..f8e2dad92 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_warning_address.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/_warning_address.html.twig @@ -1,5 +1,38 @@ -
{{ 'This course is located by'|trans }}: {{ accompanyingCourse.personLocation|chill_entity_render_string }}
+ {% elseif accompanyingCourse.locationStatus == 'address' %} +{{ 'This course has a temporarily location'|trans }}
+ {% 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 %} + + +