mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'fix-getParticipationsContainsPerson' into 'master'
Fix `::getParticipationsContainsPerson`. See merge request Chill-Projet/chill-bundles!50
This commit is contained in:
commit
126ffc55bf
@ -447,12 +447,13 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
*/
|
||||
public function getParticipationsContainsPerson(Person $person): Collection
|
||||
{
|
||||
return $this->getParticipations($person)->filter(
|
||||
function(AccompanyingPeriodParticipation $participation) use ($person) {
|
||||
if ($person === $participation->getPerson()) {
|
||||
return $participation;
|
||||
return $this
|
||||
->getParticipations()
|
||||
->filter(
|
||||
static function(AccompanyingPeriodParticipation $participation) use ($person): bool {
|
||||
return $person === $participation->getPerson();
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -462,12 +463,13 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
*/
|
||||
public function getOpenParticipationContainsPerson(Person $person): ?AccompanyingPeriodParticipation
|
||||
{
|
||||
$collection = $this->getParticipationsContainsPerson($person)->filter(
|
||||
function(AccompanyingPeriodParticipation $participation) use ($person) {
|
||||
if (NULL === $participation->getEndDate()) {
|
||||
return $participation;
|
||||
$collection = $this
|
||||
->getParticipationsContainsPerson($person)
|
||||
->filter(
|
||||
static function(AccompanyingPeriodParticipation $participation): bool {
|
||||
return null === $participation->getEndDate();
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
return $collection->count() > 0 ? $collection->first() : NULL;
|
||||
}
|
||||
@ -557,15 +559,16 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
$participation = $this->getParticipationsContainsPerson($person);
|
||||
if (!null === $participation)
|
||||
$participation = $this->getOpenParticipationContainsPerson($person);
|
||||
|
||||
if (null === $participation)
|
||||
{
|
||||
$person = $participation->getPerson();
|
||||
$periods = $person->getAccompanyingPeriodsOrdered();
|
||||
return end($periods) === $this;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
$periods = $participation->getPerson()->getAccompanyingPeriodsOrdered();
|
||||
|
||||
return end($periods) === $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -825,14 +828,18 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
|
||||
/**
|
||||
* Get a list of all persons which are participating to this course
|
||||
*
|
||||
* @psalm-return Collection<int, Person>
|
||||
*/
|
||||
public function getPersons(): Collection
|
||||
{
|
||||
return $this->participations->map(
|
||||
function(AccompanyingPeriodParticipation $participation) {
|
||||
return $participation->getPerson();
|
||||
}
|
||||
);
|
||||
return $this
|
||||
->participations
|
||||
->map(
|
||||
static function(AccompanyingPeriodParticipation $participation): Person {
|
||||
return $participation->getPerson();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTimeInterface $datetime): self
|
||||
|
Loading…
x
Reference in New Issue
Block a user