Browse Source

Affichage des Elements sur les pages 'show'

bastien 13 years ago
parent
commit
766238b100

+ 45 - 0
src/Muzich/CoreBundle/Repository/ElementRepository.php View File

@@ -76,4 +76,49 @@ class ElementRepository extends EntityRepository
76 76
     return $query;
77 77
   }
78 78
   
79
+  /**
80
+   * Retourne une requete selectionnant les Elements en fonction du
81
+   * propriétaire.
82
+   * 
83
+   * @param int $user_id
84
+   * @param int $limit
85
+   * @return type Doctrine\ORM\Query
86
+   */
87
+  public function findByUser($user_id, $limit)
88
+  {
89
+    return $this->getEntityManager()
90
+      ->createQuery('
91
+        SELECT e FROM MuzichCoreBundle:Element e
92
+        JOIN e.owner u
93
+        WHERE u.id = :uid
94
+        ORDER BY e.id DESC'
95
+      )
96
+      ->setParameter('uid', $user_id)
97
+      ->setMaxResults($limit)
98
+    ;
99
+  }
100
+  
101
+  /**
102
+   * Retourne une requete selectionnant les Elements en fonction du
103
+   * groupe.
104
+   * 
105
+   * @param int $user_id
106
+   * @param int $limit
107
+   * @return type Doctrine\ORM\Query
108
+   */
109
+  public function findByGroup($group_id, $limit)
110
+  {
111
+    return $this->getEntityManager()
112
+      ->createQuery('
113
+        SELECT e FROM MuzichCoreBundle:Element e
114
+        JOIN e.owner u
115
+        JOIN e.group g
116
+        WHERE g.id = :gid
117
+        ORDER BY e.id DESC'
118
+      )
119
+      ->setParameter('gid', $group_id)
120
+      ->setMaxResults($limit)
121
+    ;
122
+  }
123
+  
79 124
 }

+ 17 - 6
src/Muzich/HomeBundle/Controller/ShowController.php View File

@@ -25,9 +25,9 @@ class ShowController extends Controller
25 25
         throw $this->createNotFoundException('Utilisateur introuvable.');
26 26
     }
27 27
     
28
-    
29 28
     return array(
30
-      'viewed_user' => $viewed_user
29
+      'viewed_user' => $viewed_user,
30
+      'elements' => $this->getShowedEntityElements($viewed_user->getId(), 'User')
31 31
     );
32 32
   }
33 33
   
@@ -48,15 +48,26 @@ class ShowController extends Controller
48 48
         throw $this->createNotFoundException('Groupe introuvable.');
49 49
     }
50 50
     
51
-    
52 51
     return array(
53
-      'group' => $group
52
+      'group' => $group,
53
+      'elements' => $this->getShowedEntityElements($group->getId(), 'Group')
54 54
     );
55 55
   }
56 56
   
57
-  protected function getShowedEntityElements()
57
+  /**
58
+   *
59
+   * @param Entity $entity
60
+   * @param string $type
61
+   * @return array 
62
+   */
63
+  protected function getShowedEntityElements($entity_id, $type)
58 64
   {
59
-    
65
+    $findBy = 'findBy'.$type;
66
+    return $this->getDoctrine()
67
+      ->getRepository('MuzichCoreBundle:Element')
68
+      ->$findBy($entity_id, 10)
69
+      ->execute()
70
+    ;
60 71
   }
61 72
   
62 73
 }

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

@@ -5,5 +5,7 @@
5 5
 {% block content %}
6 6
     
7 7
   <b>{{ group.name }}</b>
8
+  
9
+  {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}
8 10
     
9 11
 {% endblock %}

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

@@ -5,5 +5,7 @@
5 5
 {% block content %}
6 6
     
7 7
   <b>{{ viewed_user.name }}</b>
8
+  
9
+  {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}
8 10
     
9 11
 {% endblock %}