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