|
@@ -13,6 +13,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
use App\Entity\Film;
|
|
|
use App\Form\FilmType;
|
|
|
+use App\Service\CommentaireManager;
|
|
|
use App\Service\FilmManager;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
@@ -124,30 +125,20 @@ class VideothequeController extends AbstractController
|
|
|
|
|
|
* @Route("/fichefilm/{id}", name="videotheque_voirfilm")
|
|
|
*/
|
|
|
- public function voirFilmAction(Request $request, \App\Entity\Film $film, Security $security, EntityManagerInterface $em)
|
|
|
+ public function voirFilmAction(Request $request, \App\Entity\Film $film, CommentaireManager $cm, Security $security, EntityManagerInterface $em)
|
|
|
{
|
|
|
- $repoComment = $em->getRepository('App:Commentaire');
|
|
|
if ($security->isGranted('IS_AUTHENTICATED_REMEMBERED'))
|
|
|
{
|
|
|
- $commentaireUser = $repoComment->findOneBy(array('film'=>$film, 'user'=>$this->getUser()));
|
|
|
+ $commentaireUser = $em->getRepository('App:Commentaire')->findOneBy(array('film'=>$film, 'user'=>$this->getUser()));
|
|
|
if (is_null($commentaireUser))
|
|
|
{
|
|
|
$commentaireUser = new Commentaire();
|
|
|
- $commentaireUser->setUser($this->getUser());
|
|
|
- $commentaireUser->setFilm(($film));
|
|
|
}
|
|
|
$form = $this->createForm('App\Form\CommentaireType', $commentaireUser);
|
|
|
$form->handleRequest($request);
|
|
|
if ($form->isSubmitted() && $form->isValid())
|
|
|
{
|
|
|
- if ($commentaireUser->getContenu() =="" && $commentaireUser->getNote() == 0) {
|
|
|
- if (!is_null($commentaireUser->getId())) {
|
|
|
- $em->remove($commentaireUser);
|
|
|
- }
|
|
|
- } else {
|
|
|
- $em->persist($commentaireUser);
|
|
|
- }
|
|
|
- $em->flush();
|
|
|
+ $cm->delEditAdd($commentaireUser, $film);
|
|
|
$this->addFlash('success', 'Le commentaire a été posté');
|
|
|
return $this->redirectToRoute('videotheque_voirfilm', array('id' => $film->getId()));
|
|
|
|
|
@@ -155,11 +146,9 @@ class VideothequeController extends AbstractController
|
|
|
} else {
|
|
|
$form = $this->createForm('App\Form\CommentaireType', null);
|
|
|
}
|
|
|
- $commentaires = $repoComment->findBy(array('film'=>$film));
|
|
|
|
|
|
return $this->render('videotheque/voirfilm.html.twig', array(
|
|
|
'film' => $film,
|
|
|
- 'commentaires' => $commentaires,
|
|
|
'form' => $form->createView()
|
|
|
));
|
|
|
}
|