Răsfoiți Sursa

Badges vu, pas vus

François 6 ani în urmă
părinte
comite
e3dfca2835

+ 20 - 1
src/AppBundle/Controller/VideothequePersonnelleController.php

@@ -37,7 +37,7 @@ class VideothequePersonnelleController extends Controller
     }*/
 
     /**
-     * @Route("/maliste/ajouter/", name="maliste_modifier")
+     * @Route("/maliste/modifieravoir/", name="maliste_modifier_a_voir")
      * @param Request $request
      * @return JsonResponse
      */
@@ -55,4 +55,23 @@ class VideothequePersonnelleController extends Controller
         return new Response('OK');
     }
 
+    /**
+     * @Route("/maliste/modifiervus/", name="maliste_modifier_vus")
+     * @param Request $request
+     * @return JsonResponse
+     */
+    public function modifierFilmVusAction(Request $request)
+    {
+        $em = $this->getDoctrine()->getManager();
+        $repo = $em->getRepository('AppBundle:Film');
+        $film = $repo->find($request->request->get('id_film'));
+        if ($request->isXmlHttpRequest())
+        {
+            $film->inverseUserWhoSeen($this->getUser());
+            $em->flush();
+        }
+        /*$resultat = $this->get('serializer')->serialize($film, 'json');*/
+        return new Response('OK');
+    }
+
 }

+ 60 - 0
src/AppBundle/Entity/Film.php

@@ -49,10 +49,18 @@ class Film
 
     /**
      * @ORM\ManyToMany(targetEntity="AppBundle\Entity\User", inversedBy="films")
+     * @ORM\JoinTable(name="filmsavoir_users")
      * @var \Doctrine\Common\Collections\Collection
      */
     private $usersWantToView;
 
+    /**
+     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\User", inversedBy="filmsVus")
+     * @ORM\JoinTable(name="filmsvus_users")
+     * @var \Doctrine\Common\Collections\Collection
+     */
+    private $usersWhoSeen;
+
     /**
      * @return mixed
      */
@@ -135,6 +143,7 @@ class Film
     {
         $this->realisateurs = new \Doctrine\Common\Collections\ArrayCollection();
         $this->usersWantToView = new \Doctrine\Common\Collections\ArrayCollection();
+        $this->usersWhoSeen = new \Doctrine\Common\Collections\ArrayCollection();
     }
 
     /**
@@ -222,4 +231,55 @@ class Film
 
     }
 
+    /////////////////////////////////////////////////////////////////////
+    /**
+     * Add user
+     *
+     * @param \AppBundle\Entity\User $user
+     *
+     * @return film
+     */
+    public function addUserWhoSeen(\AppBundle\Entity\User $user)
+    {
+        $this->usersWhoSeen[] = $user;
+        $user->addFilmVu($this);
+
+        return $this;
+    }
+
+    /**
+     * Remove user
+     *
+     * @param \AppBundle\Entity\User $user
+     */
+    public function removeUserWhoSeen(\AppBundle\Entity\User $user)
+    {
+        $this->usersWhoSeen->removeElement($user);
+        $user->removeFilmVu($this);
+    }
+
+    /**
+     * Get usersWantToView
+     *
+     * @return \Doctrine\Common\Collections\Collection
+     */
+    public function getUsersWhoSeen()
+    {
+        return $this->usersWhoSeen;
+    }
+
+    /**
+     * Inverse ToSee
+     * @param \AppBundle\Entity\User $user
+     */
+    public function inverseUserWhoSeen(\AppBundle\Entity\User $user)
+    {
+        if ($this->usersWhoSeen->contains($user)) {
+            $this->removeUserWhoSeen($user);
+        } else {
+            $this->addUserWhoSeen($user);
+        }
+
+    }
+
 }

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

@@ -78,6 +78,12 @@ class User implements UserInterface
      */
     private $films;
 
+    /**
+     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Film", mappedBy="usersWhoSeen")
+     * @var \Doctrine\Common\Collections\Collection
+     */
+    private $filmsVus;
+
     /**
      * Get id
      *
@@ -279,4 +285,40 @@ class User implements UserInterface
     {
         return $this->films;
     }
+
+    ///////////////////////////////////////////////////////////////////////////
+    /**
+     * Add film
+     *
+     * @param \AppBundle\Entity\Film $film
+     *
+     * @return User
+     */
+    public function addFilmVu(\AppBundle\Entity\Film $film)
+    {
+        $this->filmsVus[] = $film;
+
+        return $this;
+    }
+
+    /**
+     * Remove film
+     *
+     * @param \AppBundle\Entity\Film $film
+     */
+    public function removeFilmVu(\AppBundle\Entity\Film $film)
+    {
+        $this->filmsVus->removeElement($film);
+    }
+
+    /**
+     * Get films
+     *
+     * @return \Doctrine\Common\Collections\Collection
+     */
+    public function getFilmsVus()
+    {
+        return $this->filmsVus;
+    }
+
 }

+ 7 - 6
src/AppBundle/Resources/public/assets/suivifilms.js

