<?php
namespace App\Controller\Site;
use App\Controller\BaseController;
use App\Entity\VideoVisit;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use App\Entity\Video;
use App\Repository\VideoRepository;
use App\Repository\CategorieVideoRepository;
class VideosController extends BaseController
{
private $em,$paginator;
public function __construct(EntityManagerInterface $em, PaginatorInterface $paginator)
{
$this->em=$em;
$this->paginator = $paginator;
}
/**
* @Route("/videos", name="site_videos")
*/
public function index(Request $request, VideoRepository $VideoRepository,CategorieVideoRepository $CategorieVideoRepository):Response
{
$status=true;
$q=($request->query->get('q'))?$request->query->get('q'):'';
$all= $VideoRepository->findBylist($status,$q);
$paginedData=$this->paginator->paginate($all,$request->query->getInt('page', 1),9);
//dd($all);
return $this->render('site/videos/videos.html.twig', [
'title' => 'Vidéos',
//'videos'=> $VideoRepository->findBylist($status),
'ALL'=> $paginedData,
'categories'=>$CategorieVideoRepository->FindAll(),
]);
}
/**
* @Route("/videos/show/{id}/{cat?}", name="site_videos_show")
*/
public function show(Request $request,VideoRepository $VideoRepository,Video $Video,CategorieVideoRepository $CategorieVideoRepository):Response
{
$cat=$request->attributes->get('cat');
//if ($Video->getPremium()){
if ($this->isGranted('IS_AUTHENTICATED_FULLY')){
$visit = (new VideoVisit())->setUser($this->getUser())
->setVideo($Video)
->setIp($request->getClientIp())
->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$this->em->persist($visit);
$this->em->flush();
}else{
//$request->headers->set('referer','');
return $this->redirectToRoute('app_login');
}
//}
$status=true;
// dd($cat);
return $this->render('site/videos/detailsvideos.html.twig', [
'title' => 'Details Vidéos',
'videos' => $VideoRepository->findBycateg($status,$cat),
'video' => $Video,
//'cat'=>$cat,
'categories'=>$CategorieVideoRepository->FindAll(),
]);
}
/**
* @Route("/videos/categorie/{id}", name="site_videos_cat")
*/
public function VideoCat(Request $request,VideoRepository $VideoRepository,CategorieVideoRepository $CategorieVideoRepository):Response
{
$cat=$request->attributes->get('id');
$status=true;
return $this->render('site/videos/videocat.html.twig', [
'title' => 'Details Vidéos',
'videos' => $VideoRepository->findBycateg($status,$cat),
'cat'=>$cat,
'categories'=>$CategorieVideoRepository->FindAll(),
]);
}
/**
* @Route("/voeux/{id}", name="voeux_show", methods={"GET"})
*/
public function Voeuxshow(Video $video): Response
{
return $this->render('site/videos/voeux.html.twig', [
'video' => $video,
]);
}
}