src/Controller/Frontend/RentABusController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Entity\Block;
  4. use App\Entity\model\Rent;
  5. use App\Form\RentType;
  6. use App\Repository\BlockRepository;
  7. use App\Repository\StopRepository;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Mailer\MailerInterface;
  12. use Symfony\Component\Mime\Email;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class RentABusController extends AbstractController {
  15.     /** @required */
  16.     public BlockRepository $blockRepo;
  17.     /**
  18.      * @Route("/location-bus", name="page_quotation", options={"i18n_locales"={"fr","en"}})
  19.      * @Template("Default/rent/quotation.html.twig")
  20.      */
  21.     public function quotationRentFormAction(Request $requestMailerInterface $mailerStopRepository $stopRepo) {
  22.         $block $this->getBlock($request);
  23.         $rent = new Rent();
  24.         $rent->setDepStop($stopRepo->find(10));
  25.         $rent->setArrStop($stopRepo->find(6));
  26.         $rent->setDepDatetime(new \DateTime('10:00'));
  27.         $rent->setToDatetime(new \DateTime('10:00'));
  28.         $form $this->createForm(RentType::class, $rent);
  29.         $form->handleRequest($request);
  30.         if ($form->isSubmitted() && $form->isValid()) {
  31.             /** @var Rent $rent */
  32.             $rent $form->getData();
  33.             if ($rent->getBack()) {
  34.                 $back "Pas de retour <br/>";
  35.             } else {
  36.                 $back "<label>Date de retour : </label>" $rent->getToDatetime()->format('Y-m-d') . "<br/>
  37.                      <label>Horaire de retour : </label>" $rent->getToDatetime()->format('H:i') . "<br/>";
  38.             }
  39.             $message = (new Email())
  40.                 ->subject('Nouvelle demande de devis [ComparaBUS]')
  41.                 ->from('remy.cloutrier@gmail.com')
  42.                 ->to('contact@comparabus.com')
  43.                 ->replyTo($rent->getEmail())
  44.                 ->html("<html>
  45.                     <body>
  46.                         <div>
  47.                             <div>
  48.                                 <p>Bonjour,<br/>
  49.                                 Vous trouverez ci-dessous toutes les informations concernant cette nouvelle demande de devis :
  50.                                 </p>
  51.                             </div><hr>
  52.                             <div style=\"color: #0b3e6f\">
  53.                                 <label>Nom : </label>" $rent->getName() . " <br/>
  54.                                 <label>Adresse email : </label>" $rent->getEmail() . "<br/>
  55.                                 <label>Téléphone : </label>".$rent->getPhone()."<br/>
  56.                                 <label>Nombre de personnes : </label>" $rent->getSeat() . " <br/>
  57.                                 <h4>Départ</h4>
  58.                                 <label>Lieu de départ : <label>" $rent->getDepStop()->getName() . "<br/>
  59.                                 <label>Date de départ : </label>" $rent->getDepDatetime()->format('Y-m-d') . "<br/>
  60.                                 <label>Horaire de départ : </label>" $rent->getDepDatetime()->format('H:i') . "<br/>
  61.                                 <h4>Arrivée</h4>
  62.                                 <label>Lieu d’arrivée : </label>" $rent->getArrStop()->getName() . " <br/>
  63.                                 <h4>Retour</h4>
  64.                                 $back
  65.                                 <h4>Commentaires  : </h4><p>" $rent->getComment() . "</p><br/>
  66.                             </div><hr>
  67.                             <div>
  68.                                 <p>
  69.                                     Bonne réception,<br/>Bien cordialement,
  70.                                 </p>
  71.                             </div>
  72.                         </div>
  73.                     </body>
  74.                     <footer>
  75.                         <h3>L’équipe ComparaBUS</h3>
  76.                         <p>Email : partner@comparabus.com</p>
  77.                         <span>
  78.                             <a href=\"https://www.comparabus.com/\">
  79.                                 <img src=\"https://www.comparabus.com/images/press/media/comparabus_logo-name_w300.png\" width=\" 64 px\">
  80.                             </a>
  81.                         </span>
  82.                     </footer>
  83.                     </html>",
  84.                     'text/html'
  85.                 );
  86.             $mailer->send($message);
  87.             $this->addFlash('message', [1]);
  88.         }
  89.         //$block = $this->getBlockRepo()->findOnebyPathNotNull($request->getPathInfo() . '#modification');
  90.         return [
  91.             'form' => $form->createView(),
  92.             'block' => $block
  93.         ];
  94.     }
  95.     /**
  96.      * Get the block if exists
  97.      */
  98.     private function getBlock(Request $request): Block {
  99.         $currentUrl $request->getPathInfo();
  100.         $block $this->blockRepo->findOneByPath($currentUrl);
  101.         if (!$block) {
  102.             throw $this->createNotFoundException('Page/Blog does not exist');
  103.         }
  104.         return $block;
  105.     }
  106. }