@@ -1,6 +1,5 @@
-
-function ecouterSuivi(chemin) {
-    $('.boutonVoir').each(function() {
+function ecouterSuivi(classBouton, texteUn, iconeEtatUn, texteDeux, iconeEtatDeux, chemin) {
+    $('.'+classBouton).each(function() {
         $(this).click(function() {
             let $icone = $(this).children('i');
             let contenu = $(this).attr('data-content');
@@ -10,10 +9,12 @@ function ecouterSuivi(chemin) {
                 data: 'id_film=' + contenu,
                 success: function (data) {
                     console.log(data);
-                    if ($icone.attr('class') === "fas fa-star") {
-                        $icone.attr('class', "far fa-star");
+                    if ($icone.attr('class') === iconeEtatUn) {
+                        $icone.attr('class', iconeEtatDeux);
+                        $icone.text(texteDeux);
                     } else {
-                        $icone.attr('class', "fas fa-star");
+                        $icone.attr('class', iconeEtatUn);
+                        $icone.text(texteUn);
                     }
                     return;
                 },

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

@@ -34,7 +34,13 @@
 
                 {%  endif %}
 			</td>
-			<td></td>
+			<td>
+                {%  if film.usersWhoSeen.contains(app.user) %}
+					<a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-success">Vu</i></a>
+                {%  else %}
+					<a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-secondary">Pas vu</i></a>
+                {%  endif %}
+			</td>
 			<td>{%  if film.authered is defined %}{{ film.authered.username }}{% endif %}</td>
 			<td><a href="{{ path('videotheque_voirfilm', {'id': film.id}) }}">{{ film.titre }}</a></td>
 			<td>
@@ -60,6 +66,9 @@
 {% block javascripts %}
 	<script src="{{ asset('bundles/app/assets/suivifilms.js') }}"></script>
 	<script>
-        $(document).ready(ecouterSuivi('{{ path('maliste_modifier') }}'));
+        $(document).ready(function() {
+                ecouterSuivi('boutonVoir', '', 'fas fa-star', '', 'far fa-star', '{{ path('maliste_modifier_a_voir') }}');
+                ecouterSuivi('boutonVu'	 , 'Vu', 'badge badge-success' , 'Pas vu', 'badge badge-secondary' , '{{ path('maliste_modifier_vus') }}');
+        });
 	</script>
 {%  endblock %}

+ 29 - 9
src/AppBundle/Resources/views/videotheque/voirfilm.html.twig

@@ -8,6 +8,11 @@
         <a href="#" class="boutonVoir" data-content="{{ film.id }}"><i class="far fa-star"></i></a>
     {%  endif %}
     {{ film.titre }}
+    {% if film.usersWhoSeen.contains(app.user) %}
+        <a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-success">Vu</i></a>
+    {% else %}
+        <a href="#" class="boutonVu" data-content="{{ film.id }}"><i class="badge badge-secondary">Pas vu</i></a>
+    {% endif %}
 {% endblock %}
 
 {%  block body %}
@@ -21,7 +26,7 @@
                                 <p><strong>Réalisateur(s)</strong></p>
                                 <ul class="list-group">
                                 {% for realisateur in film.realisateurs %}
-                                    <li class="list-group-item">{{ realisateur.nomComplet }}</li>
+                                    <li class="list-group-item">{{ realisateur.nomComplet }} <small><a href="{{ path('realisateur_modifier', {'id': realisateur.id}) }}">Modifier nom</a></small></li>
                                 {% endfor %}
                                 </ul>
                             </div>
@@ -32,12 +37,24 @@
                     </div>
                 </div>
             </div>
-            <p><strong>Suivi par</strong></p>
-            <ul>
-                {% for user in film.usersWantToView %}
-                    <li>{{ user.username }}</li>
-                {% endfor %}
-            </ul>
+            <div class="row">
+                <div class="col">
+                    <p><strong>Suivi par</strong></p>
+                    <ul>
+                        {% for user in film.usersWantToView %}
+                            <li>{{ user.username }}</li>
+                        {% endfor %}
+                    </ul>
+                </div>
+                <div class="col">
+                    <p><strong>Vu par</strong></p>
+                    <ul>
+                        {% for user in film.usersWhoSeen %}
+                            <li>{{ user.username }}</li>
+                        {% endfor %}
+                    </ul>
+                </div>
+            </div>
             <h3>Votre commentaire</h3>
             {{ include('@App/videotheque/form_commentaire.html.twig') }}
         </div>
@@ -57,6 +74,9 @@
 {% block javascripts %}
     <script src="{{ asset('bundles/app/assets/suivifilms.js') }}"></script>
     <script>
-        $(document).ready(ecouterSuivi('{{ path('maliste_modifier') }}'));
+        $(document).ready(function() {
+            ecouterSuivi('boutonVoir', '', 'fas fa-star', '', 'far fa-star', '{{ path('maliste_modifier_a_voir') }}');
+            ecouterSuivi('boutonVu'	 , 'Vu', 'badge badge-success' , 'Pas vu', 'badge badge-secondary' , '{{ path('maliste_modifier_vus') }}');
+        });
     </script>
-{% endblock %}
+{%  endblock %}