|
|
|
|
|
|
|
|
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; |
|
|
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; |
|
|
|
|
|
|
|
|
$countUsers = count($users) ; |
|
|
$countUsers = count($users) ; |
|
|
$toArray = []; |
|
|
|
|
|
|
|
|
$messagesArray = []; |
|
|
|
|
|
|
|
|
|
|
|
$paramsTemplate = [ |
|
|
|
|
|
'news' => $news, |
|
|
|
|
|
'newsletter' => $newsletter, |
|
|
|
|
|
'user' => $this->security->getUser() |
|
|
|
|
|
] ; |
|
|
|
|
|
|
|
|
foreach ($users as $user) { |
|
|
foreach ($users as $user) { |
|
|
$toArray[] = [ |
|
|
|
|
|
'Email' => $user->getEmail(), |
|
|
|
|
|
'Name' => $user->getFirstname().' '.$user->getLastname(), |
|
|
|
|
|
] ; |
|
|
|
|
|
|
|
|
if($user->getEmail() && strlen($user->getEmail())) { |
|
|
|
|
|
$messagesArray[] = [ |
|
|
|
|
|
'To' => [ |
|
|
|
|
|
[ |
|
|
|
|
|
'Email' => $user->getEmail(), |
|
|
|
|
|
'Name' => $user->getFirstname().' '.$user->getLastname(), |
|
|
|
|
|
] |
|
|
|
|
|
], |
|
|
|
|
|
'From' => [ |
|
|
|
|
|
'Email' => $this->getParameter('app.noreply_email'), |
|
|
|
|
|
'Name' => $this->getParameter('app.site_name') |
|
|
|
|
|
], |
|
|
|
|
|
'Subject' => $currentMerchant->getMerchantConfig('email-subject-prefix').' '.$news->getTitle(), |
|
|
|
|
|
'TextPart' => $this->renderView('mail/news-text.html.twig', $paramsTemplate), |
|
|
|
|
|
'HTMLPart' => $this->renderView('mail/news-html.html.twig', $paramsTemplate), |
|
|
|
|
|
'CustomCampaign' => $news->getTitle(), |
|
|
|
|
|
'DeduplicateCampaign' => true |
|
|
|
|
|
] ; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if($countUsers > 0) { |
|
|
if($countUsers > 0) { |
|
|
|
|
|
|
|
|
$mj = new \Mailjet\Client($this->mailjetTransport->getApiKey(), $this->mailjetTransport->getApiSecret(),true,['version' => 'v3.1']); |
|
|
$mj = new \Mailjet\Client($this->mailjetTransport->getApiKey(), $this->mailjetTransport->getApiSecret(),true,['version' => 'v3.1']); |
|
|
|
|
|
|
|
|
$paramsTemplate = [ |
|
|
|
|
|
'news' => $news, |
|
|
|
|
|
'newsletter' => $newsletter, |
|
|
|
|
|
'user' => $this->security->getUser() |
|
|
|
|
|
] ; |
|
|
|
|
|
|
|
|
|
|
|
$body = [ |
|
|
$body = [ |
|
|
'Messages' => [ |
|
|
|
|
|
[ |
|
|
|
|
|
'From' => [ |
|
|
|
|
|
'Email' => $this->getParameter('app.noreply_email'), |
|
|
|
|
|
'Name' => $this->getParameter('app.site_name') |
|
|
|
|
|
], |
|
|
|
|
|
'To' => $toArray, |
|
|
|
|
|
'Subject' => $currentMerchant->getMerchantConfig('email-subject-prefix').' '.$news->getTitle(), |
|
|
|
|
|
'TextPart' => $this->renderView('mail/news-text.html.twig', $paramsTemplate), |
|
|
|
|
|
'HTMLPart' => $this->renderView('mail/news-html.html.twig', $paramsTemplate), |
|
|
|
|
|
'CustomCampaign' => $news->getTitle(), |
|
|
|
|
|
'DeduplicateCampaign' => true |
|
|
|
|
|
] |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
'Messages' => $messagesArray |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = $mj->post(Resources::$Email, ['body' => $body]); |
|
|
$response = $mj->post(Resources::$Email, ['body' => $body]); |
|
|
|
|
|
|
|
|
if($response->success()) { |
|
|
if($response->success()) { |
|
|
|
|
|
|
|
|
$this->em->flush() ; |
|
|
$this->em->flush() ; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
print_r($response->getBody()) ; |
|
|
|
|
|
die() ; |
|
|
$this->addFlash('error', "Une erreur est survenue lors de l'envoi de l'actualité."); |
|
|
$this->addFlash('error', "Une erreur est survenue lors de l'envoi de l'actualité."); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |