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