src/Controller/Frontend/DefaultController.php line 270

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