request->get('id') ; $newsletter = $this->merchantUtils->getMerchantCurrent()->getNewsletter() ; if($newsletter) { $users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; $countUsers = count($users) ; $messages = []; $news = $this->em->getRepository($this->em->getClassMetadata(NewsInterface::class)->getName())->find($idNews) ; if($news) { foreach ($users as $user) { $message = new \Swift_Message('[Place du Local] '.$news->getTitle()); $message->addTo($user->getEmail()) ->addFrom($this->getParameter('app.noreply_email'), $this->getParameter('app.site_name')) ->setBody($this->renderView('mail/news.html.twig', [ 'message' => $news->getDescription(), 'image' => $news->getImage(), 'newsletter' => $newsletter, 'user' => $user ]), 'text/html'); array_push($messages, $message); } if($countUsers > 0) { $result = $this->mailjetTransport->bulkSend($messages); $this->addFlash('success', 'Actualité envoyée à '.count($users).' utilisateurs.'); $news->setIsSent(true) ; $this->em->persist($news); $this->em->flush() ; } else { $this->addFlash('error', 'Aucun utilisateur inscrit à la newsletter.'); } } else { throw new NotFoundHttpException('Actualité introuvable') ; } } else { throw new \ErrorException('Aucune newsletter n\'est lié à ce Merchant.') ; } return $this->redirectToRoute('easyadmin', ['entity' => 'News', 'action' => 'list']) ; } }