Преглед изворни кода

Ménage drastique des reqûetes sur page principale

François пре 6 година
родитељ
комит
3121b4afd8

+ 2 - 2
src/AppBundle/Controller/VideothequePersonnelleController.php

@@ -52,7 +52,7 @@ class VideothequePersonnelleController extends Controller
             $em->flush();
         }
         /*$resultat = $this->get('serializer')->serialize($film, 'json');*/
-        return new Response('OK');
+        return new JsonResponse('OK');
     }
 
     /**
@@ -71,7 +71,7 @@ class VideothequePersonnelleController extends Controller
             $em->flush();
         }
         /*$resultat = $this->get('serializer')->serialize($film, 'json');*/
-        return new Response('OK');
+        return new JsonResponse('OK');
     }
 
 }

+ 19 - 0
src/AppBundle/Entity/User.php

@@ -2,6 +2,7 @@
 
 namespace AppBundle\Entity;
 
+use AppBundle\AppBundle;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Security\Core\User\AdvancedUserInterface;
@@ -520,4 +521,22 @@ class User implements AdvancedUserInterface
             ) = unserialize($serialized, array('allowed_classes' => false));
     }
 
+    /**
+     * @param \AppBundle\Entity\Film $film
+     * @return boolean
+     */
+    public function wantToSee(Film $film)
+    {
+        return $this->getFilms()->contains($film);
+    }
+
+    /**
+     * @param \AppBundle\Entity\Film $film
+     * @return boolean
+     */
+    public function haveSeen(Film $film)
+    {
+        return $this->getFilmsVus()->contains($film);
+    }
+
 }

+ 2 - 2
src/AppBundle/Resources/views/videotheque/liste.html.twig

@@ -29,7 +29,7 @@
 		{% for film in listeFilms %}
 		<tr>
 			<td>
-                {%  if film.usersWantToView.contains(app.user) %}
+                {%  if app.user.wantToSee(film) %}
 					<a href="#" class="boutonVoir" data-toggle="tooltip" title="Supprimer ce film de votre liste à voir" data-content="{{ film.id }}"><i class="fa fa-star fa-lg"></i></a>
                 {%  else %}
 					<a href="#" class="boutonVoir" data-toggle="tooltip" title="Ajouter ce film à vos liste à voir" data-content="{{ film.id }}"><i class="fa fa-star-o fa-lg"></i></a>
@@ -37,7 +37,7 @@
                 {%  endif %}
 			</td>
 			<td>
-                {%  if film.usersWhoSeen.contains(app.user) %}
+                {%  if app.user.haveSeen(film) %}
 					<a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-secondary">Pas vu</i><i class="badge badge-success">Vu</i></a>
                 {%  else %}
 					<a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-danger">Pas vu</i><i class="badge badge-secondary">Vu</i></a>