Browse Source

Fichefilm maintenant publique

François 5 years ago
parent
commit
c209dcfee3

+ 1 - 1
config/packages/security.yaml

@@ -42,7 +42,7 @@ security:
     # Easy way to control access for large sections of your site
     # Note: Only the *first* access control that matches will be used
     access_control:
-        - { path: ^/(login$|register$|motdepasseoublie$|resetpassword/token=|activate/token=|public/) , roles: IS_AUTHENTICATED_ANONYMOUSLY }
+        - { path: ^/(login$|register$|motdepasseoublie$|resetpassword/token=|activate/token=|fichefilm/) , roles: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/admin, roles: ROLE_ADMIN }
         - { path: ^/genre, roles: ROLE_MODERATEUR }
         - { path: ^/, roles: IS_AUTHENTICATED_REMEMBERED }

+ 27 - 37
src/Controller/VideothequeController.php

@@ -6,6 +6,7 @@ use App\Entity\Commentaire;
 use App\Entity\Realisateur;
 use App\Service\UniciteCollections;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
+use Symfony\Component\Security\Core\Security;
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\Routing\Annotation\Route;
@@ -135,35 +136,40 @@ class VideothequeController extends AbstractController
 	/**
      * @Route("/fichefilm/{id}", name="videotheque_voirfilm")
      */
-	public function voirFilmAction(Request $request, \App\Entity\Film $film)
+	public function voirFilmAction(Request $request, \App\Entity\Film $film, Security $security)
     {
         $em = $this->getDoctrine()->getManager();
         $repoComment = $em->getRepository('App:Commentaire');
-        $commentaireUser = $repoComment->findOneBy(array('film'=>$film, 'user'=>$this->getUser()));
-        if (is_null($commentaireUser))
+        if ($security->isGranted('IS_AUTHENTICATED_REMEMBERED'))
         {
-            $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);
+            $commentaireUser = $repoComment->findOneBy(array('film'=>$film, 'user'=>$this->getUser()));
+            if (is_null($commentaireUser))
+            {
+                $commentaireUser = new Commentaire();
+                $commentaireUser->setUser($this->getUser());
+                $commentaireUser->setFilm(($film));
             }
-            $em->flush();
-            $this->addFlash('success', 'Le commentaire a été posté');
-            return $this->redirectToRoute('videotheque_voirfilm', array('id' => $film->getId()));
+            $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();
+                $this->addFlash('success', 'Le commentaire a été posté');
+                return $this->redirectToRoute('videotheque_voirfilm', array('id' => $film->getId()));
 
+            }
+        } 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,
@@ -171,22 +177,6 @@ class VideothequeController extends AbstractController
         ));
     }
 
-    /**
-     * @Route("/public/{id}", name="videotheque_voirfilm_public")
-     */
-	public function voirFilmPublicAction(Request $request, \App\Entity\Film $film)
-    {
-        $em = $this->getDoctrine()->getManager();
-        $repoComment = $em->getRepository('App:Commentaire');
-        $commentaires = $repoComment->findBy(array('film'=>$film));
-
-        return $this->render('videotheque/voirfilm.html.twig', array(
-            'film' => $film,
-            'commentaires'  => $commentaires,
-        ));
-    }
-
-
     /**
      * @Route("/ajax_req_realisateurs", name="videotheque_ajax_realisateurs")
      */

+ 6 - 6
templates/videotheque/voirfilm.html.twig

@@ -144,12 +144,12 @@
                 </div>
                 <div class="card-body">
                     {% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
-                        <p>
-                            <a data-toggle="collapse" role="button" href="#collapseCommentaire" aria-expanded="false" aria-controls="collapseCommentaire">Commenter <i class="fa fa-chevron-down"></i></a>
-                        </p>
-                        <div class="collapse" id="collapseCommentaire">
-                        {{ include('videotheque/form_commentaire.html.twig') }}
-                        </div>
+                            <p>
+                                <a data-toggle="collapse" role="button" href="#collapseCommentaire" aria-expanded="false" aria-controls="collapseCommentaire">Commenter <i class="fa fa-chevron-down"></i></a>
+                            </p>
+                            <div class="collapse" id="collapseCommentaire">
+                            {{ include('videotheque/form_commentaire.html.twig') }}
+                            </div>
                     {% endif %}
                     <div class="list-group">
                         {% for commentaire in commentaires %}