src/Controller/MaillingController.php line 363

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