Bladeren bron

Mise en place des liens suivre / ne plus suivre

bastien 12 jaren geleden
bovenliggende
commit
7adbe42a50

+ 49 - 0
src/Muzich/CoreBundle/Entity/User.php Bestand weergeven

@@ -272,4 +272,53 @@ class User extends BaseUser
272 272
     return $this->getUsername();
273 273
   }
274 274
   
275
+  /**
276
+   * Retourn si l'user_id transmis fait partis des enregistrements
277
+   * followed de l'objet.
278
+   * 
279
+   * @param int $user_id 
280
+   * @return boolean
281
+   */
282
+  public function isFollowingUser($user_id)
283
+  {
284
+    foreach ($this->followeds_users as $followed_user)
285
+    {
286
+      if ($followed_user->getFollowed()->getId() == $user_id)
287
+      {
288
+        return true;
289
+      }
290
+    }
291
+    return false;
292
+  }
293
+  
294
+  /**
295
+   * Retourn si l'user_id transmis est l'un des User suivis
296
+   * 
297
+   * @param Symfony\Bundle\DoctrineBundle\Registry doctrine
298
+   * @param int $user_id 
299
+   * @return boolean
300
+   */
301
+  public function isFollowingUserByQuery($doctrine, $user_id)
302
+  {
303
+    return $doctrine
304
+      ->getRepository('MuzichCoreBundle:User')
305
+      ->isFollowingUser($this->getId(), $user_id)
306
+    ;
307
+  }
308
+  
309
+  /**
310
+   * Retourn si l'group_id transmis est l'un des groupe suivis
311
+   * 
312
+   * @param Symfony\Bundle\DoctrineBundle\Registry doctrine
313
+   * @param int $user_id 
314
+   * @return boolean
315
+   */
316
+  public function isFollowingGroupByQuery($doctrine, $group_id)
317
+  {
318
+    return $doctrine
319
+      ->getRepository('MuzichCoreBundle:User')
320
+      ->isFollowingGroup($this->getId(), $group_id)
321
+    ;
322
+  }
323
+  
275 324
 }

+ 48 - 1
src/Muzich/CoreBundle/Repository/UserRepository.php Bestand weergeven

@@ -3,6 +3,7 @@
3 3
 namespace Muzich\CoreBundle\Repository;
4 4
 
5 5
 use Doctrine\ORM\EntityRepository;
6
+use Doctrine\ORM\Query;
6 7
 
7 8
 class UserRepository extends EntityRepository
