Browse Source

Evolution #144: Info sur profil (et groupe)

bastien 13 years ago
parent
commit
9cfb2b153b

+ 11 - 1
app/Resources/translations/elements.fr.yml View File

@@ -58,4 +58,14 @@ comment:
58 58
 elements:
59 59
   ajax:
60 60
     more:
61
-      noelements:       Pas d'autres éléments
61
+      noelements:       Pas d'autres éléments
62
+      
63
+show:
64
+  user:
65
+    followers:
66
+      zero_count:       Personne ne suit %name%
67
+      one_count:        %count% personne suit %name%
68
+      x_count:          %count% personnes suivent %name%
69
+    elements:
70
+      no_count:         Aucun partage
71
+      count:            %count_owned% partages (dont %count_favorited% mis en favoris par %count_favorited_users% utilisateurs)

+ 34 - 0
src/Muzich/CoreBundle/Repository/GroupRepository.php View File

@@ -91,6 +91,40 @@ class GroupRepository extends EntityRepository
91 91
       ->getResult()
92 92
     ;
93 93
   }
94
+ 
95
+  public function getElementIdsOwned($group_id)
96
+  {
97
+    $ids = array();
98
+    foreach ($this->getEntityManager()
99
+      ->createQuery('SELECT e.id FROM MuzichCoreBundle:Element e
100
+        WHERE e.group = :gid')
101
+      ->setParameter('gid', $group_id)
102
+      ->getScalarResult() as $row)
103
+    {
104
+      $ids[] = $row['id'];
105
+    }
106
+    return $ids;
107
+  }
108
+  
109
+  public function countFollowers($group_id)
110
+  {
111
+    $data = $this->getEntityManager()
112
+      ->createQuery('SELECT COUNT(f) FROM MuzichCoreBundle:FollowGroup f
113
+        WHERE f.group = :gid')
114
+      ->setParameter('gid', $group_id)
115
+      ->getScalarResult()
116
+    ;
117
+    
118
+    if (count($data))
119
+    {
120
+      if (count($data[0]))
121
+      {
122
+        return $data[0][1];
123
+      }
124
+    }
125
+    
126
+    return 0;
127
+  }
94 128
   
95 129
 }
96 130
   

+ 35 - 2
src/Muzich/CoreBundle/Repository/UserRepository.php View File

@@ -200,6 +200,39 @@ class UserRepository extends EntityRepository
200 200
       ->getResult()
201 201
     ;
202 202
   }
203
+ 
204
+  public function getElementIdsOwned($user_id)
205
+  {
206
+    $ids = array();
207
+    foreach ($this->getEntityManager()
208
+      ->createQuery('SELECT e.id FROM MuzichCoreBundle:Element e
209
+        WHERE e.owner = :uid')
210
+      ->setParameter('uid', $user_id)
211
+      ->getScalarResult() as $row)
212
+    {
213
+      $ids[] = $row['id'];
214
+    }
215
+    return $ids;
216
+  }
217
+  
218
+  public function countFollowers($user_id)
219
+  {
220
+    $data = $this->getEntityManager()
221
+      ->createQuery('SELECT COUNT(f) FROM MuzichCoreBundle:FollowUser f
222
+        WHERE f.followed = :uid')
223
+      ->setParameter('uid', $user_id)
224
+      ->getScalarResult()
225
+    ;
226
+    
227
+    if (count($data))
228
+    {
229
+      if (count($data[0]))
230
+      {
231
+        return $data[0][1];
232
+      }
233
+    }
234
+    
235
+    return 0;
236
+  }
203 237
   
204
-}
205
-  
238
+}  

+ 56 - 0
src/Muzich/CoreBundle/Repository/UsersElementsFavoritesRepository.php View File

@@ -29,5 +29,61 @@ class UsersElementsFavoritesRepository extends EntityRepository
29 29
     ;
30 30
   }
31 31
   
32
+  public function countFavoritedForUserElements($user_id, $ids)
33
+  {
34
+    if (count($ids))
35
+    {
36
+      if ($user_id)
37
+      {
38
+        return count($this->getEntityManager()
39
+          ->createQuery('SELECT COUNT(f.id) FROM MuzichCoreBundle:UsersElementsFavorites f
40
+            WHERE f.user != :uid AND f.element IN (:eids)
41
+            GROUP BY f.element')
42
+          ->setParameters(array('uid'=> $user_id, 'eids' => $ids))
43
+          ->getScalarResult())
44
+        ;
45
+      }
46
+      else
47
+      {
48
+        return count($this->getEntityManager()
49
+          ->createQuery('SELECT COUNT(f.id) FROM MuzichCoreBundle:UsersElementsFavorites f
50
+            WHERE f.element IN (:eids)
51
+            GROUP BY f.element')
52
+          ->setParameter('eids', $ids)
53
+          ->getScalarResult())
54
+        ;
55
+      }
56
+    }
57
+    return array();
58
+  }
59
+  
60
+  public function countFavoritedUsersForUserElements($user_id, $ids)
61
+  {
62
+    if (count($ids))
63
+    {
64
+      if ($user_id)
65
+      {
66
+        return count($this->getEntityManager()
67
+          ->createQuery('SELECT COUNT(f.id) FROM MuzichCoreBundle:UsersElementsFavorites f
68
+            WHERE f.user != :uid AND f.element IN (:eids)
69
+            GROUP BY f.user')
70
+          ->setParameters(array('uid'=> $user_id, 'eids' => $ids))
71
+          ->getScalarResult())
72
+        ;
73
+      }
74
+      else
75
+      {
76
+        return count($this->getEntityManager()
77
+          ->createQuery('SELECT COUNT(f.id) FROM MuzichCoreBundle:UsersElementsFavorites f
78
+            WHERE f.element IN (:eids)
79
+            GROUP BY f.user')
80
+          ->setParameter('eids', $ids)
81
+          ->getScalarResult())
82
+        ;
83
+      }
84
+    }
85
+    return null;
86
+  }
87
+  
32 88
 }
33 89
   

+ 50 - 10
src/Muzich/HomeBundle/Controller/ShowController.php View File

@@ -36,16 +36,36 @@ class ShowController extends Controller
36 36
       $tags_id[] = $tag->getId();
37 37
     }
38 38
     
39
+    $element_ids_owned = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
40
+      ->getElementIdsOwned($viewed_user->getId())      
41
+    ;
42
+    
43
+    $count_favorited = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
44
+      ->countFavoritedForUserElements($viewed_user->getId(), $element_ids_owned)      
45
+    ;
46
+    
47
+    $count_favorited_users = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
48
+      ->countFavoritedUsersForUserElements($viewed_user->getId(), $element_ids_owned)      
49
+    ;
50
+    
51
+    $count_followers = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
52
+      ->countFollowers($viewed_user->getId())      
53
+    ;
54
+    
39 55
     return array(
40
-      'tags'           => $tags,
41
-      'tags_id_json'   => json_encode($tags_id),
42
-      'viewed_user'    => $viewed_user,
43
-      'elements'       => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
44
-      'following'      => $this->getUser()->isFollowingUserByQuery($this->getDoctrine(), $viewed_user->getId()),
45
-      'user'           => $this->getUser(),
46
-      'more_count'     => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
47
-      'more_route'     => 'show_user_more',
48
-      'topmenu_active' => ($viewed_user->getId() == $this->getUserId()) ? 'myfeeds' : 'public'
56
+      'tags'            => $tags,
57
+      'tags_id_json'    => json_encode($tags_id),
58
+      'viewed_user'     => $viewed_user,
59
+      'elements'        => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
60
+      'following'       => $this->getUser()->isFollowingUserByQuery($this->getDoctrine(), $viewed_user->getId()),
61
+      'user'            => $this->getUser(),
62
+      'more_count'      => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
63
+      'more_route'      => 'show_user_more',
64
+      'topmenu_active'  => ($viewed_user->getId() == $this->getUserId()) ? 'myfeeds' : 'public',
65
+      'count_owned'     => count($element_ids_owned),
66
+      'count_favorited' => $count_favorited,
67
+      'count_favorited_users' => $count_favorited_users,
68
+      'count_followers' => $count_followers
49 69
     );
50 70
   }
51 71
   
@@ -80,6 +100,22 @@ class ShowController extends Controller
80 100
       $tags_id[] = $tag->getId();
81 101
     }
