瀏覽代碼

Anomalie #455: autoplay: erreur affichage favoris

Sevajol Bastien 11 年之前
父節點
當前提交
cc4840d93e

+ 7 - 2
src/Muzich/CoreBundle/Controller/ElementController.php 查看文件

@@ -1106,8 +1106,13 @@ class ElementController extends Controller
1106 1106
       $display_comments      = false;
1107 1107
     }
1108 1108
     
1109
-    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
1110
-      ->findOneById($element_id)))
1109
+    // On prépare la récupèration de l'élèment
1110
+    $es = new ElementSearcher();
1111
+    $es->init(array(
1112
+      'ids' => array($element_id)
1113
+    ));
1114
+    
1115
+    if (!($element = $es->getElements($this->getDoctrine(), $this->getUserId(), 'single')))
1111 1116
     {
1112 1117
       throw $this->createNotFoundException('Not found');
1113 1118
     }

+ 20 - 7
src/Muzich/CoreBundle/Entity/Element.php 查看文件

@@ -712,14 +712,27 @@ class Element
712 712
     }
713 713
   }
714 714
   
715
-  /**
716
-   * Retourne le nombre de fois que cet élément a été msi en favoris 
717
-   * 
718
-   * @return int
719
-   */
720
-  public function getCountFavorite()
715
+//  /**
716
+//   * Retourne le nombre de fois que cet élément a été msi en favoris 
717
+//   * 
718
+//   * @return int
719
+//   */
720
+//  public function getCountFavorite()
721
+//  {
722
+//    return count($this->elements_favorites);
723
+//  }
724
+  
725
+  public function hasFavoriteUser($user_id)
721 726
   {
722
-    return count($this->elements_favorites);
727
+    foreach ($this->elements_favorites as $favorite)
728
+    {
729
+      if ($favorite->getUser()->getId() == $user_id)
730
+      {
731
+        return true;
732
+      }
733
+    }
734
+    
735
+    return false;
723 736
   }
724 737
   
725 738
   public function setGroupToId()

+ 3 - 3
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig 查看文件

@@ -239,13 +239,13 @@
239 239
       </li>
240 240
       <li>
241 241
 
242
-      {% if element.getCountFavorite %}
242
+      {% if element.hasFavoriteUser(app.user.id) %}
243 243
         <a class="favorite_link" href="{{ path('favorite_remove', { 'id': element.id, 'token': app.user.personalHash }) }}" >
244
-          <img src="{{ asset('bundles/muzichcore/img/favorite.png') }}" title="{{ 'element.favorite.remove'|trans({}, 'elements') }}" alt="{{ 'element.favorite.remove'|trans({}, 'elements') }}"/>
244
+          <img id="favorite_{{ element.id }}_is" src="{{ asset('bundles/muzichcore/img/favorite.png') }}" title="{{ 'element.favorite.remove'|trans({}, 'elements') }}" alt="{{ 'element.favorite.remove'|trans({}, 'elements') }}"/>
245 245
         </a>
246 246
       {% else %}
247 247
         <a class="favorite_link" href="{{ path('favorite_add', { 'id': element.id, 'token': app.user.personalHash }) }}" >
248
-          <img src="{{ asset('bundles/muzichcore/img/favorite_bw.png') }}" title="{{ 'element.favorite.add'|trans({}, 'elements') }}" alt="{{ 'element.favorite.add'|trans({}, 'elements') }}" />
248
+          <img id="favorite_{{ element.id }}_isnot" src="{{ asset('bundles/muzichcore/img/favorite_bw.png') }}" title="{{ 'element.favorite.add'|trans({}, 'elements') }}" alt="{{ 'element.favorite.add'|trans({}, 'elements') }}" />
249 249
         </a>
250 250
       {% endif %}
251 251
 

+ 4 - 0
src/Muzich/CoreBundle/Searcher/ElementSearcher.php 查看文件

@@ -329,6 +329,10 @@ class ElementSearcher extends Searcher implements SearcherInterface
329 329
         return count($query->getArrayResult());
330 330
       break;
331 331
     
332
+      case 'single':
333
+        return $query->getSingleResult();
334
+      break;
335
+    
332 336
       default :
333 337
         throw new \Exception('Mode de récupération des Elements non supporté.');
334 338
       break;

+ 35 - 0
src/Muzich/CoreBundle/Tests/Controller/FavoriteControllerTest.php 查看文件

@@ -76,6 +76,41 @@ class FavoriteControllerTest extends FunctionalTest
76 76
   }
77 77
   
78 78
   /**
79
+   * Test vérifiant que l'étoile apparait bien lorsque un élement est en favoris
80
+   * Test d'affichage dom en somme
81
+   */
82
+  public function testStarFavorites()
83
+  {
84
+    $this->client = self::createClient();
85
+    $this->connectUser('bux', 'toor');
86
+    
87
+    $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
88
+      ->findOneByUsername('bux')
89
+    ;
90
+    
91
+    // On se rend sur sa page des favoris de bux
92
+    $this->crawler = $this->client->request('GET', $this->generateUrl('favorite_user_list', array('slug' => 'bux')));
93
+           
94
+    $elements = $this->getDoctrine()->getEntityManager()->createQuery("
95
+      SELECT e FROM MuzichCoreBundle:Element e
96
+      LEFT JOIN e.elements_favorites ef
97
+      WHERE ef.user = :uid
98
+    ")->setParameter('uid', $bux->getId())
99
+      ->getResult()
100
+    ;
101
+    
102
+    $this->assertTrue(!is_null($elements));
103
+    
104
+    if (count($elements))
105
+    {
106
+      foreach ($elements as $element)
107
+      {
108
+        $this->exist('img#favorite_'.$element->getId().'_is');
109
+      }
110
+    }
111
+  }
112
+  
113
+  /**
79 114
    * Test d'ajout en favori un element, puis son retrait
80 115
    * Ce test dépend actuellement du fait que l'élément testé se truove sur la 
81 116
    * page du groupe en question