8 9
 {
@@ -18,6 +19,8 @@ class UserRepository extends EntityRepository
18 19
   {
19 20
     $select = 'u';
20 21
     $join = '';
22
+    $where = '';
23
+    $parameters = array('uid' => $user_id);
21 24
     
22 25
     if (in_array('followeds_users', $join_list))
23 26
     {
@@ -37,13 +40,23 @@ class UserRepository extends EntityRepository
37 40
       $join   .= ' JOIN u.followed_groups fdg JOIN fdg.group fdg_g';
38 41
     }
39 42
     
43
+//    if (array_key_exists('followed_user_id', $join_list))
44
+//    {
45
+//      $select .= ', fu, fu_u';
46
+//      $join   .= ' LEFT JOIN u.followeds_users fu WITH fu.followed = :fuid LEFT JOIN fu.followed fu_u';
47
+//      $parameters = array_merge($parameters, array(
48
+//        'fuid' => $join_list['followed_user_id']
49
+//      ));
50
+//    }
51
+    
40 52
     return $this->getEntityManager()
41 53
       ->createQuery("
42 54
         SELECT $select FROM MuzichCoreBundle:User u
43 55
         $join
44 56
         WHERE u.id = :uid
57
+        $where
45 58
       ")
46
-      ->setParameter('uid', $user_id)
59
+      ->setParameters($parameters)
47 60
     ;
48 61
   }
49 62
   
@@ -116,5 +129,39 @@ class UserRepository extends EntityRepository
116 129
     ;
117 130
   }
118 131
   
132
+  public function isFollowingUser($follower_id, $followed_id)
133
+  {
134
+    $result = $this->getEntityManager()
135
+      ->createQuery("
136
+        SELECT COUNT(fu.id) FROM MuzichCoreBundle:FollowUser fu
137
+        WHERE fu.follower = :frid AND fu.followed = :fdid
138
+      ")
139
+      ->setParameters(array(
140
+        'frid' => $follower_id,
141
+        'fdid' => $followed_id
142
+      ))
143
+      ->getSingleResult(Query::HYDRATE_ARRAY)
144
+    ;
145
+    
146
+    return $result[1];
147
+  }
148
+  
149
+  public function isFollowingGroup($follower_id, $group_id)
150
+  {
151
+    $result = $this->getEntityManager()
152
+      ->createQuery("
153
+        SELECT COUNT(fg.id) FROM MuzichCoreBundle:FollowGroup fg
154
+        WHERE fg.follower = :frid AND fg.group = :fdgid
155
+      ")
156
+      ->setParameters(array(
157
+        'frid' => $follower_id,
158
+        'fdgid' => $group_id
159
+      ))
160
+      ->getSingleResult(Query::HYDRATE_ARRAY)
161
+    ;
162
+    
163
+    return $result[1];
164
+  }
165
+  
119 166
 }
120 167
   

+ 11 - 3
src/Muzich/HomeBundle/Controller/ShowController.php Bestand weergeven

@@ -16,18 +16,22 @@ class ShowController extends Controller
16 16
   public function showUserAction($slug)
17 17
   {
18 18
     try {
19
+      
19 20
       $viewed_user = $this->getDoctrine()
20 21
         ->getRepository('MuzichCoreBundle:User')
21 22
         ->findOneBySlug($slug)
22 23
         ->getSingleResult()
23 24
       ;
25
+      $user = $this->getUser();
26
+      
24 27
     } catch (\Doctrine\ORM\NoResultException $e) {
25 28
         throw $this->createNotFoundException('Utilisateur introuvable.');
26 29
     }
27 30
     
28 31
     return array(
29 32
       'viewed_user' => $viewed_user,
30
-      'elements' => $this->getShowedEntityElements($viewed_user->getId(), 'User')
33
+      'elements'    => $this->getShowedEntityElements($viewed_user->getId(), 'User'),
34
+      'following'   => $user->isFollowingUserByQuery($this->getDoctrine(), $viewed_user->getId())
31 35
     );
32 36
   }
33 37
   
@@ -39,18 +43,22 @@ class ShowController extends Controller
39 43
   public function showGroupAction($slug)
40 44
   {
41 45
     try {
46
+      
42 47
       $group = $this->getDoctrine()
43 48
         ->getRepository('MuzichCoreBundle:Group')
44 49
         ->findOneBySlug($slug)
45 50
         ->getSingleResult()
46 51
       ;
52
+      $user = $this->getUser();
53
+      
47 54
     } catch (\Doctrine\ORM\NoResultException $e) {
48 55
         throw $this->createNotFoundException('Groupe introuvable.');
49 56
     }
50 57
     
51 58
     return array(
52
-      'group' => $group,
53
-      'elements' => $this->getShowedEntityElements($group->getId(), 'Group')
59
+      'group'       => $group,
60
+      'elements'    => $this->getShowedEntityElements($group->getId(), 'Group'),
61
+      'following'   => $user->isFollowingGroupByQuery($this->getDoctrine(), $group->getId())
54 62
     );
55 63
   }
56 64
   

+ 10 - 0
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig Bestand weergeven

@@ -3,6 +3,16 @@
3 3
 {% block title %}{% endblock %}
4 4
 
5 5
 {% block content %}
6
+
7
+  {% if following %}
8
+    <a href="" class="follow_link following" >
9
+      Ne plus suivre
10
+    </a>
11
+  {% else %}
12
+    <a href="" class="follow_link notfollowing" >
13
+      Suivre
14
+    </a>
15
+  {% endif %}
6 16
     
7 17
   <h2>{{ group.name }}</h2>
8 18
   

+ 10 - 0
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig Bestand weergeven

@@ -4,6 +4,16 @@
4 4
 
5 5
 {% block content %}
6 6
     
7
+  {% if following %}
8
+    <a href="" class="follow_link following" >
9
+      Ne plus suivre
10
+    </a>
11
+  {% else %}
12
+    <a href="" class="follow_link notfollowing" >
13
+      Suivre
14
+    </a>
15
+  {% endif %}
16
+
7 17
   <h2>{{ viewed_user.name }}</h2>
8 18
   
9 19
   {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}

+ 5 - 11
web/bundles/muzichhome/css/home.css Bestand weergeven

@@ -1,13 +1,7 @@
1
-/* 
2
-    Document   : home
3
-    Created on : 10 sept. 2011, 12:49:23
4
-    Author     : bux
5
-    Description:
6
-        Purpose of the stylesheet follows.
7
-*/
8 1
 
9
-/* 
10
-   TODO customize this sample style
11
-   Syntax recommendation http://www.w3.org/TR/REC-CSS2/
12
-*/
13 2
 
3
+#container .follow_link
4
+{
5
+  float: right;
6
+  text-decoration: none;
7
+}