Browse Source

Mise en place des liens suivre / ne plus suivre

bastien 13 years ago
parent
commit
7adbe42a50

+ 49 - 0
src/Muzich/CoreBundle/Entity/User.php View File

272
     return $this->getUsername();
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 View File

3
 namespace Muzich\CoreBundle\Repository;
3
 namespace Muzich\CoreBundle\Repository;
4
 
4
 
5
 use Doctrine\ORM\EntityRepository;
5
 use Doctrine\ORM\EntityRepository;
6
+use Doctrine\ORM\Query;
6
 
7
 
7
 class UserRepository extends EntityRepository
8
 class UserRepository extends EntityRepository
8
 {
9
 {
18
   {
19
   {
19
     $select = 'u';
20
     $select = 'u';
20
     $join = '';
21
     $join = '';
22
+    $where = '';
23
+    $parameters = array('uid' => $user_id);
21
     
24
     
22
     if (in_array('followeds_users', $join_list))
25
     if (in_array('followeds_users', $join_list))
23
     {
26
     {
37
       $join   .= ' JOIN u.followed_groups fdg JOIN fdg.group fdg_g';
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
     return $this->getEntityManager()
52
     return $this->getEntityManager()
41
       ->createQuery("
53
       ->createQuery("
42
         SELECT $select FROM MuzichCoreBundle:User u
54
         SELECT $select FROM MuzichCoreBundle:User u
43
         $join
55
         $join
44
         WHERE u.id = :uid
56
         WHERE u.id = :uid
57
+        $where
45
       ")
58
       ")
46
-      ->setParameter('uid', $user_id)
59
+      ->setParameters($parameters)
47
     ;
60
     ;
48
   }
61
   }
49
   
62
   
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 View File

16
   public function showUserAction($slug)
16
   public function showUserAction($slug)
17
   {
17
   {
18
     try {
18
     try {
19
+      
19
       $viewed_user = $this->getDoctrine()
20
       $viewed_user = $this->getDoctrine()
20
         ->getRepository('MuzichCoreBundle:User')
21
         ->getRepository('MuzichCoreBundle:User')
21
         ->findOneBySlug($slug)
22
         ->findOneBySlug($slug)
22
         ->getSingleResult()
23
         ->getSingleResult()
23
       ;
24
       ;
25
+      $user = $this->getUser();
26
+      
24
     } catch (\Doctrine\ORM\NoResultException $e) {
27
     } catch (\Doctrine\ORM\NoResultException $e) {
25
         throw $this->createNotFoundException('Utilisateur introuvable.');
28
         throw $this->createNotFoundException('Utilisateur introuvable.');
26
     }
29
     }
27
     
30
     
28
     return array(
31
     return array(
29
       'viewed_user' => $viewed_user,
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
   public function showGroupAction($slug)
43
   public function showGroupAction($slug)
40
   {
44
   {
41
     try {
45
     try {
46
+      
42
       $group = $this->getDoctrine()
47
       $group = $this->getDoctrine()
43
         ->getRepository('MuzichCoreBundle:Group')
48
         ->getRepository('MuzichCoreBundle:Group')
44
         ->findOneBySlug($slug)
49
         ->findOneBySlug($slug)
45
         ->getSingleResult()
50
         ->getSingleResult()
46
       ;
51
       ;
52
+      $user = $this->getUser();
53
+      
47
     } catch (\Doctrine\ORM\NoResultException $e) {
54
     } catch (\Doctrine\ORM\NoResultException $e) {
48
         throw $this->createNotFoundException('Groupe introuvable.');
55
         throw $this->createNotFoundException('Groupe introuvable.');
49
     }
56
     }
50
     
57
     
51
     return array(
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 View File

3
 {% block title %}{% endblock %}
3
 {% block title %}{% endblock %}
4
 
4
 
5
 {% block content %}
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
   <h2>{{ group.name }}</h2>
17
   <h2>{{ group.name }}</h2>
8
   
18
   

+ 10 - 0
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig View File

4
 
4
 
5
 {% block content %}
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
   <h2>{{ viewed_user.name }}</h2>
17
   <h2>{{ viewed_user.name }}</h2>
8
   
18
   
9
   {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}
19
   {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}

+ 5 - 11
web/bundles/muzichhome/css/home.css View File

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
+}