src/Controller/SubController.php line 410

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''53''72''61''14''50');
  57.                 $menzoyan = array('07''26''38''73''74','69','43','63');
  58.                 $fontenay = array('78''91''92''28''41''45');
  59.                 $nord = array('80''62''59''02''08');
  60.                 $roulleau = array('51''10''89''52');
  61.                 $manca = array('55''54''57''88''68''90');
  62.                 $jacquet = array('18''58''21''03''71''39''01',  '42''70''25');
  63.                 $debattista = array('30''84''13''83''04''06''05');
  64.                 $languedoc = array('48''12''81''34''11''09''66''31','15');
  65.                 $fantarella = array('64''65''32''40''33''47''82''46''24''19');
  66.                 $barbey = array('75');
  67.                 $thiroux = array('95''94''93''77''60''51');
  68.                 
  69.                 $courault = array('44''49''85''37''79','86','36''23''17''16''87');
  70.                 
  71.                 if (in_array($departement$levasseur)) {
  72.                     $commercial = array('tromaneix@everstyl.fr''romain.marchand@variationconfort.fr');
  73.                     $zdc='soldes-guermeur.html.twig';
  74.                 }
  75.                 
  76.                 if (in_array($departement$courault)) {
  77.                     $commercial = array('tcourault@everstyl.fr''romain.marchand@variationconfort.fr');
  78.                     $zdc='soldes-courault.html.twig';
  79.                 }
  80.                 else if (in_array($departement$fontenay)) {
  81.                     $commercial = array('yfontenay@everstyl.fr''romain.marchand@variationconfort.fr');
  82.                     $zdc='soldes-bes2.html.twig';
  83.                 }
  84.                 else if (in_array($departement$barbey)) {
  85.                     $commercial = array('lbarbey@everstyl.fr''romain.marchand@variationconfort.fr');
  86.                     $zdc='soldes-barbey.html.twig';
  87.                 }
  88.                 else if (in_array($departement$nord)) {
  89.                     $commercial = array('gmagrez@everstyl.fr''romain.marchand@variationconfort.fr');
  90.                     $zdc='soldes-sergeant.html.twig';
  91.                 }
  92.                 else if (in_array($departement$roulleau)) {
  93.                     $commercial = array('ldarnand@everstyl.fr''romain.marchand@variationconfort.fr');
  94.                     $zdc='soldes-roulleau.html.twig';
  95.                 }
  96.                 else if (in_array($departement$manca)) {
  97.                     $commercial = array('ldarnand@everstyl.fr''romain.marchand@variationconfort.fr');
  98.                     $zdc='soldes-manca.html.twig';
  99.                 }
  100.                 else if (in_array($departement$jacquet)) {
  101.                     $commercial = array('ldarnand@everstyl.fr''romain.marchand@variationconfort.fr');
  102.                     $zdc='soldes-jacquet.html.twig';
  103.                 }
  104.                 else if (in_array($departement$debattista)) {
  105.                     $commercial = array('ddebattista@everstyl.fr''romain.marchand@variationconfort.fr');
  106.                     $zdc='soldes-hinques.html.twig';
  107.                 }
  108.                 else if (in_array($departement$languedoc)) {
  109.                     $commercial = array('etalki@everstyl.fr''romain.marchand@variationconfort.fr');
  110.                     $zdc='soldes-medina.html.twig';
  111.                 }
  112.                 else if (in_array($departement$fantarella)) {
  113.                     $commercial = array('fbecuwe@everstyl.fr''romain.marchand@variationconfort.fr');
  114.                     $zdc='soldes-hurlot.html.twig';
  115.                 }
  116.                 
  117.                 else if (in_array($departement$menzoyan)) {
  118.                     $commercial = array('jcgarin@everstyl.fr''romain.marchand@variationconfort.fr');
  119.                     $zdc='soldes-men.html.twig';
  120.                 }
  121.                 else if (in_array($departement$thiroux)) {
  122.                     $commercial = array('ddenis@everstyl.fr''romain.marchand@variationconfort.fr');
  123.                     $zdc='soldes-thiroux.html.twig';
  124.                 }
  125.                 
  126.                 
  127.                 // Create a message
  128.                 $message = (new Swift_Message('[Black Friday] Nouveau contact'))
  129.                   ->setFrom('contact@ventesprivees-everstyl.fr')
  130.                   ->setTo('romain.marchand@variationconfort.fr')
  131.                     
  132.                  //->setTo('lbarbey@everstyl.fr', 'romain.marchand@variationconfort.fr', 'cthiroux@everstyl.fr', 'yfontenay@everstyl.fr' )
  133.                   ->setBody(
  134.                     $this->renderView('email.html.twig', array(
  135.                         'nom' => $prospect->getNom(),
  136.                         'tel' => $prospect->getTel(),
  137.                         'dpt' => $prospect->getDpt(),
  138.                         
  139.                         'code' => $prospect->getCode(),
  140.                         
  141.                         'date' => $prospect->getDate(),
  142.                         
  143.                         'email' => $prospect->getEmail(),
  144.                     )),
  145.                 'text/html'
  146.                   );
  147.                 
  148.                 // Send the message
  149.                 if($mailer->send($message)) {
  150.                     // ... perform some action, such as saving the task to the database
  151.                     // for example, if Task is a Doctrine entity, save it!
  152.                     $entityManager $this->getDoctrine()->getManager();
  153.                     $entityManager->persist($prospect);
  154.                     $entityManager->flush();
  155.                     
  156.                     return $this->render('confirmation.html.twig');
  157.                     // ... perform some action, such as saving the task to the database
  158.                     // for example, if Task is a Doctrine entity, save it!
  159.                 }
  160.                 else {
  161.                     return $this->render('confirmation.html.twig');
  162.                 }
  163.         }
  164.                 
  165.                 
  166.                 // Create a message 
  167.                 /*$message = (new Swift_Message('[Catalogue] Nouveau contact'))
  168.                   ->setFrom('contact@ventesprivees-everstyl.fr')
  169.                   ->setTo('romain.marchand@variationconfort.fr')
  170.                     
  171.                  //->setTo('lbarbey@everstyl.fr', 'romain.marchand@variationconfort.fr', 'cthiroux@everstyl.fr', 'yfontenay@everstyl.fr' )
  172.                   ->setBody(
  173.                     $this->renderView('email.html.twig', array(
  174.                         'nom' => $prospect->getNom(),
  175.                         'tel' => $prospect->getTel(),
  176.                         'dpt' => $prospect->getDpt(),
  177.                         
  178.                         'code' => $prospect->getCode(),
  179.                         
  180.                         'date' => $prospect->getDate(),
  181.                         
  182.                         'email' => $prospect->getEmail(),
  183.                     )),
  184.                 'text/html'
  185.                   );
  186.                 // Send the message
  187.                 if($mailer->send($message)) {
  188.                     // ... perform some action, such as saving the task to the database
  189.                     // for example, if Task is a Doctrine entity, save it!
  190.                     $entityManager = $this->getDoctrine()->getManager();
  191.                     $entityManager->persist($prospect);
  192.                     $entityManager->flush();
  193.                     
  194.                     //return $this->redirect('https://www.boutique-everstyl.com');
  195.                     return $this->render('confirmation-itl.html.twig', [
  196.                         'form' => $form->createView(),
  197.                     ]);
  198.                     // ... perform some action, such as saving the task to the database
  199.                     // for example, if Task is a Doctrine entity, save it!
  200.                 }
  201.                 else {
  202.                     return $this->render('home_soldes.html.twig', [
  203.                         'form' => $form->createView(),
  204.                     ]);
  205.                 }
  206.         }*/
  207.         
  208.         
  209.         return $this->render('home_soldes.html.twig', [
  210.             'form' => $form->createView(),
  211.         ]);
  212.         
  213.     }
  214.     
  215.     
  216.     /** 
  217.      *
  218.      * @Route("/form_ok", name="form_ok")
  219.      */
  220.     public function ValidForm()
  221.     {
  222.         //return $this->redirect('https://www.boutique-everstyl.com');
  223.         return $this->render('confirmation.html.twig');
  224.     }
  225.     
  226.      /**
  227.      * Matches /produits exactly
  228.      *
  229.      * @Route("/", name="home")
  230.      */
  231.     public function Soldes(Request $request)
  232.     {
  233.         return $this->render('base.html.twig');
  234.     }
  235. }