mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
first impl of event (WIP)
This commit is contained in:
@@ -15,13 +15,13 @@ use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use LogicException;
|
||||
use Symfony\Component\Validator\ConstraintViolationList;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
use function in_array;
|
||||
use function spl_object_hash;
|
||||
|
||||
@@ -41,12 +41,17 @@ class MembersEditor
|
||||
|
||||
private array $persistables = [];
|
||||
|
||||
private array $events = [];
|
||||
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
public function __construct(ValidatorInterface $validator, ?Household $household)
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
public function __construct(ValidatorInterface $validator, ?Household $household, EventDispatcherInterface $eventDispatcher)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
$this->household = $household;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
public function addMovement(DateTimeImmutable $date, Person $person, Position $position, ?bool $holder = false, ?string $comment = null): self
|
||||
@@ -55,6 +60,8 @@ class MembersEditor
|
||||
throw new LogicException('You must define a household first');
|
||||
}
|
||||
|
||||
$event = new PersonAddressMoveEvent($person);
|
||||
|
||||
$membership = (new HouseholdMember())
|
||||
->setStartDate($date)
|
||||
->setPerson($person)
|
||||
@@ -62,6 +69,7 @@ class MembersEditor
|
||||
->setHolder($holder)
|
||||
->setComment($comment);
|
||||
$this->household->addMember($membership);
|
||||
$event->setNextMembership($membership);
|
||||
|
||||
if ($position->getShareHousehold()) {
|
||||
foreach ($person->getHouseholdParticipationsShareHousehold() as $participation) {
|
||||
@@ -74,6 +82,7 @@ class MembersEditor
|
||||
}
|
||||
|
||||
if ($participation->getEndDate() === null || $participation->getEndDate() > $date) {
|
||||
$event->setPreviousMembership($participation);
|
||||
$participation->setEndDate($date);
|
||||
$this->membershipsAffected[] = $participation;
|
||||
$this->oldMembershipsHashes[] = spl_object_hash($participation);
|
||||
@@ -92,6 +101,7 @@ class MembersEditor
|
||||
|
||||
$this->membershipsAffected[] = $membership;
|
||||
$this->persistables[] = $membership;
|
||||
$this->events[] = $event;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -129,6 +139,8 @@ class MembersEditor
|
||||
->matching($criteria);
|
||||
|
||||
foreach ($participations as $participation) {
|
||||
$this->events[] = $event = new PersonAddressMoveEvent();
|
||||
$event->setPreviousMembership($participation);
|
||||
$participation->setEndDate($date);
|
||||
$this->membershipsAffected[] = $participation;
|
||||
}
|
||||
@@ -136,6 +148,13 @@ class MembersEditor
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function postMove(): void
|
||||
{
|
||||
foreach ($this->events as $event) {
|
||||
$this->eventDispatcher->dispatch($event);
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(): ConstraintViolationListInterface
|
||||
{
|
||||
if ($this->hasHousehold()) {
|
||||
|
Reference in New Issue
Block a user