redirectToRoute('videotheque_liste'); } /** * @Route("/liste", name="videotheque_liste") */ public function listeAction() { $em = $this->getDoctrine()->getManager(); $repo = $em->getRepository('AppBundle:Film'); $listeFilms = $repo->findAll(); return $this->render('@App/videotheque/liste.html.twig', array( 'listeFilms' => $listeFilms )); } /** * @Route("/liste-by/{id}", name="videotheque_listepargenre") */ public function listeParGenreAction(\AppBundle\Entity\Genre $genre) { $em = $this->getDoctrine()->getManager(); $films = $em->getRepository('AppBundle:Film')->findFilmWithGenre(array($genre->getName())); return $this->render('@App/videotheque/liste.html.twig', array( 'listeFilms' => $films, 'titre' => 'Films par catégorie : '.$genre->getName() )); } /** * @Route("/liste-by_real/{id}", name="videotheque_listeparreal") */ public function listeParRealisateurAction(Realisateur $realisateur) { $em = $this->getDoctrine()->getManager(); $films = $em->getRepository('AppBundle:Film')->findFilmWithReal(array($realisateur->getNomComplet())); return $this->render('@App/videotheque/liste.html.twig', array( 'listeFilms' => $films, 'titre' => 'Films par réalisateur : '.$realisateur->getNomComplet() )); } /** * @Route("/ajouter", name="videotheque_ajouter") */ public function ajouterAction(Request $request) { $film = new Film; $film->setAuthered($this->getUser()); $form = $this->createForm(FilmType::class, $film); $em = $this->getDoctrine()->getManager(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $uniciteCollections = $this->get('film.unicite_collections'); $film = $uniciteCollections->assureUniciteCollections($film); $em->persist($film); $em->flush(); $this->addFlash('success', 'Le film a été ajouté'); return $this->redirectToRoute('videotheque_voirfilm', array('id'=>$film->getId())); } return $this->render('@App/videotheque/ajouter.html.twig', array( 'form' => $form->createView(), )); } /** * @Route("/modifier/{id}", name="videotheque_modifier") */ public function modifierAction(Request $request, Film $film) { $form = $this->createForm(FilmType::class, $film); $form->handleRequest($request); $em = $this->getDoctrine()->getManager(); if ($form->isSubmitted() && $form->isValid()) { $uniciteCollections = $this->get('film.unicite_collections'); $film = $uniciteCollections->assureUniciteCollections($film); $em->flush(); $this->addFlash('success', 'Le film a été modifié'); return $this->redirectToRoute('videotheque_voirfilm',array('id'=>$film->getId())); } return $this->render('@App/videotheque/modifier.html.twig', array( 'form' => $form->createView(), )); } /** * @Route("/supprimer/{id}", name="videotheque_supprimer") * @Security("has_role('ROLE_ADMIN')") */ public function supprimerAction(Request $request, Film $film) { $form = $this->get('form.factory')->create(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $commentaire = $em->getRepository('AppBundle:Commentaire')->findOneBy(array('film'=>$film)); if ($commentaire != null) { $em->remove($commentaire); } $em->remove($film); $em->flush(); $this->addFlash('success', 'Le film '.$film->getTitre().' a bien été supprimé.'); return $this->redirectToRoute('videotheque_liste'); } return $this->render('@App/videotheque/supprimer.html.twig', array( 'film' => $film, 'form' => $form->createView() )); } /** * @Route("/fichefilm/{id}", name="videotheque_voirfilm") */ public function voirFilmAction(Request $request, \AppBundle\Entity\Film $film) { $em = $this->getDoctrine()->getManager(); $repoComment = $em->getRepository('AppBundle:Commentaire'); $commentaireUser = $repoComment->findOneBy(array('film'=>$film, 'user'=>$this->getUser())); if (is_null($commentaireUser)) { $commentaireUser = new Commentaire(); $commentaireUser->setUser($this->getUser()); $commentaireUser->setFilm(($film)); } $form = $this->createForm('AppBundle\Form\CommentaireType', $commentaireUser); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $commentaireUser = $form->getData(); $em->persist($commentaireUser); $em->flush(); $this->addFlash('success', 'Le commentaire a été posté'); } $commentaires = $repoComment->findBy(array('film'=>$film)); return $this->render('@App/videotheque/voirfilm.html.twig', array( 'film' => $film, 'commentaires' => $commentaires, 'form' => $form->createView() )); } /** * @Route("/ajax_req_realisateurs", name="videotheque_ajax_realisateurs") */ public function ajaxRealisateurs(Request $request) { $realisateurs = $this ->getDoctrine() ->getManager() ->getRepository('AppBundle:Realisateur') ->findNomsComplets(); $liste = array(); foreach ($realisateurs as $key=>$nom) { $liste[$key] = $this->get('serializer')->serialize($nom, 'json'); } return new JsonResponse($liste); } /** * @Route("/ajax_req_genres", name="videotheque_ajax_genres") */ public function ajaxGenres(Request $request) { $genres = $this ->getDoctrine() ->getManager() ->getRepository('AppBundle:Genre') ->findGenres(); $liste = array(); foreach ($genres as $key=>$nom) { $liste[$key] = $this->get('serializer')->serialize($nom, 'json'); } return new JsonResponse($liste); } }