src/Controller/PlaylistController.php line 153
<?phpnamespace App\Controller;use App\Entity\Video;use App\Entity\Contient;use App\Entity\Playlist;use App\Entity\Category;use App\Form\PlaylistType;use App\Services\DeviceCheck;use App\Services\FileUploader;use App\Repository\VideoRepository;use App\Repository\ContientRepository;use App\Repository\PlaylistRepository;use App\Repository\CategoryRepository;use App\Repository\UserRepository;use App\Repository\NoteRepository;use App\Repository\CommentRepository;use App\Repository\InstructorRepository;use App\Entity\Instructor;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpKernel\Exception\HttpException;use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;#[Route('/playlist')]class PlaylistController extends AbstractController{#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/', name: 'app_playlist_index', methods: ['GET'])]public function index(PlaylistRepository $playlistRepository): Response{return $this->render('playlist/list.html.twig', ['playlists' => $playlistRepository->findAll(),]);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/new', name: 'app_playlist_new', methods: ['GET', 'POST'])]public function new(Request $request, PlaylistRepository $playlistRepository,FileUploader $fileUploader): Response{$playlist = new Playlist();$form = $this->createForm(PlaylistType::class, $playlist);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$imagecname = $fileUploader->up($form->get('image_de_couverture')->getData(),$this->getParameter('image_directory'));$playlist->setImageDeCouverture($imagecname);$playlistRepository->save($playlist, true);return $this->redirectToRoute('app_playlist_index', [], Response::HTTP_SEE_OTHER);}return $this->renderForm('playlist/new.html.twig', ['playlist' => $playlist,'form' => $form,]);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/publish/{id}','app_playlist_publish')]public function publish(Playlist $playlist, PlaylistRepository $playlistRepository):Response{$playlist->setPublish($playlist->isPublish()?false:true);$playlistRepository->save($playlist,true);return $this->redirectToRoute('app_playlist_show',['id' => $playlist->getId()]);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/addvid/{id}','app_playlist_add')]public function addvideo(Playlist $playlist, PlaylistRepository $playlistRepository,VideoRepository $videoRepository):Response{return $this->render('playlist/add_video.html.twig', ['playlist' => $playlist,'video' => $videoRepository->findAll(),]);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/addthisvid/{id}/{video}','app_playlist_add_video')]public function addthisvideo(Playlist $playlist,Video $video, PlaylistRepository $playlistRepository,VideoRepository $videoRepository, ContientRepository $contientRepository):Response{$contient = new Contient();$contient->setVideo($video);$contients = $playlist->getContient();$i = 1;foreach ($contients as $c) {$i++;}$contient->setOrders($i);$contientRepository->save($contient,true);$playlist->addContient($contient);$playlistRepository->save($playlist,true);return $this->render('playlist/add_video.html.twig', ['playlist' => $playlist,'video' => $videoRepository->findAll(),]);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/{id}/category/{category}', name: 'app_playlist_set_category', methods: ['GET'])]public function setCategory(Playlist $playlist, Category $category, PlaylistRepository $playlistRepository): Response{$playlist->setCategory($category);$playlistRepository->save($playlist, true);return $this->redirectToRoute('app_playlist_show', ['id' => $playlist->getId()], Response::HTTP_SEE_OTHER);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/{id}/category-remove', name: 'app_playlist_remove_category', methods: ['GET'])]public function removeCategory(Playlist $playlist, PlaylistRepository $playlistRepository): Response{$playlist->setCategory(null);$playlistRepository->save($playlist, true);return $this->redirectToRoute('app_playlist_show', ['id' => $playlist->getId()], Response::HTTP_SEE_OTHER);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/addinstructor/{id}','app_playlist_add_instructor')]public function addinstructor(Playlist $playlist, PlaylistRepository $playlistRepository, InstructorRepository $instructorRepository):Response{return $this->render('playlist/add_instructor.html.twig', ['playlist' => $playlist,'instructors' => $instructorRepository->findAll(),]);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/addthisinstructor/{id}/{instructor}','app_playlist_add_this_instructor')]public function addthisinstructor(Playlist $playlist, Instructor $instructor, PlaylistRepository $playlistRepository, InstructorRepository $instructorRepository):Response{if (!$playlist->getInstructors()->contains($instructor)) {$playlist->addInstructor($instructor);$playlistRepository->save($playlist, true);}return $this->redirectToRoute('app_playlist_add_instructor', ['id' => $playlist->getId()], Response::HTTP_SEE_OTHER);}#[IsGranted('ROLE_USER',statusCode:'403',message:"don't have access to this ressource")]#[Route('/{id}', name: 'app_playlist_show', methods: ['GET'])]public function show(Playlist $playlist,UserRepository $userRepository,AuthorizationCheckerInterface $authorizationChecker, CategoryRepository $categoryRepository): Response{$user_connected = $this->getUser();$user= $userRepository->findOneBy(['phone' => $user_connected->getUserIdentifier()]);$userPlaylist =$user->getUsersPlayslists();$found = false;foreach ($userPlaylist as $up) {if ($up->getPlaylist() == $playlist) {$found = true;}}if (!$authorizationChecker->isGranted('ROLE_USER_ADMIN')) {if ($found === false) {throw new HttpException('403','not found');}}return $this->render('playlist/show.html.twig', ['playlist' => $playlist,'categories' => $categoryRepository->findAll(),]);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/{id}/edit', name: 'app_playlist_edit', methods: ['GET', 'POST'])]public function edit(Request $request, Playlist $playlist, PlaylistRepository $playlistRepository): Response{$form = $this->createForm(PlaylistType::class, $playlist);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$playlistRepository->save($playlist, true);return $this->redirectToRoute('app_playlist_index', [], Response::HTTP_SEE_OTHER);}return $this->renderForm('playlist/edit.html.twig', ['playlist' => $playlist,'form' => $form,]);}#[IsGranted('ROLE_USER_ADMIN',statusCode:'403',message:"don't have access to this ressource")]#[Route('/{id}', name: 'app_playlist_delete', methods: ['POST'])]public function delete(Request $request, Playlist $playlist, PlaylistRepository $playlistRepository): Response{if ($this->isCsrfTokenValid('delete'.$playlist->getId(), $request->request->get('_token'))) {$playlistRepository->remove($playlist, true);}return $this->redirectToRoute('app_playlist_index', [], Response::HTTP_SEE_OTHER);}#[IsGranted('ROLE_USER',statusCode:'403',message:"don't have access to this ressource")]#[Route('/{id}/load/{video}','load_this_video')]public function load_playlist_video(Playlist $playlist,Video $video,DeviceCheck $deviceCheck,UserRepository $userRepository,AuthorizationCheckerInterface $authorizationChecker,PlaylistRepository $playlistRepository,ContientRepository $contientRepository,NoteRepository $noteRepository,CommentRepository $commentRepository):Response{$user_connected = $this->getUser();$user= $userRepository->findOneBy(['phone' => $user_connected->getUserIdentifier()]);$userVideo =$user->getUserVideos();$found = false;foreach ($userVideo as $uv) {if ($uv->getVideo() == $video) {$found = true;}}if (!$authorizationChecker->isGranted('ROLE_USER_ADMIN')) {if ($found === false) {throw new HttpException('403','not found');}}$device = $deviceCheck->check();$supported =true;if ($device['is_mobile'] && $device['mobile_os'] == 'iOS') {$supported =false;}$next = 0;$order = $playlistRepository->findOrder($playlist->getId(),$video->getId());$next_video = $contientRepository->findOneBynextOrder($playlist->getId(),($order + 1));if ($next_video) {$next = $next_video->getVideo()->getId();}$basic = false;// if(intval($deviceCheck->getBrowser()['version']) < 55){// $basic = true;// }$advanced = $deviceCheck->supportsAdvancedPlayer();$basic = ! $advanced;// Récupérer toutes les notes de l'utilisateur pour cette vidéo$notes = $noteRepository->findAllByUserAndVideo($user, $video);// Récupérer les commentaires de la vidéo$comments = $commentRepository->findByVideo($video);return $this->render('playlist/load_video.html.twig',['playlist' => $playlist,'video' => $video,'supported' => $supported,'next' => $next,'basic' => $basic,'notes' => $notes,'comments' => $comments,'current_user' => $user]);}}