userRepository->findByRole('ROLE_ADMIN'); $number = sprintf('CT-%03d', $ticket->getNumber()); $projectName = $ticket->getProject()?->getName() ?? ''; foreach ($admins as $admin) { $notification = new Notification(); $notification->setUser($admin); $notification->setType('ticket_created'); $notification->setTitle('Nouveau ticket client '.$number); $notification->setMessage($ticket->getTitle().' — '.$projectName); $notification->setRelatedTicket($ticket); $notification->setCreatedAt(new DateTimeImmutable()); $this->entityManager->persist($notification); } $this->entityManager->flush(); } /** * Notify the ticket submitter that the status has changed. */ public function createForStatusChange(ClientTicket $ticket): void { $submittedBy = $ticket->getSubmittedBy(); if (null === $submittedBy) { return; } $number = sprintf('CT-%03d', $ticket->getNumber()); $statusComment = $ticket->getStatusComment(); $message = 'Nouveau statut : '.$ticket->getStatus(); if (null !== $statusComment && '' !== $statusComment) { $message .= ' — '.$statusComment; } $notification = new Notification(); $notification->setUser($submittedBy); $notification->setType('ticket_status_changed'); $notification->setTitle('Ticket '.$number.' mis à jour'); $notification->setMessage($message); $notification->setRelatedTicket($ticket); $notification->setCreatedAt(new DateTimeImmutable()); $this->entityManager->persist($notification); $this->entityManager->flush(); } }