Merge branch 'features/household-members-list' into features/household-editor

This commit is contained in:
2021-06-07 17:36:25 +02:00
18 changed files with 433 additions and 27 deletions

View File

@@ -5,6 +5,7 @@ namespace Chill\PersonBundle\Entity\Household;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\Serializer\Annotation as Serializer;
use Chill\MainBundle\Entity\Address;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
@@ -97,6 +98,66 @@ class Household
return $this->members;
}
public function getCurrentMembers(\DateTimeImmutable $now = null): Collection
{
$criteria = new Criteria();
$expr = Criteria::expr();
$date = $now === null ? (new \DateTimeImmutable('now')) : $now;
$criteria
->where($expr->orX(
$expr->isNull('startDate'),
$expr->lte('startDate', $date)
))
->andWhere($expr->orX(
$expr->isNull('endDate'),
$expr->gte('endDate', $date)
));
return $this->getMembers()->matching($criteria);
}
public function getNonCurrentMembers(\DateTimeImmutable $now = null): Collection
{
$criteria = new Criteria();
$expr = Criteria::expr();
$date = $now === null ? (new \DateTimeImmutable('now')) : $now;
$criteria
->where(
$expr->gt('startDate', $date)
)
->orWhere(
$expr->andX(
$expr->lt('endDate', $date),
$expr->neq('endDate', null)
)
);
return $this->getMembers()->matching($criteria);
}
public function getCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
$criteria->where($expr->eq('position', $position));
return $this->getCurrentMembers($now)->matching($criteria);
}
public function getNonCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
$criteria->where($expr->eq('position', $position));
return $this->getNonCurrentMembers($now)->matching($criteria);
}
public function addMember(HouseholdMember $member): self
{
if (!$this->members->contains($member)) {

View File

@@ -120,7 +120,7 @@ class HouseholdMember
return $this->endDate;
}
public function setEndDate(\DateTimeImmutable $endDate): self
public function setEndDate(?\DateTimeImmutable $endDate = null): self
{
$this->endDate = $endDate;

View File

@@ -81,6 +81,11 @@ class Position
return $this->allowHolder;
}
public function isAllowHolder(): ?bool
{
return $this->getAllowHolder();
}
public function setAllowHolder(bool $allowHolder): self
{
$this->allowHolder = $allowHolder;