|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function sendAction() |
|
|
public function sendAction() |
|
|
{ |
|
|
{ |
|
|
|
|
|
ini_set('memory_limit', '-1'); |
|
|
|
|
|
|
|
|
$currentMerchant = $this->merchantUtils->getMerchantCurrent() ; |
|
|
$currentMerchant = $this->merchantUtils->getMerchantCurrent() ; |
|
|
$newsletter = $this->getNewsletter() ; |
|
|
$newsletter = $this->getNewsletter() ; |
|
|
$news = $this->getNews() ; |
|
|
$news = $this->getNews() ; |
|
|
$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 = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$packageMessagesArray = []; |
|
|
|
|
|
$packageMessageLimit = 50 ; |
|
|
|
|
|
|
|
|
|
|
|
$paramsTemplate = [ |
|
|
|
|
|
'news' => $news, |
|
|
|
|
|
'newsletter' => $newsletter, |
|
|
|
|
|
'user' => $this->security->getUser() |
|
|
|
|
|
] ; |
|
|
|
|
|
|
|
|
|
|
|
$i = 0 ; |
|
|
foreach ($users as $user) { |
|
|
foreach ($users as $user) { |
|
|
$toArray[] = [ |
|
|
|
|
|
'Email' => $user->getEmail(), |
|
|
|
|
|
'Name' => $user->getFirstname().' '.$user->getLastname(), |
|
|
|
|
|
] ; |
|
|
|
|
|
|
|
|
if(!isset($packageMessagesArray[$i])) { |
|
|
|
|
|
$packageMessagesArray[$i] = [] ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if($user->getEmail() && strlen($user->getEmail())) { |
|
|
|
|
|
$packageMessagesArray[$i][] = [ |
|
|
|
|
|
'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(count($packageMessagesArray[$i]) >= $packageMessageLimit) { |
|
|
|
|
|
$i ++ ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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 = [ |
|
|
|
|
|
'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 |
|
|
|
|
|
] |
|
|
|
|
|
] |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = $mj->post(Resources::$Email, ['body' => $body]); |
|
|
|
|
|
|
|
|
|
|
|
if($response->success()) { |
|
|
|
|
|
|
|
|
foreach($packageMessagesArray as $messagesArray) { |
|
|
|
|
|
$body = [ |
|
|
|
|
|
'Messages' => $messagesArray |
|
|
|
|
|
]; |
|
|
|
|
|
$response = $mj->post(Resources::$Email, ['body' => $body]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(isset($response) && $response->success()) { |
|
|
$this->addFlash('success', 'Actualité envoyée à '.$countUsers.' utilisateurs.'); |
|
|
$this->addFlash('success', 'Actualité envoyée à '.$countUsers.' utilisateurs.'); |
|
|
|
|
|
|
|
|
$news->setIsSent(true) ; |
|
|
$news->setIsSent(true) ; |