getNewsletter() ; $news = $this->getNews() ; $merchantCurrent = $this->merchantUtils->getMerchantCurrent() ; $merchantConfigEmailContact = $merchantCurrent->getMerchantConfig('email-contact'); if($merchantConfigEmailContact && strlen($merchantConfigEmailContact)) { $this->mailUtils->send([ MailUtils::SUBJECT => $news->getTitle(), MailUtils::TO_EMAIL => $merchantConfigEmailContact, MailUtils::TO_NAME => $this->parameterBag->get('app.site_name'), MailUtils::CONTENT_TEMPLATE => 'mail/news', MailUtils::CONTENT_DATA => [ 'news' => $news, 'newsletter' => $newsletter, 'user' => $this->security->getUser() ], ]); $this->addFlash('success', 'Actualité de test envoyée à '.$merchantConfigEmailContact); } else { throw new \ErrorException("L'email de contact n'est pas défini pour ce Merchant.") ; } return $this->redirectToRoute('easyadmin', ['entity' => 'News', 'action' => 'list']) ; } public function sendAction() { $newsletter = $this->getNewsletter() ; $news = $this->getNews() ; $users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; $countUsers = count($users) ; $messages = []; 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.html.twig', [ 'news' => $news, '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.'); } return $this->redirectToRoute('easyadmin', ['entity' => 'News', 'action' => 'list']) ; } public function getNewsletter() { $newsletter = $this->merchantUtils->getMerchantCurrent()->getNewsletter() ; if($newsletter) { return $newsletter ; } else { throw new \ErrorException('Aucune newsletter n\'est liée à ce Merchant.') ; } } public function getNews() { $idNews = $this->request->get('id') ; $news = $this->em->getRepository($this->em->getClassMetadata(NewsInterface::class)->getName())->find($idNews) ; if($news) { return $news ; } else { throw new NotFoundHttpException('Actualité introuvable') ; } } }