PersonAddressMoveEvent on household move (wip)

This commit is contained in:
2022-02-19 14:04:51 +01:00
parent 8675bb65c1
commit caa63ea97a
11 changed files with 237 additions and 48 deletions

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Entity\Address;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
@@ -22,7 +23,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity
* @ORM\Table("chill_person_accompanying_period_location_history")
*/
class AccompanyingPeriodLocationHistory
class AccompanyingPeriodLocationHistory implements TrackCreationInterface
{
use TrackCreationTrait;

View File

@@ -106,20 +106,74 @@ class Household
$this->compositions = new ArrayCollection();
}
/**
* @return $this
*/
public function addAddress(Address $address)
public function addAddress(Address $address): self
{
foreach ($this->getAddresses() as $a) {
if ($a->getValidFrom() <= $address->getValidFrom() && $a->getValidTo() === null) {
$a->setValidTo($address->getValidFrom());
if (!$this->addresses->contains($address)) {
$this->addresses[] = $address;
$this->makeAddressConsistent();
}
return $this;
}
public function getAddressesOrdered(): array
{
$addresses = $this->getAddresses()->toArray();
usort($addresses, function (Address $a, Address $b) {
$validFromA = $a->getValidFrom()->format('Y-m-d');
$validFromB = $b->getValidFrom()->format('Y-m-d');
if ($a === $b) {
if (null === $a->getId()) {
return 1;
}
if (null === $b->getId()) {
return -1;
}
return $a->getId() <=> $b->getId();
}
return $validFromA <=> $validFromB;
});
return $addresses;
}
public function getPreviousAddressOf(Address $address): ?Address
{
$iterator = new ArrayIterator($this->getAddressesOrdered());
$iterator->rewind();
while ($iterator->valid()) {
$current = $iterator->current();
$iterator->next();
if ($iterator->valid()) {
if ($address === $iterator->current()) {
return $current;
}
}
}
$this->addresses[] = $address;
return null;
}
return $this;
public function makeAddressConsistent(): void
{
$iterator = new ArrayIterator($this->getAddressesOrdered());
$iterator->rewind();
while ($iterator->valid()) {
$current = $iterator->current();
$iterator->next();
if ($iterator->valid()) {
$current->setValidTo($iterator->current()->getValidFrom());
}
}
}
public function addComposition(HouseholdComposition $composition): self