<?php
namespace App\Controller\Front;
use App\Controller\CoreController;
use App\Enum\AppConst;
use App\Enum\Roles;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* Class HomeController
* @package App\Controller\Front
* @Route("/")
* @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')")
*/
class HomeController extends CoreController
{
/**
* Change locale - front
*
* @return Response
*
* @Route("/change/locale/{locale}", name="change_locale")
*/
public function changeLocale($locale): Response
{
// On stocke la langue dans la session
$this->requestStack->getCurrentRequest()->getSession()->set('_locale', $locale);
// On revient sur la page pr�c�dente
return $this->redirect($this->requestStack->getCurrentRequest()->headers->get('referer'));
}
/**
* Index - front
*
* @return Response
*
* @Route("/{myflix}", name="app_path_front")
*/
public function index($myflix): Response
{
$user = $this->getUser();
$chanel = $this->repository->MyflixRepository->findOneBy(["slug" => $myflix]);
/*** if the connected user is a speaker redirected to the list of interventions */
$intervenant = $this->repository->UserFlixRepository->findOneBy(['member' => $user->getId(), 'myflix' => $chanel->getId(), 'role' => Roles::ROLE_INTERVENANT, 'isVerified' => 1]);
$member = $this->repository->UserFlixRepository->findOneBy(['member' => $user->getId(), 'myflix' => $chanel->getId(), 'role' => Roles::ROLE_MEMBER, 'isVerified' => 1]);
if($intervenant && is_null($member)){ return $this->redirectToRoute('interventions', ['myflix' => $chanel->getSlug()]); }
$this->checkMyflix($chanel);
$setting = $this->repository->GeneralSettingRepository->findOneBy(["myflix" => $chanel]);
$listVideo = $this->capsuleService->findCapsuleByFilter($chanel, AppConst::PAGE_HOME, null);
return $this->render('front/index.html.twig', [
'capsules' => $listVideo,
'setting' => $setting,
'banners' => $chanel->getBanner(),
]);
}
/**
*
* Check Myflix
*/
public function checkMyflix($myflix){
$user = $this->getUser();
if(is_null($user)){ return $this->redirectToRoute('app_login_membre', ['myflix' => $myflix]); }
if($myflix == "login"){ return $this->redirectToRoute('app_login'); }
$chanel = $this->repository->MyflixRepository->findOneBy(["slug" => $myflix]);
if(is_null($chanel)){ return $this->redirectToRoute('error_404'); }
}
/**
* Redirect to front
*
* @return Response
*
* @Route("/redirect/{type_user}/{myflix}/{locale}", name="redirect_to_front")
*/
public function redirectFront($type_user, $myflix, $locale): Response
{
$session = $this->requestStack->getCurrentRequest()->getSession();
if($type_user == 'admin_canal'){
$session->set('session_admin', 'admin_canal');
}else{
$session->set('session_admin', '');
}
$this->requestStack->getCurrentRequest()->getSession()->set('_locale', $locale);
return $this->redirectToRoute('app_path_front', ['myflix' => $myflix]);
}
}