add accompanying period where the person is requestor + badge in results

This commit is contained in:
2021-10-01 09:50:13 +02:00
parent f1f13996f9
commit 0d5d4b3f05
6 changed files with 145 additions and 38 deletions

View File

@@ -28,9 +28,9 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Country;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\MaritalStatus;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\Address;
@@ -329,6 +329,15 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*/
private $accompanyingPeriodParticipations;
/**
* The accompanying period requested by the Person
*
* @ORM\OneToMany(targetEntity=AccompanyingPeriod::class,
* mappedBy="requestorPerson")
* @var Collection|AccompanyingPeriod[]
*/
private Collection $accompanyingPeriodRequested;
/**
* A remark over the person
* @var string
@@ -478,6 +487,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
$this->genderComment = new CommentEmbeddable();
$this->maritalStatusComment = new CommentEmbeddable();
$this->periodLocatedOn = new ArrayCollection();
$this->accompanyingPeriodRequested = new ArrayCollection();
}
/**
@@ -605,6 +615,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Get AccompanyingPeriodParticipations Collection
*
* @return AccompanyingPeriodParticipation[]|Collection
*/
public function getAccompanyingPeriodParticipations(): Collection
{
@@ -614,6 +626,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Return a collection of participation, where the participation
* is still opened, not a draft, and the period is still opened
*
* @return AccompanyingPeriodParticipation[]|Collection
*/
public function getOpenedParticipations(): Collection
{
@@ -1650,6 +1664,84 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
/**
* @return AccompanyingPeriod[]|Collection
*/
public function getAccompanyingPeriodRequested(): Collection
{
return $this->accompanyingPeriodRequested;
}
/**
* Return a list of all accompanying period where the person is involved:
*
* * as requestor;
* * as participant, only for opened participation;
*
* @param bool $asParticipantOpen add participation which are still opened
* @param bool $asRequestor add accompanying period where the person is requestor
* @return AccompanyingPeriod[]|Collection
*/
public function getAccompanyingPeriodInvolved(
bool $asParticipantOpen = true,
bool $asRequestor = true
): Collection
{
$result = new ArrayCollection();
if ($asParticipantOpen) {
foreach ($this->getOpenedParticipations()
->map(fn (AccompanyingPeriodParticipation $app) =>
$app->getAccompanyingPeriod())
as $period
) {
if (!$result->contains($period)) {
$result->add($period);
}
}
}
if ($asRequestor) {
foreach ($this->accompanyingPeriodRequested as $period) {
if (!$result->contains($period)) {
$result->add($period);
}
}
}
return $result;
}
/**
* Handy method to get the AccompanyingPeriodParticipation
* matching a given AccompanyingPeriod.
*
* Used in template, to find the participation when iterating on a list
* of period.
*
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $period
* @return AccompanyingPeriodParticipation
*/
public function findParticipationForPeriod(AccompanyingPeriod $period): ?AccompanyingPeriodParticipation
{
$closeCandidates = [];
foreach ($this->getAccompanyingPeriodParticipations() as $participation) {
if ($participation->getAccompanyingPeriod() === $period) {
if ($participation->isOpen()) {
return $participation;
}
$closeCandidates[] = $participation;
}
}
if (0 < count($closeCandidates)) {
return $closeCandidates[0];
}
return null;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;