82 102
     
103
+    $element_ids_owned = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
104
+      ->getElementIdsOwned($group->getId())      
105
+    ;
106
+    
107
+    $count_favorited = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
108
+      ->countFavoritedForUserElements(null, $element_ids_owned)      
109
+    ;
110
+    
111
+    $count_favorited_users = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
112
+      ->countFavoritedUsersForUserElements(null, $element_ids_owned)      
113
+    ;
114
+    
115
+    $count_followers = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
116
+      ->countFollowers($group->getId())      
117
+    ;
118
+    
83 119
     return array(
84 120
       'tags'          => $tags,
85 121
       'tags_id_json'  => json_encode($tags_id),
@@ -91,7 +127,11 @@ class ShowController extends Controller
91 127
       'add_form'      => (isset($add_form)) ? $add_form->createView() : null,
92 128
       'add_form_name' => (isset($add_form)) ? 'add' : null,
93 129
       'more_count'    => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
94
-      'more_route'    => 'show_group_more'
130
+      'more_route'    => 'show_group_more',
131
+      'count_owned'     => count($element_ids_owned),
132
+      'count_favorited' => $count_favorited,
133
+      'count_favorited_users' => $count_favorited_users,
134
+      'count_followers' => $count_followers
95 135
     );
96 136
   }
97 137
   

+ 20 - 0
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig View File

@@ -25,6 +25,26 @@
25 25
     
26 26
   <h2>{{ group.name }}</h2>
27 27
   
28
+  <p class="show_info">
29
+    {% if count_owned != 0 %}
30
+    {{ 'show.user.elements.count'|trans({
31
+      '%count_owned%' : count_owned,
32
+      '%count_favorited%': count_favorited,
33
+      '%count_favorited_users%': count_favorited_users
34
+    }, 'elements') }}
35
+    {% else %}
36
+      {{ 'show.user.elements.no_count'|trans({}, 'elements') }}
37
+    {% endif %}
38
+    <br />
39
+    {% if count_followers > 1 %}
40
+      {{ 'show.user.followers.x_count'|trans({'%count%':count_followers, '%name%':group.name }, 'elements') }}
41
+    {% elseif count_followers == 0 %}
42
+      {{ 'show.user.followers.zero_count'|trans({'%name%':group.name }, 'elements') }}
43
+    {% else %}
44
+      {{ 'show.user.followers.one_count'|trans({'%count%':count_followers, '%name%':group.name }, 'elements') }}
45
+    {% endif %}
46
+  </p>
47
+  
28 48
   <p class="group_description">
29 49
     {{ group.description }}
30 50
   </p>

+ 21 - 1
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig View File

@@ -25,7 +25,27 @@
25 25
   
26 26
 
27 27
   <h2>{{ 'user.show.title'|trans({'%name%' : viewed_user.name}, 'users') }}</h2>
28
-
28
+  
29
+  <p class="show_info">
30
+    {% if count_owned != 0 %}
31
+    {{ 'show.user.elements.count'|trans({
32
+      '%count_owned%' : count_owned,
33
+      '%count_favorited%': count_favorited,
34
+      '%count_favorited_users%': count_favorited_users
35
+    }, 'elements') }}
36
+    {% else %}
37
+      {{ 'show.user.elements.no_count'|trans({}, 'elements') }}
38
+    {% endif %}
39
+    <br />
40
+    {% if count_followers > 1 %}
41
+      {{ 'show.user.followers.x_count'|trans({'%count%':count_followers, '%name%':viewed_user.name }, 'elements') }}
42
+    {% elseif count_followers == 0 %}
43
+      {{ 'show.user.followers.zero_count'|trans({'%name%':viewed_user.name }, 'elements') }}
44
+    {% else %}
45
+      {{ 'show.user.followers.one_count'|trans({'%count%':count_followers, '%name%':viewed_user.name }, 'elements') }}
46
+    {% endif %}
47
+  </p>
48
+    
29 49
   {% include "MuzichCoreBundle:Tag:tagsList.show.html.twig" with {
30 50
     'object_id'   : viewed_user.id,
31 51
     'object_type' : 'user'