src/Controller/MaillingController.php line 363

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: anthony
  5.  * Date: 25/05/18
  6.  * Time: 10:45
  7.  */
  8. namespace App\Controller;
  9. use App\Entity\Actualite;
  10. use App\Entity\Auth\AuthUser;
  11. use App\Entity\Client;
  12. use App\Entity\ClientRoleUser;
  13. use App\Entity\Coupure;
  14. use App\Entity\Email\AdresseMailVerif;
  15. use App\Entity\Email\EmailRetour;
  16. use App\Entity\Mailling;
  17. use App\Entity\PieceJointeMailling;
  18. use App\Entity\ThemeDescriptif;
  19. use App\Entity\Veille;
  20. use App\Ovh\OvhSend;
  21. use App\Service\Coupure\GenerateCoupureInterface;
  22. use App\Service\Ftp\FtpGetPieceJointe;
  23. use App\Service\MaillingEnCour\MaillingEnCour;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  26. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  27. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  28. use Spipu\Html2Pdf\Html2Pdf;
  29. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  30. use Symfony\Component\HttpFoundation\JsonResponse;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\HttpFoundation\Response;
  33. use Symfony\Component\HttpKernel\KernelInterface;
  34. use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
  35. use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
  36. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  37. use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
  38. use Symfony\Component\Serializer\Serializer;
  39. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  40. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  41. use Doctrine\Common\Annotations\AnnotationReader;
  42. use PDO;
  43. class MaillingController extends Controller
  44. {
  45.     /**
  46.      * @Route("api/maillings/maillings/getErreur/{idMailling}", methods={"GET"}, name="get.erreur.mailling.en.cours")
  47.      */
  48.     public function getErreurMaillingEnCourAction($idMaillingEntityManagerInterface $emMaillingEnCour $maillingEnCour){
  49.         $maillingEnCoursErreur $maillingEnCour->getMaillingErreur($idMailling);
  50.         $encoders = array(new XmlEncoder(), new JsonEncoder());
  51.         $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
  52.         $normalizer = new PropertyNormalizer($classMetadataFactory);
  53.         $dateTimeNormalizer = new DateTimeNormalizer('d-m-y H:i');
  54.         $serializer = new Serializer([$normalizer,$dateTimeNormalizer], $encoders);
  55.         $jsonContent $serializer->normalize($maillingEnCoursErreurnull, array('groups' => array('email_retour')));
  56.         $response = new JsonResponse($jsonContent);
  57.         $response->headers->set('Content-Type''application/json');
  58.         return $response;
  59.     }
  60.     /**
  61.      * @Route("/maillings/content/{id}",methods={"GET"},name="get.mailling.content")
  62.      */
  63.     public function getMaillingContentAction($idRequest $requestKernelInterface $kernel)
  64.     {
  65.         $em $this->get('doctrine.orm.entity_manager');
  66.         $mailling $em->getRepository('App\Entity\Mailling')
  67.             ->find($request->get('id'));
  68.         $path $kernel->getRootDir() . '/../public/maillings/' $mailling->getAncienId() . '.html';
  69.         $read file_get_contents($path);
  70.         return new JsonResponse(utf8_encode($read));
  71.     }
  72.     /**
  73.      * @Route("/maillings/getNbEnvoyer/{id}",methods={"GET"},name="get.mailling.nb.envoyer")
  74.      */
  75.     public function getMaillingNbEnvoyer($id)
  76.     {
  77.         $em $this->get('doctrine.orm.entity_manager');
  78.         $mailling $em->getRepository('App\Entity\Mailling')
  79.             ->findOneBy(['ancienId' => $id]);
  80.         return new JsonResponse($mailling->getNbMailEnvoye());
  81.     }
  82.     /**
  83.      * @Route("/maillings/checkDelete",methods={"GET"},name="mail.check")
  84.      */
  85.     public function getCheckMailAction()
  86.     {
  87.         $em $this->get('doctrine.orm.entity_manager');
  88.         $maillings $em->getRepository("App\Entity\Mailling")
  89.             ->findBy(['envoyer' => 'enCour' => ]);
  90.         $checkIfMaillingExist $this->get('check.mailling.exist');
  91.         $anomalieGestion $this->get('gestion.anomalie');
  92.         foreach ($maillings as $mailling){
  93.             if($checkIfMaillingExist->checKMailling($mailling) < 1){
  94.                 $suivitOuvertures $em->getRepository('App:SuivitOuvertureMailling')
  95.                     ->findBy(['mailling' => $mailling]);
  96.                 if(count($suivitOuvertures) < 1){
  97.                     $em->remove($mailling);
  98.                 }
  99.                 else{
  100.                     $anomalieGestion->addAnomalieDeleteWithSuivit($mailling);
  101.                 }
  102.             }
  103.         }
  104.         $em->flush();
  105.         return new Response('ok');
  106.     }
  107.     /**
  108.      * @Route("/maillings/send/test/{idMailling}/{idAuthUser}",methods={"GET"},name="send.mailling.test")
  109.      */
  110.     public function getSendMailTestAction($idMailling$idAuthUserMaillingEnCour $maillingEnCourKernelInterface $kernel)
  111.     {
  112.         $em $this->get('doctrine.orm.entity_manager');
  113.         $mailling $em->getRepository("App\Entity\Mailling")
  114.             ->find($idMailling);
  115.         $authUser $em->getRepository("App\Entity\Auth\AuthUser")
  116.             ->find($idAuthUser);
  117.         if($authUser){
  118.             if($mailling){
  119.                 /** @var Mailling $mailling
  120.                  *  @var AuthUser $authUser
  121.                  */
  122.                 if (strpos($mailling->getEnvoyePar()->getAdresseEnvoi(), '@escalconsulting.com') !== false) {
  123.                     $maillingEnCour->addTestSend($mailling,$authUser);
  124.                     return new JsonResponse('mail test lancé en envoi');
  125.                 } else {
  126.                     return new JsonResponse('l\'utilisateur ne possède pas d\'addresse d\'envoi');
  127.                 }
  128.             } else {
  129.                 return new JsonResponse('le mailling n\'existe pas');
  130.             }
  131.         } else {
  132.             return new JsonResponse('l\'utilisateur n\'existe pas');
  133.         }
  134.     }
  135.     /**
  136.      * @Route("/maillings/send/veille/{id}", methods={"GET"}, name="mailling.veille.send")
  137.      */
  138.     public function sendVeilleAction(MaillingEnCour $maillingEnCourEntityManagerInterface $em$idKernelInterface $kernel){
  139.         $veille $em->getRepository('App:Veille')->find($id);
  140.         if($veille){
  141.             $match_date $veille->getDate();
  142.             $date = new \DateTime();
  143.             $interval $date->diff($match_date);
  144.             if($interval->days == 0) {
  145.                 if(!$veille->getValider()){
  146.                     $veille->setValider(true);
  147.                     $em->persist($veille);
  148.                     $em->flush();
  149.                     $maillingEnCour->addVeilleSend($veille);
  150.                     $this->importerVeilleNetwork($id$em$kernel);
  151.                     return new JsonResponse('veille lancer en envoi');
  152.                 }
  153.             }
  154.         }
  155.        return new JsonResponse('veille déja envoyé');
  156.     }
  157.     /**
  158.      * @Route("/maillings/importer/veille/network/{id}", methods={"GET"}, name="mailling_importer_veille_network")
  159.      */
  160.     public function importerVeilleNetwork($idEntityManagerInterface $emKernelInterface $kernel){
  161.         $veille $em->getRepository('App:Veille')->find($id);
  162.         if ($veille){
  163.             $spreadsheet = new Spreadsheet();
  164.             $sheet $spreadsheet->getActiveSheet();
  165.             $date = new \DateTime('today');
  166.             $dateF = new \DateTime('tomorrow');
  167.             $sheet->setCellValue("A1""Articles veille du " $date->format('Y-m-d'));
  168.             $ligne 2;
  169.             $veilles =  $em->getRepository('App:Veille')->findAll();
  170.             foreach ($veilles as $veille) {
  171.                 if($veille->getDate()>= $date && $veille->getDate()<= $dateF){
  172.                     foreach ($veille->getVeilleThematiques() as $veilleThematique) {
  173.                         foreach ($veilleThematique->getElementsVeille() as $element) {
  174.                             $sheet->setCellValue("A" $ligne'=Hyperlink("'.$element->getLiens().'")');
  175.                             $ligne $ligne 1;
  176.                         }
  177.                     }
  178.                 }
  179.             }
  180.             foreach (range('A''B') as $columnID) {
  181.                 $spreadsheet->getActiveSheet()->getColumnDimension($columnID)
  182.                     ->setAutoSize(true);
  183.             }
  184.             $writer = new Xlsx($spreadsheet);
  185.             $fileName './excelStat/Veille Quotidienne du '$date->format('Y-m-d').'.xlsx';
  186.             $writer->save($fileName);
  187.             $file $kernel->getRootDir() . '/../public/excelStat/Veille Quotidienne du '$date->format('Y-m-d').'.xlsx';
  188.             // Enregistrement sur le Network
  189.             $ftp_server "docs.escalconsulting.com";
  190.             $ftp_conn ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
  191.             ftp_login($ftp_conn'informatique''E9;b5+AAx%k6')or die("Cannot login");
  192.             ftp_pasv($ftp_conntrue) or die("Cannot switch to passive mode");
  193.             ftp_put($ftp_conn"/../ESCAL Consulting/Network/Conseil/Veille Quotidienne/Veille Quotidienne du "$date->format('Y-m-d').".xlsx"$file);
  194.             ftp_close($ftp_conn);
  195.             // retirer du fichier public
  196.             if (file_exists($file)) {
  197.                 unlink($file);
  198.             }
  199.         }
  200.         return new JsonResponse('veille importee');
  201.     }
  202.     /**
  203.      * @Route("/maillings/supprimer/veille/network/{id}", methods={"GET"}, name="mailling_supprimer_veille_network")
  204.      */
  205.     public function supprimerVeilleNetwork($idEntityManagerInterface $emKernelInterface $kernel){
  206.         $veille $em->getRepository('App:Veille')->find($id);
  207.         if ($veille){
  208.             $date = new \DateTime('today');
  209.             // supprimer du network
  210.             $ftp_server "docs.escalconsulting.com";
  211.             $ftp_conn ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
  212.             ftp_login($ftp_conn'informatique''E9;b5+AAx%k6') or die("Cannot login");
  213.             ftp_pasv($ftp_conntrue) or die("Cannot switch to passive mode");
  214.             ftp_delete($ftp_conn"/../ESCAL Consulting/Network/Conseil/Veille Quotidienne/Veille Quotidienne du "$date->format('Y-m-d').".xlsx");
  215.             ftp_close($ftp_conn);
  216.         }
  217.         return new JsonResponse('veille supprimée');
  218.     }
  219.     /**
  220.      * @Route("/maillings/send/date/{idMailling}",methods={"GET"},name="send.mail.date")
  221.      */
  222.     public function getSendMaillingDateAction($idMailling MaillingEnCour $maillingEnCourRequest $request)
  223.     {
  224.         ini_set('memory_limit',-1);
  225.         set_time_limit(0);
  226.         $dateEnvoie $request->query->get('date');
  227.         $dateEnvoie = new \DateTime($dateEnvoie);
  228.         $em $this->get('doctrine.orm.entity_manager');
  229.         $mailling $em->getRepository("App\Entity\Mailling")
  230.             ->find($idMailling);
  231.         if($mailling){
  232.             if($mailling->getValiderEnvoi()){
  233.                 if(!$mailling->getEnCour()){
  234.                     if(!$mailling->getEnvoyer()){
  235.                         if (strpos($mailling->getEnvoyePar()->getAdresseEnvoi(), '@escalconsulting.com') !== false) {
  236.                             $mailling->setEnCour(true);
  237.                             $em->persist($mailling);
  238.                             $em->flush();
  239.                             if($maillingEnCour->addMaillingSend($mailling$dateEnvoietrue) == false){
  240.                                 return new JsonResponse('le mailling est déja en cours d\'envoi');
  241.                             }
  242.                             return new JsonResponse('le mailling a été lancé en envoi');
  243.                         } else {
  244.                             return new JsonResponse('l\'utilisateur ne possède pas d\'addresse d\'envoi');
  245.                         }
  246.                     } else {
  247.                         return new JsonResponse('le mailling est déjà en envoyé');
  248.                     }
  249.                 } else {
  250.                     return new JsonResponse('le mailling est déjà en cours d\'envoi');
  251.                 }
  252.             } else {
  253.                 return new JsonResponse('le mailling doit être validé');
  254.             }
  255.         } else {
  256.             return new JsonResponse('le mailling n\'existe pas');
  257.         }
  258.     }
  259.     /**
  260.      * @Route("/maillings/send/{idMailling}",methods={"GET"},name="send.mail.reel")
  261.      */
  262.     public function getSendMaillingAction($idMailling MaillingEnCour $maillingEnCourOvhSend $ovhSendActualiteController $actualiteController)
  263.     {
  264.         ini_set('memory_limit',-1);
  265.         set_time_limit(0);
  266.         $em $this->get('doctrine.orm.entity_manager');
  267.         $mailling $em->getRepository("App\Entity\Mailling")
  268.             ->find($idMailling);
  269.         /** @var Mailling $mailling */
  270.         if($mailling){
  271.             if($mailling->getValiderEnvoi()){
  272.                 if(!$mailling->getEnCour()){
  273.                     if(!$mailling->getEnvoyer()){
  274.                         if (strpos($mailling->getEnvoyePar()->getAdresseEnvoi(), '@escalconsulting.com') !== false) {
  275.                             $mailling->setEnCour(true);
  276.                             $em->persist($mailling);
  277.                             $em->flush();
  278.                             if ($mailling->getTypeMail() == 'CP') {
  279.                                 // on créé une actualité
  280.                                 $this->creerActualiteMailing($idMailling$em$ovhSend$actualiteController);
  281.                                 // on envoie le contenu final du cp à intranet
  282.                                 try
  283.                                 {
  284.                                     $bdd = new PDO('mysql:host=185.126.230.125;dbname=escal_web;charset=utf8''escalprod''skl001');
  285.                                 }
  286.                                 catch (Exception $e)
  287.                                 {
  288.                                     die('Erreur : ' $e->getMessage());
  289.                                 }
  290.                                 $contenu $mailling->getContent();
  291.                                 $query 'UPDATE `ecw_mails` SET `contenu_cp`="'.$contenu.'"  WHERE `ID_mail`='.$mailling->getAncienId();
  292.                                 $retour $bdd->exec($query);
  293.                             }
  294.                             if($maillingEnCour->addMaillingSend($mailling, new \DateTime('now')) == false){
  295.                                 return new JsonResponse('le mailling est déja en cours d\'envoi');
  296.                             }
  297.                             return new JsonResponse('le mailling a été lancé en envoi');
  298.                         } else {
  299.                             return new JsonResponse('l\'utilisateur ne possède pas d\'addresse d\'envoi');
  300.                         }
  301.                     } else {
  302.                         return new JsonResponse('le mailling est déjà en envoyé');
  303.                     }
  304.                 } else {
  305.                     return new JsonResponse('le mailling est déjà en cours d\'envoi');
  306.                 }
  307.             } else {
  308.                 return new JsonResponse('le mailling doit être validé');
  309.             }
  310.         } else {
  311.             return new JsonResponse('le mailling n\'existe pas');
  312.         }
  313.     }
  314.     /**
  315.      * @Route("/maillings/creer/actualite/suite/envoie/{idMailling}", methods={"GET"}, name="creer_actu_mailing")
  316.      */
  317.     public function creerActualiteMailing($idMaillingEntityManagerInterface $emOvhSend $ovhSendActualiteController $actualiteController){
  318.         $mailling $em->getRepository('App:Mailling')->find($idMailling);
  319.         $actualite = new Actualite();
  320.         $nomMailling str_replace('&#039;''\''$mailling->getNom());
  321.         $actualite->setNom($nomMailling);
  322.         $actualite->setClient($mailling->getClient());
  323.         $actualite->setPitch($mailling->getResumer());
  324.         $actualite->setCreation(new \DateTime('now'));
  325.         $actualite->setAuteur($mailling->getEnvoyePar());
  326.         $em->persist($actualite);
  327.         $em->flush();
  328.         $actualite $em->getRepository('App:Actualite')->findDerniereActu();
  329.         $theme = new ThemeDescriptif();
  330.         $theme->setLibelle($mailling->getResumerCour());
  331.         $theme->setActualite($actualite);
  332.         $em->persist($theme);
  333.         $em->flush();
  334.         $actualiteController->parutionImporterCopie($actualite->getId(), 0$em);
  335.         try
  336.         {
  337.             $bdd = new PDO('mysql:host=185.126.230.125;dbname=escal_web;charset=utf8''escalprod''skl001');
  338.         }
  339.         catch (Exception $e)
  340.         {
  341.             die('Erreur : ' $e->getMessage());
  342.         }
  343.         $query 'SELECT MAX(`ID_actualite`) as actuId FROM `ecw_actualites`';
  344.         $reponse $bdd->query($query);
  345.         while ($row $reponse->fetch()) {
  346.             $actuAncienId $row['actuId'];
  347.         }
  348.         $reponse->closeCursor();
  349.         $actualite->setAncienId($actuAncienId);
  350.         $em->flush();
  351.         $ovhSend->sendMailNouvelleActualite($actualite);
  352.         return new JsonResponse('ok');
  353.     }
  354.     /**
  355.      * @Route("/mailling/enCour/{idMailling}", methods={"GET"}, name="mailling.en.cour.status")
  356.      */
  357.     public function getMaillingInfoEnCourAction($idMaillingEntityManagerInterface $emMaillingEnCour $maillingEnCour){
  358.         $mailling $em->getRepository('App:Mailling')->find($idMailling);
  359.         $retour = [];
  360.         if($mailling){
  361.             $debutMailling $maillingEnCour->getIfMaillingBegin($mailling);
  362.             if($debutMailling !== false){
  363.                 $nbMailling $maillingEnCour->getNbMailMailling($mailling);
  364.                 $nbMaillingAttente $maillingEnCour->getNbMailRestantAvantFin($mailling);
  365.                 if($nbMaillingAttente != false){
  366.                     $dateFurtureEnvoie $maillingEnCour->getHeureEnvoieFuture($mailling);
  367.                     if( $dateFurtureEnvoie == false){
  368.                         $retour['nbMaillAttente'] = $nbMaillingAttente;
  369.                         $retour['nbMailToSend'] = $nbMailling[0];
  370.                         $retour['nbMailSend'] = $nbMailling[1];
  371.                     } else {
  372.                         $retour['message_erreur'] = 'le mailling commencera a être envoyé le ' $dateFurtureEnvoie;
  373.                     }
  374.                 } else {
  375.                     if($mailling->getEnvoyer() == true){
  376.                         $retour['message_erreur'] = 'le mailling a fini d\'être envoyé';
  377.                     }
  378.                     $retour['message_erreur'] = 'Le mailling est en cours d\'envoi, l\'affichage du diagramme peut prendre plusieurs minutes. Merci de patienter.';
  379.                 }
  380.             } else {
  381.                 $retour['message_erreur'] = 'le mailling n\'est pas en envoi';
  382.             }
  383.         } else {
  384.             $retour['message_erreur'] = 'le mailling n\'existe pas';
  385.         }
  386.         return new JsonResponse($retour);
  387.     }
  388.     /**
  389.      * @Route("/maillings/deleteMailling/{idMailling}", methods={"DELETE"}, name="delete.mailling")
  390.      */
  391.     public function deleteMailling($idMaillingEntityManagerInterface $em){
  392.         $mailling $em->getRepository('App:Mailling')->find($idMailling);
  393.         if($mailling->getEnCour() === false){
  394.             $maillingsEnCour $em->getRepository('App:MaillingEnCour')->findBy(['mailling' => $mailling]);
  395.             foreach ($maillingsEnCour as $maillingEnCour){
  396.                 $em->remove($maillingEnCour);
  397.             }
  398.             $em->remove($mailling);
  399.             $em->flush();
  400.             $retour['message'] = 'le mailling a été supprimé';
  401.         } else {
  402.             $retour['message'] = 'le mailling a déjà été lancé en envoi';
  403.         }
  404.         return new JsonResponse($retour);
  405.     }
  406.     /**
  407.      * @Route("/maillings/prepareCoupure/{idClient}", methods={"GET"}, name="mailling.cree.coupure")
  408.      */
  409.     public function creeMaillingCoupure($idClientEntityManagerInterface $emGenerateCoupureInterface $generateCoupure){
  410.         $client $em->getRepository('App:Client')->find($idClient);
  411.         if($client){
  412.             /** @var Client $client */
  413.             $mailling $em->getRepository('App:Mailling')->findOneBy(['client' => $client'typeMail' => 'Coupure''envoyer' => false]);
  414.             /** @var Mailling $mailling */
  415.             if($mailling){
  416.                 foreach ($mailling->getPiecesJointes() as $piecesJointe){
  417.                     $mailling->removePiecesJointe($piecesJointe);
  418.                     $em->remove($piecesJointe);
  419.                 }
  420.                 $em->flush();
  421.             } else{
  422.                 $mailling = new Mailling();
  423.                 $mailling->setClient($client);
  424.                 $date = new \DateTime('now');
  425.                 $mailling->setNom('Retombées presse '$client->getNom(). ' du '.date_format($date'd/m/Y'));
  426.                 $mailling->setObjet('Retombées presse '$client->getNom(). ' du '.date_format($date'd/m/Y'));
  427.                 foreach ($client->getRolesUserClient() as $roleUserClient){
  428.                     /** @var ClientRoleUser $roleUserClient */
  429.                     if($roleUserClient->getRole() == 'Bo'){
  430.                         $mailling->setEnvoyePar($roleUserClient->getAuthUser());
  431.                         $mailling->setReplyTo($roleUserClient->getAuthUser());
  432.                     }
  433.                 }
  434.                 $mailling->setTypeMail('Coupure');
  435.             }
  436.             $coupuresClient $em->getRepository('App:Coupure')->findBy(['client' => $client'envoyer' => false]);
  437.             foreach ($coupuresClient as $coupure){
  438.                 /** @var Coupure $coupure */
  439.                 $pieceJointeMailling = new PieceJointeMailling();
  440.                 $pieceJointeMailling->setUrl($coupure->getPiecesJointe());
  441.                 $pieceJointeMailling->setCoupure($coupure);
  442.                 $pieceJointeMailling->setMailling($mailling);
  443.                 $mailling->addPiecesJointe($pieceJointeMailling);
  444.             }
  445.             $mailling->setValiderEnvoi(0);
  446.             $mailling->setEnCour(0);
  447.             $mailling->setEnvoyer(0);
  448.             $mailling->setNbMail(0);
  449.             $mailling->setNbMailEnvoye(0);
  450.             $mailling->setDebutMailCoupure($generateCoupure->generateDebutMail($mailling));
  451.             $mailling->setFinMailCoupure($generateCoupure->generateFinMail($mailling));
  452.             $mailling->sethyperlien(1);
  453.             $em->persist($mailling);
  454.             $em->flush();
  455.         } else {
  456.             $retour['message_erreur'] = 'le client n\'existe pas';
  457.         }
  458.         return new JsonResponse(['idMailling' => $mailling->getId()]);
  459.     }
  460.     /**
  461.      * @Route("/maillings/information/{idMailling}", methods={"GET"}, name="nb.mail.envoyer")
  462.      */
  463.     public function getNombreMailEnvoyer($idMaillingEntityManagerInterface $em){
  464.         $mailling $em->getRepository('App:Mailling')->findBy(['ancienId' => $idMailling]);
  465.         if(!isset($mailling[0])){
  466.             return new JsonResponse(0);
  467.         }
  468.         $mailling $mailling[0];
  469.         return new JsonResponse($mailling->getNbMailEnvoye());
  470.     }
  471.     /**
  472.      * @Route("/maillings/refreshNbMail/{idMailling}", methods={"GET"}, name="nb.mail.envoyer.refresh")
  473.      */
  474.     public function getRefreshNombreMail(OvhSend $ovhSend$idMaillingEntityManagerInterface $em){
  475.         $mailling $em->getRepository('App:Mailling')->find($idMailling);
  476.         /** @var Mailling $mailling */
  477.         $contactsSend $ovhSend->getContactSend($mailling);
  478.         $nbMail 0;
  479.         foreach ($contactsSend as $contactSend) {
  480.             $userInfo explode('#'$contactSend);
  481.             $userMail trim($userInfo[0]);
  482.             $blackList $em->getRepository('App:BlackList')
  483.                 ->findOneBy(['email'=> $userMail]);
  484.             if(!$blackList) {
  485.                 $nbMail $nbMail 1;
  486.             }
  487.         }
  488.         if($mailling->getNbMail() != $nbMail){
  489.            $mailling->setNbMail($nbMail);
  490.         }
  491.         $em->persist($mailling);
  492.         $em->flush();
  493.         return new JsonResponse($mailling->getNbMail());
  494.     }
  495.     /**
  496.      * @Route("/mailing/contactsenvoireel/{idMailling}", methods={"GET"}, name="mailing.contact.Envoi.reel")
  497.      */
  498.     public function getContactsEnvoiReel($idMaillingEntityManagerInterface $em) {
  499.         $mailing $em->getRepository('App:Mailling')->findOneBy(["ancienId" => $idMailling]);
  500.         $mailingsEnCours $em->getRepository('App:MaillingEnCour')->findBy(["mailling" => $mailing->getId()]);
  501.         $contactsIDIntranet = [];
  502.         foreach ($mailingsEnCours as $mailingEncours) {
  503.             if(!is_null($mailingEncours->getUserId()))
  504.                 $contactsIDIntranet[] = $mailingEncours->getUserId();
  505.         }
  506.         return new JsonResponse($contactsIDIntranet);
  507.     }
  508.     /**
  509.      * @Route("/mailing/get/contacts/safe/{idMailling}", methods={"GET"}, name="mailing_contact_safe_envoi")
  510.      */
  511.     public function getContactsSafeEnvoi($idMaillingEntityManagerInterface $emOvhSend $ovhSend) {
  512.         $contactsSafe '';
  513.         // liste contacts hors blacklist et email retour
  514.         $mailing $em->getRepository('App:Mailling')->findOneBy(["ancienId" => $idMailling]);
  515.         $contactsSend $ovhSend->getContactSend($mailing);
  516.         foreach ($contactsSend as $contactSend) {
  517.             $contactInfo explode('#'$contactSend);
  518.             $contactMail trim($contactInfo[0]);
  519.             $contactID trim($contactInfo[1]);
  520.             $adresseEmailVerif $em->getRepository('App:Email\AdresseMailVerif')->findOneBy(['email' => $contactMail]);
  521.             // Rapidité de traitement
  522.             $qb $em->createQueryBuilder();
  523.             $emailRetour $qb->select('1')
  524.                 ->from(EmailRetour::class, 'er')
  525.                 ->where('er.email = :email')
  526.                 ->setParameter('email'$contactMail)
  527.                 ->orderBy('er.id''DESC')
  528.                 ->setMaxResults(1)
  529.                 ->getQuery()
  530.                 ->getResult();
  531.             $safeToSend 0;
  532.             //Si l'adresse mail a deja ete verifie  : recuperer le statut de l'adresse mail verifiee
  533.             if ($adresseEmailVerif){
  534.                 // Gestion de cas des adresses mails de type "Accept All"
  535.                 if(!$emailRetour && $adresseEmailVerif->getSafeToSend()==1){
  536.                     $safeToSend 1;
  537.                 }
  538.             }
  539.             $blackList $em->getRepository('App:BlackList')->findOneBy(['email' => $contactMail]);
  540.             if (!$blackList || $blackList->getAutorise() == 1) {
  541.                 $dateDuJour = new \DateTime('now');
  542.                 //La dateAbsence correspond à la date de retour
  543.                 if($emailRetour && $emailRetour->getDateAbsence()>$dateDuJour) {
  544.                     $safeToSend 0;
  545.                 }
  546.                 // Ne pas bloquer l'envoi à l'adresse mail classée 'autre' par les BO
  547.                 if($emailRetour && $emailRetour->getRaison() == 'autre') {
  548.                     $safeToSend 1;
  549.                 }
  550.                 if($safeToSend == 1) {
  551.                     $contactsSafe $contactsSafe '"'.$contactMail.'", ';
  552.                 }
  553.             }
  554.             // vérifier si contact dans les listes coeur de cible et itw articles du client, envoyer obligatoirement
  555.             $contact $em->getRepository('App\Entity\Contact')->findOneBy(['ancienId' => $contactID]);
  556.             $safeInListe false;
  557.             if ($contact != null) {
  558.                 $listes $em->getRepository('App:ListeContact')->findListeCoeurCibleEtItwArticlesClient($mailing->getClient()->getNom());
  559.                 foreach ($listes as $liste){
  560.                     $asso $this->getDoctrine()->getRepository('App:ListeContactContact')->findBy(['contact' => $contact'listeContact' => $liste]);
  561.                     if ($asso != null) {
  562.                         $safeInListe true;
  563.                     }
  564.                 }
  565.                 if ($safeInListe === true) {
  566.                     $safeToSend 1;
  567.                 }
  568.             }
  569.             if($safeToSend == 1) {
  570.                 $contactsSafe $contactsSafe '"'.$contactMail.'", ';
  571.             }
  572.         }
  573.         return new JsonResponse($contactsSafe);
  574.     }
  575.     /**
  576.      * @Route("/api/maillings/auteur/intranet/{maillingId}", methods={"GET"}, name="rechercher_auteur_intranet_mailling")
  577.      */
  578.     public function rechercherAncienIdAuteur ($maillingId)
  579.     {
  580.         $mailling $this->getDoctrine()->getRepository('App:Mailling')->find($maillingId);
  581.         $authUserId 0;
  582.         // récupérer ancien id authuser
  583.         if($mailling->getAuteur() != null) {
  584.             if($mailling->getAuteur()->getUser() != null) {
  585.                 $nomPrenom $mailling->getAuteur()->getUser()->getPrenom() . "." $mailling->getAuteur()->getUser()->getNom();
  586.                 if (strpos($nomPrenom' ') !== false) {
  587.                     $nomPrenom str_replace(' ''.'$nomPrenom);
  588.                 }
  589.                 $url 'extranet.escalconsulting.com/information/getMembreByNom.php?name=' $nomPrenom;
  590.                 $c curl_init();
  591.                 curl_setopt($cCURLOPT_URL$url);
  592.                 curl_setopt($cCURLOPT_RETURNTRANSFERtrue);
  593.                 curl_setopt($cCURLOPT_HEADERfalse);
  594.                 $output curl_exec($c);
  595.                 curl_close($c);
  596.                 $output json_decode($output);
  597.                 $output = (array)$output;
  598.                 $authUserId $output['id'];
  599.             }
  600.         }
  601.         return new JsonResponse($authUserId);
  602.     }
  603.     /**
  604.      * @Route("/api/maillings/liste/associee/associer/{maillingId}/{listeAId}", methods={"GET"}, name="mailling_liste_associee_associer")
  605.      */
  606.     public function addMailingListeAssociee($maillingId$listeAIdEntityManagerInterface $em): JsonResponse
  607.     {
  608.         $mailling $this->getDoctrine()->getRepository('App:Mailling')->find($maillingId);
  609.         $listeA $this->getDoctrine()->getRepository('App:ListeContact')->find($listeAId);
  610.         $mailling->addListesAssociee($listeA);
  611.         $em->flush();
  612.         return new JsonResponse("ok");
  613.     }
  614.     /**
  615.      * @Route("/api/maillings/liste/desassociee/associer/{maillingId}/{listeDId}", methods={"GET"}, name="mailling_liste_desassociee_associer")
  616.      */
  617.     public function addMailingListeDesassociee($maillingId$listeDIdEntityManagerInterface $em): JsonResponse
  618.     {
  619.         $mailling $this->getDoctrine()->getRepository('App:Mailling')->find($maillingId);
  620.         $listeD $this->getDoctrine()->getRepository('App:ListeContact')->find($listeDId);
  621.         $mailling->addListesDesassociee($listeD);
  622.         $em->flush();
  623.         return new JsonResponse("ok");
  624.     }
  625.     /**
  626.      * @Route("/api/maillings/liste/associee/desassocier/{maillingId}", methods={"GET"}, name="mailling_liste_associee_desassocier")
  627.      */
  628.     public function deleteMailingListeAssociee($maillingIdEntityManagerInterface $em): JsonResponse
  629.     {
  630.         $mailling $this->getDoctrine()->getRepository('App:Mailling')->find($maillingId);
  631.         $associations $mailling->getListesAssociees();
  632.         foreach ($associations as $association) {
  633.             $mailling->removeListesAssociee($association);
  634.         }
  635.         $em->flush();
  636.         return new JsonResponse("ok");
  637.     }
  638.     /**
  639.      * @Route("/api/maillings/liste/desassociee/desassocier/{maillingId}", methods={"GET"}, name="mailling_liste_desassociee_desassocier")
  640.      */
  641.     public function deleteMailingListeDesassociee($maillingIdEntityManagerInterface $em): JsonResponse
  642.     {
  643.         $mailling $this->getDoctrine()->getRepository('App:Mailling')->find($maillingId);
  644.         $associations $mailling->getListesDesassociees();
  645.         foreach ($associations as $association) {
  646.             $mailling->removeListesDesassociee($association);
  647.         }
  648.         $em->flush();
  649.         return new JsonResponse("ok");
  650.     }
  651.     /**
  652.      * @Route("/api/maillings/importation/copie/mailling/{maillingId}/{ancienId}", methods={"GET"}, name="mailing_importer_copie_intranet")
  653.      */
  654.     public function mailingImporterCopie ($maillingId$ancienIdEntityManagerInterface $em)
  655.     {
  656.         try
  657.         {
  658.             $bdd = new PDO('mysql:host=185.126.230.125;dbname=escal_web;charset=utf8''escalprod''skl001');
  659.         }
  660.         catch (Exception $e)
  661.         {
  662.             die('Erreur : ' $e->getMessage());
  663.         }
  664.         // récupérer données mailing
  665.         $mailling $this->getDoctrine()->getRepository('App:Mailling')->find($maillingId);
  666.         // récupérer ancien id auteur
  667.         $authUserId 0;
  668.         if($mailling->getAuteur() != null) {
  669.             $nomPrenom $mailling->getAuteur()->getUser()->getPrenom().".".$mailling->getAuteur()->getUser()->getNom();
  670.             if (strpos($nomPrenom,' ') !== false) {
  671.                 $nomPrenom str_replace(' ','.'$nomPrenom);
  672.             }
  673.             $url 'extranet.escalconsulting.com/information/getMembreByNom.php?name='.$nomPrenom;
  674.             $c curl_init();
  675.             curl_setopt($cCURLOPT_URL$url);
  676.             curl_setopt($cCURLOPT_RETURNTRANSFERtrue);
  677.             curl_setopt($cCURLOPT_HEADERfalse);
  678.             $output curl_exec($c);
  679.             curl_close($c);
  680.             $output json_decode($output);
  681.             $output = (array)$output;
  682.             $authUserId $output['id'];
  683.         }
  684.         // récupérer nom
  685.         $nom $mailling->getNom();
  686.         // récupérer from
  687.         $from $mailling->getEnvoyePar()->getUser()->getEmail();
  688.         // récupérer nomfrom
  689.         $nomfrom $mailling->getAuteur()->getUser()->getPrenom()." ".$mailling->getAuteur()->getUser()->getNom();
  690.         // récupérer replyto
  691.         $replyto $mailling->getReplyTo()->getUser()->getEmail();
  692.         // récupérer objet
  693.         $objet $mailling->getObjet();
  694.         // récupérer id client
  695.         if($mailling->getClient() != null){
  696.             $clientId $mailling->getClient()->getAncienId();
  697.         } else {
  698.             $clientId 0;
  699.         }
  700.         // récupérer priorite
  701.         if($mailling->getPriorite() == 1){
  702.             $priorite "1 (Highest)";
  703.         } else if($mailling->getPriorite() == 2){
  704.             $priorite "2 (High)";
  705.         } else if($mailling->getPriorite() == 3){
  706.             $priorite "3 (Normal)";
  707.         } else if($mailling->getPriorite() == 4){
  708.             $priorite "4 (Low)";
  709.         } else if($mailling->getPriorite() == 5){
  710.             $priorite "5 (Lowest)";
  711.         }
  712.         $cc '';
  713.         $bcc '';
  714.         $format 'Html';
  715.         $typeId 3;
  716.         // récupérer ancien id signataire
  717.         $signataireId 0;
  718.         if($mailling->getEnvoyePar() != null) {
  719.             $nomPrenomBis $mailling->getEnvoyePar()->getUser()->getPrenom().".".$mailling->getEnvoyePar()->getUser()->getNom();
  720.             if (strpos($nomPrenomBis,' ') !== false) {
  721.                 $nomPrenomBis str_replace(' ','.'$nomPrenomBis);
  722.             }
  723.             $url 'extranet.escalconsulting.com/information/getMembreByNom.php?name='.$nomPrenomBis;
  724.             $c curl_init();
  725.             curl_setopt($cCURLOPT_URL$url);
  726.             curl_setopt($cCURLOPT_RETURNTRANSFERtrue);
  727.             curl_setopt($cCURLOPT_HEADERfalse);
  728.             $output curl_exec($c);
  729.             curl_close($c);
  730.             $output json_decode($output);
  731.             $output = (array)$output;
  732.             $signataireId $output['id'];
  733.         }
  734.         $track 'N';
  735.         $dejaEnvoye 0;
  736.         $dateEnvoi null;
  737.         // récupérer création
  738.         if ($mailling->getCreation() != null) {
  739.             $creation $mailling->getCreation()->format('Y-m-d H:i');
  740.         } else {
  741.             $creation '';
  742.         }
  743.         // récupérer modification
  744.         if ($mailling->getModification() != null) {
  745.             $modification $mailling->getModification()->format('Y-m-d H:i');
  746.         } else {
  747.             $modification '';
  748.         }
  749.         $encours 0;
  750.         $postfb 0;
  751.         $posttw 0;
  752.         $postfbes 0;
  753.         $posttwes 0;
  754.         $heureenvoi '00:00:00';
  755.         // récupérer id outil
  756.         if($mailling->getOutil() != null){
  757.             $outilId $mailling->getOutil()->getId();
  758.         } else {
  759.             $outilId 0;
  760.         }
  761.         // récupérer id niveau
  762.         if($mailling->getNiveau() != null){
  763.             $niveauId $mailling->getNiveau()->getId();
  764.         } else {
  765.             $niveauId 0;
  766.         }
  767.         // récupérer id sous niveau
  768.         if($mailling->getSousNiveau() != null){
  769.             $sousniveauId $mailling->getSousNiveau()->getId();
  770.         } else {
  771.             $sousniveauId 0;
  772.         }
  773.         // récupérer contenu
  774.         $contenu $mailling->getContent();
  775.         // si ce n'est pas une mise à jour
  776.         if ($ancienId == 0) {
  777.             // on insère le mailling
  778.             if (strpos($nom,'"') !== false) {
  779.                 $nom str_replace('"','\"'$nom);
  780.             }
  781.             if (strpos($objet,'"') !== false) {
  782.                 $objet str_replace('"','\"'$objet);
  783.             }
  784.             if (strpos($contenu,'"') !== false) {
  785.                 $contenu str_replace('"','\"'$contenu);
  786.             }
  787.             $query 'INSERT INTO `ecw_mails`(`nom_mail`, `cc_mail`, `bcc_mail`, `from_mail`, `nomfrom_mail`, `replyto_mail`, `objet_mail`, `client_mail`, `format_mail`, `priorite_mail`, `IDtype_mail`, `IDmembresignature_mail`, `track_mail`, `DejaEnvoye`, `dateenvoi_mail`, `ID_auteur_mail`, `creation_mail`, `modif_mail`, `encours`, `post_facebook`, `post_twitter`, `post_facebook_escal`, `post_twitter_escal`, `heureenvoi_mail`, `ID_outil`, `ID_niveau`, `ID_sous_niveau`, `contenu_cp`) '
  788.                 .' VALUES ("'.$nom.'","'.$cc.'","'.$bcc.'","'.$from.'","'.$nomfrom.'","'.$replyto.'","'.$objet.'",'.$clientId.',"'.$format.'","'.$priorite.'",'.$typeId.','.$signataireId.',"'.$track.'",'.$dejaEnvoye.',NULL,'.$authUserId.',"'.$creation.'", NULL,'.$encours.','.$postfb.','.$posttw.','.$postfbes.','.$posttwes.',"'.$heureenvoi.'",'.$outilId.','.$niveauId.','.$sousniveauId.',"'.$contenu.'")';
  789.             $retour $bdd->exec($query);
  790.             if (!$retour) {
  791.                 echo 'Problème lors de l\'insertion du mailing';
  792.             }
  793.             // on récupère le mailing nouvellement créé
  794.             $query 'SELECT MAX(`ID_mail`) as mailId FROM `ecw_mails`';
  795.             $reponse $bdd->query($query);
  796.             while ($row $reponse->fetch()) {
  797.                 $maillingAncienId $row['mailId'];
  798.             }
  799.             $reponse->closeCursor();
  800.             // on insère les associations du mailing
  801.             // liste associee
  802.             $listeAsso $mailling->getListesAssociees();
  803.             if(count($listeAsso) > 0) {
  804.                 $query10 'DELETE FROM `ecw_mail_liste_asso` WHERE `ID_mail`='.$maillingAncienId;
  805.                 $retour10 $bdd->exec($query10);
  806.                 foreach ($listeAsso as $liste) {
  807.                     $query11 'INSERT INTO `ecw_mail_liste_asso`(`ID_mail`, `ID_liste_contact`) '
  808.                         .' VALUES ('.$maillingAncienId.','.$liste->getAncienId().')';
  809.                     $retour11 $bdd->exec($query11);
  810.                     if (!$retour11) {
  811.                         echo 'Problème lors de l\'insertion de l\'asso mailing liste associee';
  812.                     }
  813.                 }
  814.             }
  815.             // liste desassociee
  816.             $listeDesa $mailling->getListesDesassociees();
  817.             if(count($listeDesa) > 0) {
  818.                 $query12 'DELETE FROM `ecw_mail_listetoremove_asso` WHERE `ID_mail`=' $maillingAncienId;
  819.                 $retour12 $bdd->exec($query12);
  820.                 foreach ($listeDesa as $liste) {
  821.                     $query13 'INSERT INTO `ecw_mail_listetoremove_asso`(`ID_mail`, `ID_liste_contact`) '
  822.                         ' VALUES (' $maillingAncienId ',' $liste->getAncienId() . ')';
  823.                     $retour13 $bdd->exec($query13);
  824.                     if (!$retour13) {
  825.                         echo 'Problème lors de l\'insertion de l\'asso mailing liste desassociee';
  826.                     }
  827.                 }
  828.             }
  829.             return new JsonResponse($maillingAncienId);
  830.         }
  831.         // si c'est une mise à jour
  832.         else if ($ancienId != 0) {
  833.             // on met à jour le mailing
  834.             if (strpos($nom,'"') !== false) {
  835.                 $nom str_replace('"','\"'$nom);
  836.             }
  837.             if (strpos($objet,'"') !== false) {
  838.                 $objet str_replace('"','\"'$objet);
  839.             }
  840.             if (strpos($contenu,'"') !== false) {
  841.                 $contenu str_replace('"','\"'$contenu);
  842.             }
  843.             $query 'UPDATE `ecw_mails` SET `nom_mail`="'.$nom.'",`cc_mail`="'.$cc.'",`bcc_mail`="'.$bcc.'",`from_mail`="'.$from.'",`nomfrom_mail`="'.$nomfrom.'",`replyto_mail`="'.$replyto.'",`objet_mail`="'.$objet.'",`client_mail`='.$clientId.', `format_mail`="'.$format.'", `priorite_mail`="'.$priorite.'", `IDtype_mail`='.$typeId.', `IDmembresignature_mail`='.$signataireId.', `track_mail`="'.$track.'", `DejaEnvoye`='.$dejaEnvoye.', `dateenvoi_mail`= NULL, `ID_auteur_mail`='.$authUserId.', `modif_mail`="'.$modification.'", `encours`='.$encours.', `post_facebook`='.$postfb.', `post_twitter`='.$posttw.', `post_facebook_escal`='.$postfbes.', `post_twitter_escal`='.$posttwes.', `heureenvoi_mail`="'.$heureenvoi.'", `ID_outil`='.$outilId.', `ID_niveau`='.$niveauId.', `ID_sous_niveau`='.$sousniveauId.', `contenu_cp`="'.$contenu.'"  WHERE `ID_mail`='.$ancienId;
  844.             $retour $bdd->exec($query);
  845.             // on update les associations du mailing
  846.             // liste associee
  847.             $listeAsso $mailling->getListesAssociees();
  848.             $query10 'DELETE FROM `ecw_mail_liste_asso` WHERE `ID_mail`='.$ancienId;
  849.             $retour10 $bdd->exec($query10);
  850.             if(count($listeAsso) > 0) {
  851.                 foreach ($listeAsso as $liste) {
  852.                     $query11 'INSERT INTO `ecw_mail_liste_asso`(`ID_mail`, `ID_liste_contact`) '
  853.                         .' VALUES ('.$ancienId.','.$liste->getAncienId().')';
  854.                     $retour11 $bdd->exec($query11);
  855.                     if (!$retour11) {
  856.                         echo 'Problème lors de l\'insertion de l\'asso mailing liste associee';
  857.                     }
  858.                 }
  859.             }
  860.             // liste desassociee
  861.             $listeDesa $mailling->getListesDesassociees();
  862.             $query12 'DELETE FROM `ecw_mail_listetoremove_asso` WHERE `ID_mail`=' $ancienId;
  863.             $retour12 $bdd->exec($query12);
  864.             if(count($listeDesa) > 0) {
  865.                 foreach ($listeDesa as $liste) {
  866.                     $query13 'INSERT INTO `ecw_mail_listetoremove_asso`(`ID_mail`, `ID_liste_contact`) '
  867.                         ' VALUES (' $ancienId ',' $liste->getAncienId() . ')';
  868.                     $retour13 $bdd->exec($query13);
  869.                     if (!$retour13) {
  870.                         echo 'Problème lors de l\'insertion de l\'asso mailing liste desassociee';
  871.                     }
  872.                 }
  873.             }
  874.             return new JsonResponse($ancienId);
  875.         }
  876.     }
  877.     /**
  878.      * @Route("/api/maillings/considerer/envoye/{ancienIdMailing}", methods={"GET"}, name="mailing_considerer_envoyer")
  879.      */
  880.     public function considererEnvoyeMailing($ancienIdMailingEntityManagerInterface $em): JsonResponse
  881.     {
  882.         try
  883.         {
  884.             $bdd = new PDO('mysql:host=185.126.230.125;dbname=escal_web;charset=utf8''escalprod''skl001');
  885.         }
  886.         catch (Exception $e)
  887.         {
  888.             die('Erreur : ' $e->getMessage());
  889.         }
  890.         if ($ancienIdMailing != && $ancienIdMailing != '') {
  891.             $query 'UPDATE `ecw_mails` SET `DejaEnvoye`= 1 WHERE `ID_mail`='.$ancienIdMailing;
  892.             $retour $bdd->exec($query);
  893.         }
  894.         return new JsonResponse("ok");
  895.     }
  896.     /**
  897.      * @Route("/api/maillings/total/contact/liste/{mailingId}/{type}", methods={"GET"}, name="mailing_total_contact_liste")
  898.      */
  899.     public function detailsListeContactInfo ($mailingId$typeEntityManagerInterface $em)
  900.     {
  901.         $ids = array();
  902.         $mailing $em->getRepository('App:Mailling')->find($mailingId);
  903.         if ($type == 'associe') {
  904.             $listesMailling $mailing->getListesAssociees();
  905.         } else {
  906.             $listesMailling $mailing->getListesDesassociees();
  907.         }
  908.         foreach ($listesMailling as $liste){
  909.             $ids[] = $liste->getId();
  910.         }
  911.         $contacts $this->getDoctrine()->getRepository('App:Contact')->findDistinctTotalContactMailing($ids);
  912.         $encoders = array(new XmlEncoder(), new JsonEncoder());
  913.         $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
  914.         $normalizer = new PropertyNormalizer($classMetadataFactory);
  915.         $normalizerDate = new DateTimeNormalizer();
  916.         $serializer = new Serializer([$normalizer$normalizerDate], $encoders);
  917.         $jsonContent $serializer->normalize($contactsnull, array('groups' => array('contact')));
  918.         $response = new JsonResponse($jsonContent);
  919.         $response->headers->set('Content-Type''application/json');
  920.         return $response;
  921.     }
  922.     /**
  923.      * @Route("/api/maillings/importation/supprimer/copie/mailing/{ancienIdMailing}", methods={"GET"}, name="mailing_supprimer_copie_intranet")
  924.      */
  925.     public function mailingSupprimerCopie ($ancienIdMailing)
  926.     {
  927.         try
  928.         {
  929.             $bdd = new PDO('mysql:host=185.126.230.125;dbname=escal_web;charset=utf8''escalprod''skl001');
  930.         }
  931.         catch (Exception $e)
  932.         {
  933.             die('Erreur : ' $e->getMessage());
  934.         }
  935.         // supprimer asso liste associee
  936.         $query 'DELETE FROM `ecw_mail_liste_asso` WHERE `ID_mail`='.$ancienIdMailing;
  937.         $retour $bdd->exec($query);
  938.         // supprimer asso liste desassociee
  939.         $query1 'DELETE FROM `ecw_mail_listetoremove_asso` WHERE `ID_mail`='.$ancienIdMailing;
  940.         $retour1 $bdd->exec($query1);
  941.         // supprimer mailing
  942.         $query5 'DELETE FROM `ecw_mails` WHERE `ID_mail`='.$ancienIdMailing;
  943.         $retour5 $bdd->exec($query5);
  944.         return new JsonResponse('ok');
  945.     }
  946.     /**
  947.      * @Route("/api/maillings/add/ftp/html/{maillingId}", methods={"GET"}, name="mailing_add_ftp_copie_intranet")
  948.      */
  949.     public function addMailHtml ($maillingIdFtpGetPieceJointe $ftp)
  950.     {
  951.         $result $ftp->addMailHTML($maillingId);
  952.         if(isset($result['type'])){
  953.             return new Response(json_encode($result));
  954.         }
  955.         return new Response('{ "status": "ok" }');
  956.     }
  957. }