src/Controller/Site/PublicController.php line 59

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Site;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. use Symfony\Component\String\Slugger\SluggerInterface;
  9. use Symfony\Component\Mailer\MailerInterface;
  10. use Symfony\Component\Mime\Crypto\DkimSigner;
  11. use Symfony\Component\Mime\Crypto\DkimOptions;
  12. use Symfony\Component\Mime\Email;
  13. use Symfony\Component\Mime\Address;
  14. use App\Entity\Evenement;
  15. use App\Entity\EvenementIntervenant;
  16. use App\Entity\Inscription;
  17. use App\Entity\Contact;
  18. use App\Entity\Intervenant;
  19. use App\Entity\Message;
  20. use App\Entity\Envoi;
  21. use App\Entity\Programme;
  22. use App\Entity\Question;
  23. use App\Entity\Reponse;
  24. use App\Entity\Optout;
  25. use App\Service\EvenementInfo;
  26. class PublicController extends AbstractController
  27. {
  28.     private $doctrine;
  29.     private $mailer;
  30.     private $slugger;
  31.     public function __construct(ManagerRegistry $doctrineMailerInterface $mailerSluggerInterface $slugger)
  32.     {
  33.         $this->doctrine $doctrine;
  34.         $this->mailer $mailer;
  35.         $this->slugger $slugger;
  36.     }
  37.     /**
  38.      * @Route("", name="home")
  39.      */
  40.     public function home() {
  41.         return $this->render('site/home.html.twig', []);    
  42.     }
  43.     /**
  44.      * @Route("/evenement/{slug}", name="evenement")
  45.      */
  46.     public function index(Request $requestSluggerInterface $sluggerEvenementInfo $evtInfostring $slug): Response
  47.     {
  48.         $evenement $this->doctrine->getRepository(Evenement::class)->findOneBySlug($slug);
  49.         $message null;
  50.         $contact null;
  51.         $inscription null;
  52.         $warning null;
  53.         // if($idmessage 
  54.         //     && $iduser 
  55.         //     && sha1($idmessage.$this->getParameter('app.salt')) ==  $hashmessage
  56.         //     && sha1($iduser.$this->getParameter('app.salt')) ==  $hashuser
  57.         //     ) {
  58.         //     $message = $this->doctrine->getRepository(Message::class)->find($idmessage);
  59.         //     $contact = $this->doctrine->getRepository(Contact::class)->find($iduser);
  60.         //     $inscription = $this->doctrine->getRepository(Inscription::class)->findOneBy(
  61.         //         [
  62.         //             'message' => $message,
  63.         //             'contact' => $contact,
  64.         //             ]
  65.         //         );
  66.         // }  
  67.         
  68.         
  69.         if($request->request->get('nom') !== null) {
  70.             //dd($request);
  71.             $em $this->doctrine->getManager();
  72.             if($contact === null) {
  73.                 $existing $this->doctrine->getRepository(Contact::class)->findOneByEmail($request->request->get('email'));
  74.                 if($existing$contact $existing;
  75.                 else $contact = new Contact;
  76.                 $contact->setNom($request->request->get('nom'));
  77.                 $contact->setPrenom($request->request->get('prenom'));
  78.                 $contact->setEmail($request->request->get('email'));
  79.                 $contact->setSociete($request->request->get('societe'));
  80.                 $contact->setFonction($request->request->get('fonction'));
  81.                 $contact->setTelephone($request->request->get('telephone'));
  82.                 $em->persist($contact);
  83.                 $em->flush();
  84.             }
  85.             //$existing = $this->doctrine->getRepository(Inscription::class)->findOneByContact($contact);
  86.             $existing $this->doctrine->getRepository(Inscription::class)->findOneBy(
  87.                 [
  88.                     'contact' => $contact,
  89.                     'evenement' => $evenement,
  90.                 ]
  91.             );
  92.             if($existing$inscription $existing;
  93.             else $inscription = new Inscription;
  94.             $inscription->setDateInscription(new \DateTime);
  95.             $inscription->setContact($contact);
  96.             $inscription->setMessage($message);
  97.             $inscription->setEvenement($evenement);
  98.             $inscription->setAccordImage$request->request->get('droitImage')!=null 0  );
  99.             $inscription->setNom($request->request->get('nom'));
  100.             $inscription->setPrenom($request->request->get('prenom'));
  101.             $inscription->setEmail($request->request->get('email'));
  102.             $inscription->setTelephone($request->request->get('telephone'));
  103.             $inscription->setPostal($request->request->get('postal'));
  104.             $inscription->setSociete($request->request->get('societe'));
  105.             $inscription->setFonction($request->request->get('fonction'));
  106.             $inscription->setConnu($request->request->get('connu'));
  107.             $inscription->setAttentes($request->request->get('attentes'));
  108.             if($request->request->get('attentes') == "Autre") {
  109.                 $inscription->setAttentesAutre($request->request->get('attentesAutre'));
  110.             }
  111.             $inscription->setNbParticipants(1);
  112.             if($request->request->get('inviteNom') != null && $request->request->get('invitePrenom') != null) {
  113.                 $inscription->setInviteNom($request->request->get('inviteNom'));
  114.                 $inscription->setInvitePrenom($request->request->get('invitePrenom'));
  115.             }
  116.             
  117.             if($request->request->get('type') == 'groupe') {
  118.                 // La nouvelle inscription concerne un groupe
  119.                 $inscription->setNbParticipants(intval($request->request->get('nbparticipants')));
  120.                 $inscription->setCreneau($request->request->get('creneau'));
  121.                 
  122.             } else {
  123.                 // inscription individuelle classique
  124.                 if($request->files->get("cv") !== null) {
  125.                     // Y a un CV
  126.                     if(!is_dir($this->getParameter('folder.uploadcv'))) {
  127.                         mkdir($this->getParameter('folder.uploadcv'), 0775);
  128.                     }
  129.                     if(
  130.                         ($request->files->get("cv")->getMimeType() == "application/msword" 
  131.                         || $request->files->get("cv")->getMimeType() == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" 
  132.                         || $request->files->get("cv")->getMimeType() == "application/pdf" )
  133.                         && $request->files->get("cv")->getSize() < 5000000
  134.                     ) {
  135.                         $cv $request->files->get('cv');
  136.                         $safeFilename $slugger->slug($request->request->get('nom')."_".$request->request->get('prenom'));
  137.                         $newFilename $safeFilename.'-'.date('YmdHis').'.'.$cv->guessExtension();
  138.                         try {
  139.                             $cv->move(
  140.                                 $this->getParameter('folder.uploadcv'),
  141.                                 $newFilename
  142.                             );
  143.                             $inscription->setCv($newFilename);
  144.                         } catch (FileException $e) {
  145.                             
  146.                         }
  147.                     } else {
  148.                         // Pas le bon format
  149.                         $warning "Votre CV n'a pas été joint. Merci d'utiliser les formats PDF ou DOC, et de limiter le poids du fichier à 3Mo maximum.";
  150.                     }
  151.                 }
  152.             }
  153.             $inscription->setType($request->request->get('type'));
  154.             
  155.             // Supprime les mails programmé pour les relances
  156.             try {
  157.                 if($contact && $message) { 
  158.                     $poubelle $this->doctrine->getRepository(Envoi::class)->findEnvoiASupprimer($contact$message->getEvenement());
  159.                     if($poubelle) {
  160.                         foreach($poubelle as $envoi) {
  161.                             $em->remove($envoi);
  162.                         }
  163.                     }
  164.                 }
  165.             } catch (\Throwable $th) {
  166.                 //throw $th;
  167.             }
  168.             // Envoi du mail de confirmation d'inscription
  169.             $confirmation  $this->doctrine->getRepository(Message::class)->findOneBy(
  170.                 [
  171.                     'evenement' => $evenement,
  172.                     'type' => 'confirmation',
  173.                 ]
  174.             );
  175.             if($confirmation) {
  176.                 $titre $this->slugger->slug(strtolower($evenement->getTitre()));
  177.                 $html $this->renderView('email/email.html.twig', [
  178.                     'message' => $confirmation,
  179.                     'titre' => $titre,
  180.                 ]);
  181.                 $email = (new Email())
  182.                     ->from(new Address('contact@evenements.engie-solutions.com ''Invitation ENGIE Solutions'))
  183.                     ->subject($confirmation->getObjet())
  184.                     ->replyTo('evenements.engiesolutions@engie.com')
  185.                     ->to(new Address($contact->getEmail(), $contact->getPrenom().' '.$contact->getNom()))
  186.                     ->html($html)
  187.                     ->text(strip_tags($html))
  188.                 ;     
  189.                 $lastProgramme $this->doctrine->getRepository(Programme::class)->findBy(
  190.                     ['evenement' => $evenement], 
  191.                     ['heureDebut' => 'DESC']
  192.                 );
  193.                 if($lastProgramme) {
  194.                     $fin $lastProgramme[0]->getHeureDebut();
  195.                     if( $lastProgramme[0]->getHeureFin() != null ) {
  196.                         $fin $lastProgramme[0]->getHeureFin();
  197.                     }
  198.                     
  199.                 }
  200.                 $dateStartEnd $evtInfo->getStartEndEvt($evenement);
  201.                 
  202.                 $ics $evtInfo->createIcs($evenement$dateStartEnd);
  203.                 
  204.                 $email->attachFromPath($this->getParameter('folder.uploadsite').$ics);
  205.                 // $signer = new DkimSigner('file:///'.$this->getParameter('folder.key').'/dkimkey.key', 'plusvertmoinscherevent.engie.fr', 'mail');
  206.                 // $email = $signer->sign($email);
  207.                 $this->mailer->send($email);
  208.             }
  209.             $em->persist($inscription);
  210.             $em->flush();
  211.         }
  212.         return $this->render('site/evenement.html.twig', [
  213.             'contact' => null
  214.             'inscription' => $inscription,
  215.             'evenement' => $evenement,
  216.             'intervenants'   => $this->doctrine->getRepository(EvenementIntervenant::class)->findByEvenement($evenement),
  217.         ]);
  218.     }
  219.      /**
  220.      * @Route("satisfaction/{idinscription}-{hashinscription}-{idevent}", name="satisfaction")
  221.      */
  222.     public function satisfaction(Request $requestint $idinscriptionstring $hashinscriptionint $idevent ): Response
  223.     {
  224.         $inscription $this->doctrine->getRepository(Inscription::class)->find($idinscription);
  225.         if($inscription) {
  226.             $evenement $inscription->getEvenement();
  227.         } else {
  228.             $evenement $this->doctrine->getRepository(Evenement::class)->find($idevent);
  229.         }
  230.         // if(
  231.         //     !$inscription 
  232.         //     || sha1($idinscription.$this->getParameter('app.salt')) !=  $hashinscription
  233.         // ) {
  234.         //     return new Response(
  235.         //         '<html><body></body></html>'
  236.         //     );
  237.         // }
  238.         $questions $this->doctrine->getRepository(Question::class)->findBy(
  239.             ['evenement' => $evenement ],
  240.             ['ordre' => 'ASC']
  241.         );
  242.         if(count($request->request)) {
  243.             $em $this->doctrine->getManager();
  244.             // Si déjà posté, supprime les anciennes réponses
  245.             $reponses $this->doctrine->getRepository(Reponse::class)->findBy(
  246.                 [
  247.                     'inscription' => $inscription,
  248.                     'contact' => $inscription->getContact(),
  249.                 ]
  250.             );
  251.             foreach($reponses as $reponse) {
  252.                 $em->remove($reponse);
  253.             }
  254.             foreach($request->request as $key=>$choix) {
  255.                 if(intval(explode("_"$key)[1]) && strpos($key"commentaire") === false) {
  256.                     $question $this->doctrine->getRepository(Question::class)->findintvalexplode("_"$key)[1] ) );
  257.                     $reponse = new Reponse;
  258.                     $reponse->setInscription($inscription)
  259.                     ->setContact($inscription->getContact())
  260.                     ->setQuestion($question)
  261.                     ->setContenu($choix)
  262.                     ;
  263.                     if($request->request->get($key.'_commentaire') != null) {
  264.                         $reponse->setCommentaire($request->request->get($key.'_commentaire'));
  265.                     }
  266.                     
  267.                     $em->persist($reponse);
  268.                 }
  269.             }
  270.             $em->flush();
  271.         }
  272.         return $this->render('site/satisfaction.html.twig', [
  273.             'evenement'   => $evenement,
  274.             'inscription' => $inscription,
  275.             'questions'   => $questions,
  276.         ]);
  277.     }
  278.     /**
  279.      * @Route("/evenement/{slug}/mentions-legales", name="site_mentions")
  280.      */
  281.     public function mentions(string $slug): Response
  282.     {
  283.         $evenement $this->doctrine->getRepository(Evenement::class)->findOneBySlug($slug);
  284.         return $this->render('site/mentions.html.twig', [
  285.             'evenement' => $evenement,
  286.         ]);
  287.     }
  288.     /**
  289.      * @Route("/evenement/{slug}/rgpd", name="site_rgpd")
  290.      */
  291.     public function rgpd(string $slug): Response
  292.     {
  293.         $evenement $this->doctrine->getRepository(Evenement::class)->findOneBySlug($slug);
  294.         return $this->render('site/rgpd.html.twig', [
  295.             'evenement' => $evenement,
  296.         ]);
  297.     }
  298.     
  299.     /**
  300.      * @Route("desabo/{idenvoi}-{hashenvoi}", name="desabo")
  301.      */
  302.     public function desabo(int $idenvoistring $hashenvoi): Response
  303.     {
  304.         $envoi $this->doctrine->getRepository(Envoi::class)->find($idenvoi);
  305.         if(
  306.             $envoi 
  307.             && sha1($idenvoi.$this->getParameter('app.salt')) ==  $hashenvoi
  308.             
  309.         {
  310.             $message "Votre adresse <b>".$envoi->getContact()->getEmail()."</b> a bien été supprimée de notre base.";
  311.             
  312.             $em $this->doctrine->getManager();
  313.             
  314.             $optout = new Optout;
  315.             $optout->setEmail($envoi->getContact()->getEmail());
  316.             $optout->setDate(new \DateTime);
  317.             $em->persist($optout);
  318.             
  319.             $em->remove($envoi->getContact());
  320.             $em->flush();
  321.             return new Response(
  322.                 '<html style="background:#003b55; color:#fff; font-family:sans-serif;">
  323.                     <body style="padding:20px 0;"><h3 style="text-align:center;font-weight: normal;">'.$message.'</h3></body>
  324.                 </html>'
  325.             );
  326.             
  327.         }
  328.     }
  329. }