src/Controller/Front/ElearningController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Elearning;
  4. use App\Entity\LiveSession;
  5. use App\Entity\Post;
  6. use App\Entity\PostCategory;
  7. use App\Services\EmailManager;
  8. use App\Services\PagesManager;
  9. use App\Services\PdfManager;
  10. use App\Services\StripeManager;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. class ElearningController extends AbstractController
  17. {
  18.     /**
  19.      * @Route("/elearning", name="page_elearning")
  20.      * Method ({"GET", "POST"})
  21.      */
  22.     public function index(Request $requestPagesManager $pagesManager): Response
  23.     {
  24.         $em $this->getDoctrine()->getManager();
  25.         $page $request->get('page'1);
  26.         $limit $request->get('limit'9);
  27.         $category $request->get('category''');
  28.         $elearningPage $em->getRepository(Post::class)->findOneBySlug('banner-elearning');
  29.         $categories $em->getRepository(PostCategory::class)->findBy(['postType' => 'elearning']);
  30.         $videos $em->getRepository(Elearning::class)->search($page$limit$category);
  31.         $formations $em->getRepository(LiveSession::class)->search(16nullnull);
  32.         return $this->render('front/elearning/index.html.twig', [
  33.             'blocs' => $pagesManager->getPageBlocs($elearningPage),
  34.             'categories' => $categories,
  35.             'formations' => $formations,
  36.             'videos' => $videos,
  37.             'page' => ($page+1),
  38.             'limit' => $limit
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route("/elearning-paginate", name="page_elearning_paginate", options={"expose"=true})
  43.      * Method ({"GET", "POST"})
  44.      */
  45.     public function paginate(Request $request): Response
  46.     {
  47.         $em $this->getDoctrine()->getManager();
  48.         $page $request->get('page'1);
  49.         $limit $request->get('limit'3);
  50.         $category $request->get('category''');
  51.         $videos $em->getRepository(Elearning::class)->search($page$limit$category);
  52.         return $this->render('front/elearning/elearning_ajax.html.twig', [
  53.             'videos' => $videos
  54.         ]);
  55.     }
  56.     /**
  57.      * @Route("/elearning/{slug}", name="page_elearning_single")
  58.      * Method ({"GET", "POST"})
  59.      */
  60.     public function show($slugPagesManager $pagesManager): Response
  61.     {
  62.         $em $this->getDoctrine()->getManager();
  63.         $elearning $em->getRepository(Elearning::class)->findOneBySlug($slug);
  64.         $toSee $em->getRepository(Elearning::class)->getToSee($elearning->getCategory(), $slug);
  65.         $formations $em->getRepository(LiveSession::class)->search(13nullnull);
  66.         $elearningPage $em->getRepository(Post::class)->findOneBySlug('banner-elearning');
  67.         return $this->render('front/elearning/show.html.twig', [
  68.             'blocs' => $pagesManager->getPageBlocs($elearningPage),
  69.             'video' => $elearning,
  70.             'toSee' => $toSee,
  71.             'formations' => $formations
  72.         ]);
  73.     }
  74.     /**
  75.      * @Route("/abonnements-elearning", name="page_abonnnements_elearning")
  76.      * Method ({"GET", "POST"})
  77.      */
  78.     public function abonnement(PagesManager $pagesManager): Response
  79.     {
  80.         $page $this->getDoctrine()->getManager()->getRepository(Post::class)->findOneBySlug('abonnements-elearning');
  81.         return $this->render('front/elearning/abonnement.html.twig', [
  82.             'blocs' => $pagesManager->getPageBlocs($page)
  83.         ]);
  84.     }
  85.     /**
  86.      * @Route("/abonnements/{type}", name="page_abonnnements_elearning_subscription")
  87.      * Method ({"GET", "POST"})
  88.      */
  89.     public function abonnementSubscription(Request $request$type): Response
  90.     {
  91.         if(!$this->getUser()) {
  92.             return new RedirectResponse($this->generateUrl('front_login'));
  93.         }
  94.         return $this->render('front/elearning/abonnement_subscription.html.twig', [
  95.             'type' => $type
  96.         ]);
  97.     }
  98.     /**
  99.      * @Route("/abonnements/{type}/validation", name="page_abonnnements_elearning_subscription_validation")
  100.      * Method ({"GET", "POST"})
  101.      */
  102.     public function abonnementSubscriptionValidation(Request $request$typeStripeManager $stripeManagerEmailManager $emailManagerPdfManager $pdfManager): Response
  103.     {
  104.         $output null;
  105.         if(!$this->getUser()) {
  106.             return new RedirectResponse($this->generateUrl('front_login'));
  107.         }
  108.         if($request->isMethod('POST')) {
  109.             if($request->request->get('newsletter'false)) {
  110.                 $this->getUser()->setIsAcceptNewsletter(true);
  111.             }
  112.             $output $stripeManager->addSubscriptionToUser($this->getUser(), $type$request->request->get('stripeToken'), $request->request->get('code_reduction'null), $request->request->get('addoption'null), $request->request->get('modality''annually'));
  113.             if($output['status'] == 'success') {
  114.                 $pdfOption null;
  115.                 $pdf $pdfManager->generatePdfFacture($output['order']);
  116.                 if($request->request->get('addoption'null)) {
  117.                     $pdfOption $pdfManager->generatePdfOptionFacture($output['order']);
  118.                 }
  119.                 $emailManager->sendEmailPaymentAbonnementSuccessToCandidate($output['order'], $pdf$pdfOption);
  120.             }
  121.         }
  122.         return $this->render('front/elearning/abonnement_subscription_validation.html.twig', [
  123.             'type' => $type,
  124.             'output' => $output
  125.         ]);
  126.     }
  127. }