diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index 72ca7aa5b..79d263f78 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -197,7 +197,7 @@ $workflow = $this->registry->get($accompanyingPeriod); * @ParamConverter("person", options={"id" = "person_id"}) */ public function getAccompanyingPeriodsByPerson(Person $person){ - $accompanyingPeriods = $person->getAccompanyingPeriods(); + $accompanyingPeriods = $person->getCurrentAccompanyingPeriods(); $accompanyingPeriodsChecked = array_filter($accompanyingPeriods, function(AccompanyingPeriod $period){ return $this->isGranted(AccompanyingPeriodVoter::SEE, $period); diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 01a524beb..5fdb4e8d2 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -613,6 +613,26 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $accompanyingPeriods; } + /** + * Get current accompanyingPeriods array + */ + public function getCurrentAccompanyingPeriods(): array + { + $currentAccompanyingPeriods = []; + $currentDate = new DateTime(); + + foreach ($this->accompanyingPeriodParticipations as $participation) + { + $endDate = $participation->getEndDate(); + + if ($endDate === null || $endDate > $currentDate){ + $currentAccompanyingPeriods[] = $participation->getAccompanyingPeriod(); + } + } + + return $currentAccompanyingPeriods; + } + /** * Get AccompanyingPeriodParticipations Collection *