mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
create view for current address and apply on Person/Household normalizer
This commit is contained in:
@@ -37,6 +37,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
||||
|
||||
/**
|
||||
* Person Class
|
||||
@@ -287,6 +288,14 @@ class Person implements HasCenterInterface
|
||||
*/
|
||||
private array $currentHouseholdAt = [];
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(
|
||||
* targetEntity=PersonHouseholdAddress::class,
|
||||
* mappedBy="person"
|
||||
* )
|
||||
*/
|
||||
private Collection $householdAddresses;
|
||||
|
||||
/**
|
||||
* Person constructor.
|
||||
*
|
||||
@@ -300,6 +309,7 @@ class Person implements HasCenterInterface
|
||||
$this->altNames = new ArrayCollection();
|
||||
$this->otherPhoneNumbers = new ArrayCollection();
|
||||
$this->householdParticipations = new ArrayCollection();
|
||||
$this->householdAddresses = new ArrayCollection();
|
||||
|
||||
if ($opening === null) {
|
||||
$opening = new \DateTime();
|
||||
@@ -1247,4 +1257,36 @@ class Person implements HasCenterInterface
|
||||
{
|
||||
return NULL !== $this->getCurrentHousehold($at);
|
||||
}
|
||||
|
||||
public function getHouseholdAddresses(): Collection
|
||||
{
|
||||
return $this->householdAddresses;
|
||||
}
|
||||
|
||||
public function getCurrentHouseholdAddress(?\DateTimeImmutable $at = null): ?Address
|
||||
{
|
||||
$at = $at === null ? new \DateTimeImmutable('today') : $at;
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where(
|
||||
$expr->lte('validFrom', $at)
|
||||
)
|
||||
->andWhere(
|
||||
$expr->orX(
|
||||
$expr->isNull('validTo'),
|
||||
$expr->gte('validTo', $at)
|
||||
)
|
||||
);
|
||||
|
||||
$addrs = $this->getHouseholdAddresses()
|
||||
->matching($criteria)
|
||||
;
|
||||
|
||||
if ($addrs->count() > 0) {
|
||||
return $addrs->first()->getAddress();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user