Kaynağa Gözat

bug fix: Suivre: Le code était inadapté pour suivre un groupe.

bastien 12 yıl önce
ebeveyn
işleme
91fa5d7347

+ 17 - 12
src/Muzich/CoreBundle/Controller/CoreController.php Dosyayı Görüntüle

@@ -3,9 +3,10 @@
3 3
 namespace Muzich\CoreBundle\Controller;
4 4
 
5 5
 use Muzich\CoreBundle\lib\Controller;
6
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
6
+//use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7 7
 use Muzich\CoreBundle\Entity\FollowUser;
8
-use Doctrine\ORM\Query;
8
+use Muzich\CoreBundle\Entity\FollowGroup;
9
+//use Doctrine\ORM\Query;
9 10
 
10 11
 class CoreController extends Controller
11 12
 {
@@ -26,7 +27,7 @@ class CoreController extends Controller
26 27
     }
27 28
     
28 29
     $em = $this->getDoctrine()->getEntityManager();
29
-    $FollowUser = $em
30
+    $Follow = $em
30 31
       ->getRepository('MuzichCoreBundle:Follow' . ucfirst($type))
31 32
       ->findOneBy(
32 33
         array(
@@ -36,25 +37,29 @@ class CoreController extends Controller
36 37
       )
37 38
     ;
38 39
     
39
-    if ($FollowUser)
40
+    if ($Follow)
40 41
     {
41 42
       // L'utilisateur suis déjà, on doit détruire l'entité
42
-      $em->remove($FollowUser);
43
+      $em->remove($Follow);
43 44
       $em->flush();
44 45
     }
45 46
     else
46 47
     {
47
-      $followed_user = $em->getRepository('MuzichCoreBundle:User')->find($id);
48
+      $followed = $em->getRepository('MuzichCoreBundle:'.ucfirst($type))->find($id);
48 49
 
49
-      if (!$followed_user) {
50
-          throw $this->createNotFoundException('No user found for id '.$id);
50
+      if (!$followed) {
51
+          throw $this->createNotFoundException('No '.$type.' found for id '.$id);
51 52
       }
52 53
       
53
-      $FollowUser = new FollowUser();
54
-      $FollowUser->setFollowed($followed_user);
55
-      $FollowUser->setFollower($user);
56 54
       
57
-      $em->persist($FollowUser);
55
+      if ($type == 'user') { $Follow = new FollowUser(); }
56
+      else { $Follow = new FollowGroup(); }
57
+      $Follow->setFollower($user);
58
+      if ($type == 'user') { $Follow->setFollowed($followed); }
59
+      else { $Follow->setGroup($followed); }
60
+      
61
+      
62
+      $em->persist($Follow);
58 63
       $em->flush();
59 64
     }
60 65
     

+ 5 - 7
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig Dosyayı Görüntüle

@@ -4,15 +4,13 @@
4 4
 
5 5
 {% block content %}
6 6
 
7
-  {% if following %}
8
-    <a href="" class="follow_link following" >
7
+  <a href="{{ path('follow', { 'type': 'group', 'id': group.id, 'token': user.personalHash }) }}" class="follow_link following" >
8
+    {% if following %}
9 9
       Ne plus suivre
10
-    </a>
11
-  {% else %}
12
-    <a href="" class="follow_link notfollowing" >
10
+    {% else %}
13 11
       Suivre
14
-    </a>
15
-  {% endif %}
12
+    {% endif %}
13
+  </a>
16 14
     
17 15
   <h2>{{ group.name }}</h2>
18 16