method added to get current accompanying periods + api adjusted

This commit is contained in:
Julie Lenaerts 2021-11-05 17:00:07 +01:00
parent cab7cc4150
commit f064e8f307
2 changed files with 21 additions and 1 deletions

View File

@ -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);

View File

@ -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
*