security = $security; $this->translator = $translator; $this->engine = $engine; $this->notificationPersister = $notificationPersister; } public static function getSubscribedEvents() { return [ 'workflow.accompanying_period_lifecycle.entered' => [ 'onStateEntered', ], ]; } public function onStateEntered(EnteredEvent $enteredEvent): void { if ($enteredEvent->getMarking()->has(AccompanyingPeriod::STEP_CONFIRMED)) { $this->onPeriodConfirmed($enteredEvent->getSubject()); } } public function postUpdate(AccompanyingPeriod $period, LifecycleEventArgs $args): void { if ($period->isChangedUser() && $period->getUser() !== $this->security->getUser() && null !== $period->getUser() && $period->getStep() !== AccompanyingPeriod::STEP_DRAFT && !$period->isPreventUserIsChangedNotification() ) { $this->generateNotificationToUser($period); } } private function generateNotificationToUser(AccompanyingPeriod $period) { $notification = new Notification(); $urgentStatement = $period->isEmergency() ? strtoupper($this->translator->trans('accompanying_period.emergency')) . ' ' : ''; $notification ->setRelatedEntityId($period->getId()) ->setRelatedEntityClass(AccompanyingPeriod::class) ->setTitle($urgentStatement . $this->translator->trans('period_notification.period_designated_subject')) ->setMessage($this->engine->render( '@ChillPerson/Notification/accompanying_course_designation.md.twig', [ 'accompanyingCourse' => $period, ] )) ->addAddressee($period->getUser()); $this->notificationPersister->persist($notification); } private function onPeriodConfirmed(AccompanyingPeriod $period) { if ($period->getUser() instanceof User && $period->getUser() !== $this->security->getUser()) { $this->generateNotificationToUser($period); } } }