mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 18:43:49 +00:00
test on members editor post move + listen for event (wip)
This commit is contained in:
@@ -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())
|
||||
;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user