src/Controller/Pages/PagesCiTourismeController.php line 124

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Pages;
  3. use App\Entity\Contacts;
  4. use App\Entity\Demandestages;
  5. use App\Form\ContactsType;
  6. use App\Form\DemandestagesType;
  7. use App\Notifications\MailNotifications;
  8. use MercurySeries\FlashyBundle\FlashyNotifier;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Serializer\SerializerInterface;
  15. /**
  16.  * @Route("/ci-tourisme")
  17.  */
  18. class PagesCiTourismeController extends AbstractController
  19. {
  20.     /**
  21.      * @var FlashyNotifier
  22.      */
  23.     private $flashy;
  24.     public function __construct(FlashyNotifier $flashy)
  25.     {
  26.         $this->flashy $flashy;
  27.     }
  28.     /**
  29.      * @Route("/distinction", name="cit.distinction", defaults={"title":"Notre distinction"})
  30.      * @param $title
  31.      * @return Response
  32.      */
  33.     public function distinction($title): Response
  34.     {
  35.         return $this->render('pages/internes/cit/distinction.html.twig', [
  36.             'title' => $title,
  37.             'menu' => "Cote d'Ivoire",
  38.             'current_page' => 'cit'
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route("/demande-stage", name="cit.demande.stage", defaults={"title":"Demande de stage"})
  43.      * @param $title
  44.      * @param Request $request
  45.      * @return Response
  46.      */
  47.     public function demandeStage($titleRequest $request): Response
  48.     {
  49.         $demandestage = new Demandestages();
  50.         $form $this->createForm(DemandestagesType::class, $demandestage);
  51.         $form->handleRequest($request);
  52.         if ($form->isSubmitted() && $form->isValid()) {
  53.             $entityManager $this->getDoctrine()->getManager();
  54.             $entityManager->persist($demandestage);
  55.             $entityManager->flush();
  56.             $this->flashy->success('Votre demande à été envoyé.');
  57.             return $this->redirectToRoute('cit.demande.stage');
  58.         }
  59.         return $this->render('pages/internes/cit/demandeStage.html.twig', [
  60.             'title' => $title,
  61.             'form' => $form->createView(),
  62.             'menu' => "Cote d'Ivoire",
  63.             'current_page' => 'cit'
  64.         ]);
  65.     }
  66.     /**
  67.      * @Route("/contact-office", name="cit.contact.office", defaults={"title":"Contact Office"}, methods={"POST", "GET"})
  68.      * @param $title
  69.      * @param Request $request
  70.      * @param MailNotifications $notifications
  71.      * @param SerializerInterface $serializer
  72.      * @param FlashyNotifier $flashy
  73.      * @return Response
  74.      */
  75.     public function contactOffice($titleRequest $requestMailNotifications $notificationsSerializerInterface $serializerFlashyNotifier $flashy): Response
  76.     {
  77.         //Traitement du formulaire de contact
  78.         $contact = new Contacts();
  79.         $form $this->createForm(ContactsType::class, $contact);
  80.         $form->handleRequest($request);
  81.         //dd($request->request->get('contacts'));
  82.         if ($request->isXmlHttpRequest()){
  83.             $json $this->json($request->request->get('contacts'));
  84.             $contact $serializer->deserialize($json->getContent(), Contacts::class, 'json');
  85.             if($contact->getRobot() !== ""){
  86.                 return new JsonResponse(['resultat' => "NONOK"]);
  87.             }
  88.             $notifications->sendWithDatas($contact);
  89.             return new JsonResponse(['resultat' => "OK"]);
  90.         }
  91.         if($form->isSubmitted() && $form->isValid()){
  92.             if($contact->getRobot() !== null){
  93.                 return $this->redirectToRoute('contacts');
  94.             }
  95.             $notifications->sendWithDatas($contact);
  96.             $flashy->success('Votre email a bien été envoyé');
  97.             return $this->redirectToRoute('contacts');
  98.         }
  99.         return $this->render('pages/internes/cit/contactOffice.html.twig', [
  100.             'title' => $title,
  101.             'contact' => $contact,
  102.             'form' => $form->createView(),
  103.             'menu' => "Cote d'Ivoire",
  104.             'current_page' => 'cit'
  105.         ]);
  106.     }
  107.     /**
  108.      * @Route("/nos-formulaires", name="cit.formulares", defaults={"title":"Nos formulaires"})
  109.      * @param string $title
  110.      * @return Response
  111.      */
  112.     public function formulaires(string $title): Response
  113.     {
  114.         return $this->render('pages/internes/cit/formulaires.html.twig', [
  115.             'title' => $title,
  116.             'menu' => "Cote d'Ivoire",
  117.             'current_page' => 'cit'
  118.         ]);
  119.     }
  120. }