src/Controller/SubController.php line 38

Open in your IDE?
  1. <?php
  2. // src/Controller/SubController.php
  3. namespace App\Controller;
  4. use App\Entity\Prospect;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Form\Extension\Core\Type\DateType;
  7. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Validator\Validator\ValidatorInterface;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Form\FormTypeInterface;
  15. use Swift_Mailer;
  16. use Swift_SmtpTransport;
  17. use Swift_Message;
  18. class SubController extends AbstractController
  19. {
  20.     /**
  21.      * @Route("/produits}", name="resa")
  22.      */
  23.     public function new(Request $requestSwift_Mailer $mailer)
  24.     {
  25.         $prospect = new Prospect();
  26.         //$date = date('d-M-y');
  27.         // ...
  28.         $form $this->createFormBuilder($prospect)
  29.             ->add('nom'TextType::class, array('label' => 'Nom / Prénom','required' => true))
  30.             ->add('tel'TextType::class, array('label' => 'Tél.','required' => true))
  31.             ->add('dpt'TextType::class, array('label' => 'Code Postal','required' => true))
  32.             
  33.             ->add('date'TextType::class, array('label' => 'Ville','required' => false))
  34.             
  35.             ->add('code'TextType::class, array('label' => 'Adresse','required' => false))
  36.             
  37.             ->add('email'TextType::class, array('label' => 'Email','required' => false))
  38.             ->getForm();
  39.         
  40.         /*$form = $this->createForm(ProspectType::class, $prospect [
  41.             'method' => 'GET',
  42.         ]);*/
  43.         
  44.         
  45.         $form->handleRequest($request);
  46.             if ($form->isSubmitted() && $form->isValid()) {
  47.                 
  48.                         
  49.                 // $form->getData() holds the submitted values
  50.                 // but, the original `$task` variable has also been updated
  51.                 $prospect $form->getData();
  52.                 $dpt $prospect->getDpt();
  53.                 $departement substr($dpt,2);
  54.                 
  55.                  //Tri par dpt
  56.                 $levasseur = array('29''22''56''35''44''49''53''72''61''14''50','85''37''79','86','36');
  57.                 $menzoyan = array('07''26''38''73''74','69');
  58.                 $fontenay = array('78''91''92''28''27''76');
  59.                 $nord = array('80''62''59');
  60.                 $roulleau = array('77''60''02''08''51''10''89''52');
  61.                 $manca = array('55''54''57''88''68''90''70''25');
  62.                 $jacquet = array('18''58''21''03''71''39''01''63''42''43''15');
  63.                 $debattista = array('30''84''13''83''04''06''05');
  64.                 $languedoc = array('48''12''81''34''11''09''66''31');
  65.                 $fantarella = array('64''65''32''40''33''47''82''46''24''19''23''17''16''87''23');
  66.                 $barbey = array('75');
  67.                 $thiroux = array('95''94''93''45''41');
  68.                 
  69.                 if (in_array($departement$levasseur)) {
  70.                     $commercial = array('tcourault@everstyl.fr''romain.marchand@variationconfort.fr');
  71.                     $zdc='soldes-guermeur.html.twig';
  72.                 }
  73.                 else if (in_array($departement$fontenay)) {
  74.                     $commercial = array('yfontenay@everstyl.fr''romain.marchand@variationconfort.fr');
  75.                     $zdc='soldes-bes2.html.twig';
  76.                 }
  77.                 else if (in_array($departement$barbey)) {
  78.                     $commercial = array('lbarbey@everstyl.fr''romain.marchand@variationconfort.fr');
  79.                     $zdc='soldes-barbey.html.twig';
  80.                 }
  81.                 else if (in_array($departement$nord)) {
  82.                     $commercial = array('cthiroux@everstyl.fr''romain.marchand@variationconfort.fr');
  83.                     $zdc='soldes-sergeant.html.twig';
  84.                 }
  85.                 else if (in_array($departement$roulleau)) {
  86.                     $commercial = array('hroulleau@everstyl.fr''romain.marchand@variationconfort.fr');
  87.                     $zdc='soldes-roulleau.html.twig';
  88.                 }
  89.                 else if (in_array($departement$manca)) {
  90.                     $commercial = array('jpmanca@everstyl.fr''romain.marchand@variationconfort.fr');
  91.                     $zdc='soldes-manca.html.twig';
  92.                 }
  93.                 else if (in_array($departement$jacquet)) {
  94.                     $commercial = array('fjacquet@everstyl.fr''romain.marchand@variationconfort.fr');
  95.                     $zdc='soldes-jacquet.html.twig';
  96.                 }
  97.                 else if (in_array($departement$debattista)) {
  98.                     $commercial = array('ddebattista@everstyl.fr''romain.marchand@variationconfort.fr');
  99.                     $zdc='soldes-hinques.html.twig';
  100.                 }
  101.                 else if (in_array($departement$languedoc)) {
  102.                     $commercial = array('gmenzoyan@everstyl.fr''romain.marchand@variationconfort.fr');
  103.                     $zdc='soldes-medina.html.twig';
  104.                 }
  105.                 else if (in_array($departement$fantarella)) {
  106.                     $commercial = array('dfantarella@everstyl.fr''romain.marchand@variationconfort.fr');
  107.                     $zdc='soldes-hurlot.html.twig';
  108.                 }
  109.                 
  110.                 else if (in_array($departement$menzoyan)) {
  111.                     $commercial = array('gmenzoyan@everstyl.fr''romain.marchand@variationconfort.fr');
  112.                     $zdc='soldes-men.html.twig';
  113.                 }
  114.                 else if (in_array($departement$thiroux)) {
  115.                     $commercial = array('cthiroux@everstyl.fr''romain.marchand@variationconfort.fr');
  116.                     $zdc='soldes-thiroux.html.twig';
  117.                 }
  118.                 
  119.                 
  120.                 // Create a message
  121.                 $message = (new Swift_Message('[Black Friday] Nouveau contact'))
  122.                   ->setFrom('contact@ventesprivees-everstyl.fr')
  123.                   ->setTo('romain.marchand@variationconfort.fr')
  124.                     
  125.                  //->setTo('lbarbey@everstyl.fr', 'romain.marchand@variationconfort.fr', 'cthiroux@everstyl.fr', 'yfontenay@everstyl.fr' )
  126.                   ->setBody(
  127.                     $this->renderView('email.html.twig', array(
  128.                         'nom' => $prospect->getNom(),
  129.                         'tel' => $prospect->getTel(),
  130.                         'dpt' => $prospect->getDpt(),
  131.                         
  132.                         'code' => $prospect->getCode(),
  133.                         
  134.                         'date' => $prospect->getDate(),
  135.                         
  136.                         'email' => $prospect->getEmail(),
  137.                     )),
  138.                 'text/html'
  139.                   );
  140.                 
  141.                 // Send the message
  142.                 if($mailer->send($message)) {
  143.                     // ... perform some action, such as saving the task to the database
  144.                     // for example, if Task is a Doctrine entity, save it!
  145.                     $entityManager $this->getDoctrine()->getManager();
  146.                     $entityManager->persist($prospect);
  147.                     $entityManager->flush();
  148.                     
  149.                     return $this->render('confirmation.html.twig');
  150.                     // ... perform some action, such as saving the task to the database
  151.                     // for example, if Task is a Doctrine entity, save it!
  152.                 }
  153.                 else {
  154.                     return $this->render('confirmation.html.twig');
  155.                 }
  156.         }
  157.                 
  158.                 
  159.                 // Create a message 
  160.                 /*$message = (new Swift_Message('[Catalogue] Nouveau contact'))
  161.                   ->setFrom('contact@ventesprivees-everstyl.fr')
  162.                   ->setTo('romain.marchand@variationconfort.fr')
  163.                     
  164.                  //->setTo('lbarbey@everstyl.fr', 'romain.marchand@variationconfort.fr', 'cthiroux@everstyl.fr', 'yfontenay@everstyl.fr' )
  165.                   ->setBody(
  166.                     $this->renderView('email.html.twig', array(
  167.                         'nom' => $prospect->getNom(),
  168.                         'tel' => $prospect->getTel(),
  169.                         'dpt' => $prospect->getDpt(),
  170.                         
  171.                         'code' => $prospect->getCode(),
  172.                         
  173.                         'date' => $prospect->getDate(),
  174.                         
  175.                         'email' => $prospect->getEmail(),
  176.                     )),
  177.                 'text/html'
  178.                   );
  179.                 // Send the message
  180.                 if($mailer->send($message)) {
  181.                     // ... perform some action, such as saving the task to the database
  182.                     // for example, if Task is a Doctrine entity, save it!
  183.                     $entityManager = $this->getDoctrine()->getManager();
  184.                     $entityManager->persist($prospect);
  185.                     $entityManager->flush();
  186.                     
  187.                     //return $this->redirect('https://www.boutique-everstyl.com');
  188.                     return $this->render('confirmation-itl.html.twig', [
  189.                         'form' => $form->createView(),
  190.                     ]);
  191.                     // ... perform some action, such as saving the task to the database
  192.                     // for example, if Task is a Doctrine entity, save it!
  193.                 }
  194.                 else {
  195.                     return $this->render('home_soldes.html.twig', [
  196.                         'form' => $form->createView(),
  197.                     ]);
  198.                 }
  199.         }*/
  200.         
  201.         
  202.         return $this->render('home_soldes.html.twig', [
  203.             'form' => $form->createView(),
  204.         ]);
  205.         
  206.     }
  207.     
  208.     
  209.     /** 
  210.      *
  211.      * @Route("/form_ok", name="form_ok")
  212.      */
  213.     public function ValidForm()
  214.     {
  215.         //return $this->redirect('https://www.boutique-everstyl.com');
  216.         return $this->render('confirmation.html.twig');
  217.     }
  218.     
  219.      /**
  220.      * Matches /produits exactly
  221.      *
  222.      * @Route("/", name="home")
  223.      */
  224.     public function Soldes(Request $request)
  225.     {
  226.         return $this->render('base.html.twig');
  227.     }
  228. }