src/Controller/Front/HomeController.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Controller\CoreController;
  4. use App\Enum\AppConst;
  5. use App\Enum\Roles;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  13. use Knp\Component\Pager\PaginatorInterface;
  14. use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
  15. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  16. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  17. /**
  18.  * Class HomeController
  19.  * @package App\Controller\Front
  20.  * @Route("/")
  21.  * @Security("is_granted('ROLE_MEMBER') or is_granted('ROLE_ADMIN_MYFLIX') or is_granted('ROLE_SUPER_PARTNER') or is_granted('ROLE_EDITOR_MYFLIX') or is_granted('ROLE_EDITOR_MYFLIX') or is_granted('ROLE_PARTNER_MYFLIX') or is_granted('ROLE_ADMIN_PARTNER') or is_granted('ROLE_EDITOR_PARTNER') or is_granted('ROLE_SUPER_ADMIN_MYFLIX') or is_granted('ROLE_INTERVENANT') or is_granted('ROLE_ORATEUR') or is_granted('ROLE_INTERVENANT')")
  22.  */
  23. class HomeController extends CoreController
  24. {
  25.     /**
  26.      * Change locale - front
  27.      *
  28.      * @return Response
  29.      *
  30.      * @Route("/change/locale/{locale}", name="change_locale")
  31.      */
  32.     public function changeLocale($locale): Response
  33.     {
  34.         // On stocke la langue dans la session
  35.         $this->requestStack->getCurrentRequest()->getSession()->set('_locale'$locale);
  36.         // On revient sur la page pr�c�dente
  37.         return $this->redirect($this->requestStack->getCurrentRequest()->headers->get('referer'));
  38.     }
  39.     /**
  40.      * Index - front
  41.      *
  42.      * @return Response
  43.      *
  44.      * @Route("/{myflix}", name="app_path_front")
  45.      */
  46.     public function index($myflix): Response
  47.     {
  48.         $user $this->getUser();
  49.         $chanel $this->repository->MyflixRepository->findOneBy(["slug" => $myflix]);
  50.         /*** if the connected user is a speaker redirected to the list of interventions */
  51.         $intervenant $this->repository->UserFlixRepository->findOneBy(['member' => $user->getId(), 'myflix' => $chanel->getId(), 'role' => Roles::ROLE_INTERVENANT'isVerified' => 1]);
  52.         $member $this->repository->UserFlixRepository->findOneBy(['member' => $user->getId(), 'myflix' => $chanel->getId(), 'role' => Roles::ROLE_MEMBER'isVerified' => 1]);
  53.         if($intervenant && is_null($member)){ return  $this->redirectToRoute('interventions', ['myflix' => $chanel->getSlug()]);  }
  54.         $this->checkMyflix($chanel);
  55.         $setting $this->repository->GeneralSettingRepository->findOneBy(["myflix" => $chanel]);
  56.         $listVideo $this->capsuleService->findCapsuleByFilter($chanelAppConst::PAGE_HOMEnull);
  57.         return $this->render('front/index.html.twig', [
  58.             'capsules' =>  $listVideo,
  59.             'setting' =>  $setting,
  60.             'banners' =>  $chanel->getBanner(),
  61.         ]);
  62.     }
  63.     /**
  64.      *
  65.      * Check Myflix
  66.      */
  67.     public function checkMyflix($myflix){
  68.         $user $this->getUser();
  69.         if(is_null($user)){ return $this->redirectToRoute('app_login_membre', ['myflix' => $myflix]); }
  70.         if($myflix == "login"){ return $this->redirectToRoute('app_login');  }
  71.         $chanel $this->repository->MyflixRepository->findOneBy(["slug" => $myflix]);
  72.         if(is_null($chanel)){ return $this->redirectToRoute('error_404'); }
  73.     }
  74.     /**
  75.      * Redirect to front
  76.      *
  77.      * @return Response
  78.      *
  79.      * @Route("/redirect/{type_user}/{myflix}/{locale}", name="redirect_to_front")
  80.      */
  81.     public function redirectFront($type_user$myflix$locale): Response
  82.     {
  83.         $session $this->requestStack->getCurrentRequest()->getSession();
  84.         if($type_user == 'admin_canal'){
  85.             $session->set('session_admin''admin_canal');
  86.         }else{
  87.             $session->set('session_admin''');
  88.         }
  89.         $this->requestStack->getCurrentRequest()->getSession()->set('_locale'$locale);
  90.         return $this->redirectToRoute('app_path_front', ['myflix' => $myflix]);
  91.     }
  92. }