src/Controller/PlstController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Newsletter;
  4. use App\Repository\NewsletterRepository;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class PlstController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/pls-tp", name="plst-tp")
  13.      */
  14.     public function index()
  15.     {
  16.         return $this->render('plst/index.html.twig', [
  17.             'controller_name' => 'PlstController',
  18.         ]);
  19.     }
  20.     /**
  21.      * @Route("/pls-tp-vih-sida", name="pls-tp-vih-sida")
  22.      */
  23.     public function vihsida()
  24.     {
  25.         return $this->render('plst/vihsida.html.twig', [
  26.         ]);
  27.     }
  28.     /**
  29.      * @Route("/pls-tp-paludisme", name="pls-tp-paludisme")
  30.      */
  31.     public function paludisme()
  32.     {
  33.         return $this->render('plst/paludisme.html.twig', [
  34.         ]);
  35.     }
  36.     /**
  37.      * @Route("/pls-tp-hepatite", name="pls-tp-hepatite")
  38.      */
  39.     public function hepatite()
  40.     {
  41.         return $this->render('plst/hepatite.html.twig', [
  42.         ]);
  43.     }
  44.     /**
  45.      * @Route("/pls-tp-tuberculose", name="pls-tp-tuberculose")
  46.      */
  47.     public function tuberculose()
  48.     {
  49.         return $this->render('plst/tuberculose.html.twig', [
  50.         ]);
  51.     }
  52.     /**
  53.      * @Route("/pls-tp-mst", name="pls-tp-mst")
  54.      */
  55.     public function mst()
  56.     {
  57.         return $this->render('plst/mst.html.twig', [
  58.         ]);
  59.     }
  60.     /**
  61.      * @Route("/pls-tp-ebook", name="pls-tp-ebook")
  62.      */
  63.     public function ebook()
  64.     {
  65.         return $this->render('plst/ebook.html.twig', [
  66.         ]);
  67.     }
  68.     /**
  69.      * @Route("/plst-new", name="newsletter_plst", methods={"GET","POST"})
  70.      */
  71.     public function newplst(Request $request,NewsletterRepository $newsletterRepository): Response
  72.     {
  73.         $newsletter = new Newsletter();
  74.         $email=$request->get('email');
  75.         //dd($email);
  76.         $found=$newsletterRepository->findOneBy([
  77.             'email'=>$email,
  78.             'owner'=>'PLST-TP'
  79.         ]);
  80.         $newsletter->setEmail($request->get('email'));
  81.        // dd($request->get('email'));
  82.         $newsletter->setOwner('PLST-TP');
  83.         $newsletter->setCreatedAt(new \DateTime('now'));
  84.         $em $this->getDoctrine()->getManager();
  85.         $em->persist($newsletter);
  86.         if(!$found){
  87.             $em->flush();
  88.             $this->addFlash(
  89.                 'success',
  90.                 "  Votre inscription à la newsletters du PLS-TP a été effectuée avec succès.
  91.             Vous recevrez désormais nos communications dans votre boîte électronique!"
  92.             );
  93.         }
  94.         else{
  95.             $this->addFlash('danger',"Vous vous êtes déjà enregistré sur notre Newsletter");
  96.         }
  97. //        $form = $this->createForm(NewsletterType::class, $newsletter);
  98. //        $form->handleRequest($request);
  99. //
  100. //        if ($form->isSubmitted() && $form->isValid()) {
  101. //            $entityManager = $this->getDoctrine()->getManager();
  102. //            $entityManager->persist($newsletter);
  103. //            $newsletter->setCreatedAt(new \DateTime('now'));
  104. //            $entityManager->flush();
  105. //
  106. //            return $this->redirectToRoute('home');
  107. //        }
  108. //        return $this->render('newsletter/new.html.twig', [
  109. //            'newsletter' => $newsletter,
  110. //            'form' => $form->createView(),
  111. //        ]);
  112.         return $this->redirectToRoute('plst-tp');
  113.     }
  114. }