entityManager = $entityManager; $this->engine = $engine; $this->metadataExtractor = $metadataExtractor; $this->registry = $registry; $this->security = $security; } public static function getSubscribedEvents(): array { return [ 'workflow.completed' => 'onCompleted', ]; } public function onCompleted(Event $event): void { if (!$event->getSubject() instanceof EntityWorkflow) { return; } /** @var EntityWorkflow $entityWorkflow */ $entityWorkflow = $event->getSubject(); $dests = array_merge( $entityWorkflow->getSubscriberToStep()->toArray(), $entityWorkflow->isFinal() ? $entityWorkflow->getSubscriberToFinal()->toArray() : [], $entityWorkflow->getCurrentStep()->getDestUser()->toArray() ); $place = $this->metadataExtractor->buildArrayPresentationForPlace($entityWorkflow); $workflow = $this->metadataExtractor->buildArrayPresentationForWorkflow( $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName()) ); $visited = []; foreach ($dests as $subscriber) { if ( $this->security->getUser() === $subscriber || in_array($subscriber->getId(), $visited, true) ) { continue; } $context = [ 'entity_workflow' => $entityWorkflow, 'dest' => $subscriber, 'place' => $place, 'workflow' => $workflow, 'is_dest' => $entityWorkflow->getCurrentStep()->getDestUser()->contains($subscriber), ]; $notification = new Notification(); $notification ->setRelatedEntityId($entityWorkflow->getId()) ->setRelatedEntityClass(EntityWorkflow::class) ->setTitle($this->engine->render('@ChillMain/Workflow/workflow_notification_on_transition_completed_title.fr.txt.twig', $context)) ->setMessage($this->engine->render('@ChillMain/Workflow/workflow_notification_on_transition_completed_content.fr.txt.twig', $context)) ->addAddressee($subscriber); $this->entityManager->persist($notification); $visited[] = $subscriber->getId(); } } }