src/Controller/Frontend/DefaultController.php line 251

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\Mailer\MailerInterface;
  13. use Symfony\Component\Mime\Email;
  14. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  15. use App\Services\MailerService;
  16. use App\Services\MessageService;
  17. use App\Services\OptionService;
  18. use App\Entity\{
  19.     Page,
  20.     Block,
  21.     Contact,
  22.     Categorypage,
  23.     Actualites,
  24.     Um6p\Event,
  25.     Um6p\MediaEvent,
  26.     Um6p\Speaker
  27. };
  28. use App\Form\Frontend\ContactpublicType;
  29. use App\Form\Frontend\CandidaturepublicType;
  30. use App\Form\Frontend\Sothema\PharmapublicType;
  31. class DefaultController extends AbstractController
  32. {
  33.     /**
  34.      * @var OptionService
  35.      */
  36.     private $configRepo;
  37.     public function __construct(OptionService $configRepo)
  38.     {
  39.         $this->configRepo $configRepo;
  40.     }
  41.     /**
  42.      * Change the locale for the current user
  43.      *
  44.      * @param String $langue
  45.      * @return array
  46.      *
  47.      * @Route("/setlocale/{langue}", name="select_lang", defaults={"langue":"en"}, requirements={"_locale":"en|fr"})
  48.      */
  49.     public function setLocaleAction($langue "en"Request $request)
  50.     {
  51.         if ($langue != null) {
  52.             $request->getSession()->set('_locale'$langue);
  53.             $this->get('session')->set('_locale'$langue);
  54.             $request->setLocale($langue);
  55.         }
  56.         $url $this->generateUrl('frontend_home', array('_locale' => $langue));
  57.         return new RedirectResponse($url);
  58.     }
  59.     /**
  60.      * @Route("/{_locale}", name="frontend_home", defaults={"_locale":"en"}, requirements={"_locale":"en|fr"})
  61.      */
  62.     public function index(): Response
  63.     {
  64.         $em                $this->getDoctrine()->getManager();
  65.         $page_selected     $em->getRepository(Page::class)->findOneBySlug('home');
  66.        // $list_inspirations = $em->getRepository(inspiration::class)->getAllHomePublic();
  67.         return $this->render('Frontend/Page/index.html.twig', [
  68.             'page_selected'      => $page_selected
  69.         ]);
  70.     }
  71.     /**
  72.      * @Route("/_header", name="_header")
  73.      */
  74.     public function _header(): Response
  75.     {
  76.         $em                $this->getDoctrine()->getManager();
  77.         $categorier_pages  $em->getRepository(Categorypage::class)->getAllpublic();
  78.         return $this->render('Frontend/_header.html.twig', [
  79.             'categorier_pages'  =>  $categorier_pages
  80.         ]);
  81.     }
  82.     /**
  83.      * @Route("/_footer", name="_footer")
  84.      */
  85.     public function _footer(Request $request): Response
  86.     {
  87.         return $this->render('Frontend/_footer.html.twig');
  88.     }
  89.     /*  Actualités  */
  90.     /**
  91.      * @Route("/{_locale}/actualites", name="actualites", defaults={"_locale":"en"}, requirements={"_locale":"en|fr"})
  92.      */
  93.     public function actualites(Request $request): Response
  94.     {
  95.         $em                $this->getDoctrine()->getManager();
  96.         $nbrmax_article    $this->configRepo->getValue('article_nbr_page');
  97.         $page              $request->query->getInt('page'1);
  98.         $page_selected     $em->getRepository(Page::class)->findOneBySlug('actualites');
  99.         $list_actualites   $em->getRepository(Actualites::class)->findAllPagination($page$nbrmax_article);
  100.         $pagination        = array(
  101.             'page'        => $page,
  102.             'nbPages'     => ceil(count($list_actualites) / $nbrmax_article),
  103.             'nomRoute'    => 'actualites',
  104.             'paramsRoute' => array()
  105.         );
  106.         if ($page_selected) {
  107.             return $this->render('Frontend/Actualites/actualites.html.twig', [
  108.                 'page_selected'     => $page_selected,
  109.                 'list_actualites'   => $list_actualites,
  110.                 'pagination'        => $pagination
  111.             ]);
  112.         }
  113.         throw new NotFoundHttpException();
  114.     }
  115.     /**
  116.      * @Route("/{_locale}/actualites/{slug}", name="actu_selected", defaults={"_locale":"en"}, requirements={"_locale":"en|fr"})
  117.      */
  118.     public function actuSelected($slugRequest $request): Response
  119.     {
  120.         $em               $this->getDoctrine()->getManager();
  121.         $page_selected    $em->getRepository(Page::class)->findOneBySlug('actualites');
  122.         $actu_selected    $em->getRepository(Actualites::class)->findOneBySlug($slug);
  123.         if ($actu_selected) {
  124.             return $this->render('Frontend/Actualites/actu_selected.html.twig', [
  125.                 'page_selected'   => $page_selected,
  126.                 'actu_selected'   => $actu_selected
  127.             ]);
  128.         }
  129.         throw new NotFoundHttpException();
  130.     }
  131.     //Events
  132.     
  133.     /**
  134.      * @Route("/{_locale}/seminars-conferences/{slug}", name="event_selected", defaults={"_locale":"en"}, requirements={"_locale":"en|fr"})
  135.      */
  136.     public function eventSelected($slugRequest $request): Response
  137.     {
  138.         $em                $this->getDoctrine()->getManager();
  139.       //  $page_selected    = $em->getRepository(Page::class)->findOneBySlug('seminars-conferences');
  140.         $event_selected    $em->getRepository(Event::class)->findOneBySlug($slug);
  141.         $list_galerie      $em->getRepository(MediaEvent::class)->getAllPublic($event_selected);
  142.         $list_videos       $em->getRepository(MediaEvent::class)->getAllPublicByOpen($event_selected);
  143.         $list_speakers     $em->getRepository(Speaker::class)->getAllPublic($event_selected);
  144.         if ($event_selected) {
  145.             return $this->render('Frontend/Events/event_selected.html.twig', [
  146.                 'event_selected'  => $event_selected,
  147.                 'list_galerie'    => $list_galerie,
  148.                 'list_videos'     => $list_videos,
  149.                 'list_speakers'   => $list_speakers,
  150.             ]);
  151.         }
  152.         throw new NotFoundHttpException();
  153.     }
  154.     /**
  155.      * @Route("/{_locale}/contact", name="contact", defaults={"_locale":"en"}, requirements={"_locale":"en|fr"})
  156.      */
  157.     public function contact(Request $requestMailerInterface $mailer): Response
  158.     {
  159.         $contact         = new Contact();
  160.         $em              $this->getDoctrine()->getManager();
  161.         $page_selected   $em->getRepository(Page::class)->findOneBySlug('contact');
  162.         $form            $this->createForm(ContactpublicType::class, $contact, array(
  163.             'action' => $this->generateUrl('contact'),
  164.             'method' => 'POST'
  165.         ));
  166.         if ($request->isMethod('POST')) {
  167.             $form->handleRequest($request);
  168.             if ($form->isValid()) {
  169.                 $em->persist($contact);
  170.                 $em->flush();
  171.                 /* $datamail = $this->sendEmail($contact,'Contact',"Frontend/Email/_contact.html.twig");
  172.                     $mailer->send($datamail); */
  173.                 $request->getSession()->getFlashBag()->add('notice_success''Votre message a bien été envoyé');
  174.                 return $this->redirectToRoute('contact');
  175.             } else {
  176.                 $request->getSession()->getFlashBag()->add('notice_error''Votre formulaire est invalide');
  177.             }
  178.         }
  179.         return $this->render('Frontend/Contact/contact.html.twig', [
  180.             'page_selected'   => $page_selected,
  181.             'form'            => $form->createView()
  182.         ]);
  183.     }
  184.     /**
  185.      * @Route("/{_locale}/{slug}", name="page_single_simple", defaults={"_locale":"en"}, requirements={"_locale":"en|fr"})
  186.      */
  187.     public function pageSingleSimple($slugRequest $request): Response
  188.     {
  189.         $em                  $this->getDoctrine()->getManager();
  190.         $page_selected       $em->getRepository(Page::class)->findOneBySlug($slug);
  191.         
  192.         if ($page_selected) {
  193.             return $this->render('Frontend/Page/page_single.html.twig', [
  194.                 'page_selected'   => $page_selected
  195.             ]);
  196.         }
  197.         throw $this->createNotFoundException('Page not found');
  198.     }
  199.     /**
  200.      * @Route("/{_locale}/{catslug}/{slug}", name="page_single", defaults={"_locale":"en"}, requirements={"_locale":"en|fr"})
  201.      */
  202.     public function pageSingle($catslug$slugRequest $request): Response
  203.     {
  204.         $em                 $this->getDoctrine()->getManager();
  205.         $cat_selected       $em->getRepository(Categorypage::class)->findOneBySlug($catslug);
  206.         $page_selected      $em->getRepository(Page::class)->findOneBySlug($slug);
  207.         if ($page_selected) {
  208.             if ($page_selected->getSlug() == 'seminars-conferences') {
  209.                 $nbrmax_article    $this->configRepo->getValue('articles_nbr_page');
  210.                 $page_current      $request->query->getInt('page'1);
  211.     
  212.                 $list_events    $em->getRepository(Event::class)->findAllPagineEtTrie($page_current$nbrmax_article);
  213.                 $pagination        = array(
  214.                     'page'        => $page_current,
  215.                     'nbPages'     => ceil(count($list_events) / $nbrmax_article),
  216.                     'nomRoute'    => 'page_single',
  217.                     'paramsRoute' => array(
  218.                                             'catslug' => $catslug,
  219.                                             'slug'    => $slug
  220.                                         )
  221.                 );
  222.                 return $this->render('Frontend/Events/list_events.html.twig', [
  223.                     'page_selected'  => $page_selected,
  224.                     'list_events'    => $list_events,
  225.                     'pagination'     => $pagination,
  226.                 ]);
  227.             }
  228.         
  229.         
  230.             return $this->render('Frontend/Page/page_single.html.twig', [
  231.                 'cat_selected'    => $cat_selected,
  232.                 'page_selected'   => $page_selected
  233.             ]);
  234.         }
  235.         throw $this->createNotFoundException('Page not found');
  236.     }
  237.     private function sendEmail($data$object$template)
  238.     {
  239.         $dataview  =  $this->renderView($template, array('contact' => $data));
  240.         $email = (new Email())
  241.             ->from($this->configRepo->getValue('mail_envoie'))
  242.             ->to($this->configRepo->getValue('mail_reception'))
  243.             ->subject($object)
  244.             ->html($dataview);
  245.         return $email;
  246.     }
  247.     private function sendEmailCC($data$object$template)
  248.     {
  249.         $dataview  =  $this->renderView($template, array('visiteur' => $data));
  250.         $email = (new Email())
  251.             ->from($this->configRepo->getValue('mail_envoie'))
  252.             ->to($data->getMailadresse())
  253.             ->subject($object)
  254.             ->html($dataview);
  255.         return $email;
  256.     }
  257. }