test on members editor post move + listen for event (wip)

This commit is contained in:
2022-02-15 00:23:01 +01:00
parent b9dbb1916a
commit 1658fee090
7 changed files with 111 additions and 3 deletions

View File

@@ -0,0 +1,53 @@
<?php
namespace Chill\PersonBundle\AccompanyingPeriod\Events;
use Chill\MainBundle\Entity\Notification;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class PersonMoveEventSubscriber implements EventSubscriberInterface
{
private TranslatorInterface $translator;
private Security $security;
public static function getSubscribedEvents()
{
return [
PersonAddressMoveEvent::class => 'resetPeriodLocation'
];
}
public function resetPeriodLocation(PersonAddressMoveEvent $event)
{
if ($event->getPreviousAddress() !== $event->getNextAddress()
&& null !== $event->getPreviousAddress()
) {
$person = $event->getPerson();
foreach ($person->getCurrentAccompanyingPeriods() as $period) {
if ($period->getPersonLocation() === $person) {
$period->setPersonLocation(null);
$period->setAddressLocation($event->getPreviousAddress());
if (null !== $period->getUser() && $period->getUser() !== $this->security->getUser()) {
$notification = new Notification();
$notification
->addAddressee($period->getUser())
->setTitle($this->translator->trans())
->setRelatedEntityClass(AccompanyingPeriod::class)
->setRelatedEntityId($period->getId())
;
}
}
}
}
}
}