Browse Source

Ecriture des pages d'affichage d'un user et d'un groupe. + récupération des entités.

bastien 12 years ago
parent
commit
14349f0a45

+ 20 - 0
src/Muzich/CoreBundle/Entity/Group.php View File

@@ -129,6 +129,26 @@ class Group
129 129
   }
130 130
 
131 131
   /**
132
+   * Set slug
133
+   *
134
+   * @param string $slug
135
+   */
136
+  public function setSlug($slug)
137
+  {
138
+    $this->slug = $slug;
139
+  }
140
+
141
+  /**
142
+   * Get slug
143
+   *
144
+   * @return string 
145
+   */
146
+  public function getSlug()
147
+  {
148
+    return $this->slug;
149
+  }
150
+
151
+  /**
132 152
    * Set description
133 153
    *
134 154
    * @param string $description

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

@@ -267,5 +267,9 @@ class User extends BaseUser
267 267
    * 
268 268
    */
269 269
   
270
+  public function getName()
271
+  {
272
+    return $this->getUsername();
273
+  }
270 274
   
271 275
 }

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

@@ -28,5 +28,24 @@ class GroupRepository extends EntityRepository
28 28
     ;
29 29
   }
30 30
   
31
+  /**
32
+   * Retourne une Query sleectionnant un Group par son slug
33
+   * 
34
+   * @param type string 
35
+   * @return Doctrine\ORM\Query
36
+   */
37
+  public function findOneBySlug($slug)
38
+  {
39
+    return $this->getEntityManager()
40
+      ->createQuery("
41
+        SELECT g FROM MuzichCoreBundle:Group g
42
+        WHERE g.slug = :str
43
+      ")
44
+      ->setParameters(array(
45
+        'str' => $slug
46
+      ))
47
+    ;
48
+  }
49
+  
31 50
 }
32 51
   

+ 21 - 1
src/Muzich/CoreBundle/Repository/UserRepository.php View File

@@ -35,7 +35,8 @@ class UserRepository extends EntityRepository
35 35
   }
36 36
   
37 37
   /**
38
-   * Retourne un tableau d'user correspondant a un chaine de caractère
38
+   * Retourne la requete selectionnant les user correspondant a une 
39
+   * chaine de caractère
39 40
    * La recherche est effectué sur le username.
40 41
    * 
41 42
    * @param type $string
@@ -56,5 +57,24 @@ class UserRepository extends EntityRepository
56 57
     ;
57 58
   }
58 59
   
60
+  /**
61
+   * Retourne une Query sleectionnant un User par son slug
62
+   * 
63
+   * @param type string 
64
+   * @return Doctrine\ORM\Query
65
+   */
66
+  public function findOneBySlug($slug)
67
+  {
68
+    return $this->getEntityManager()
69
+      ->createQuery("
70
+        SELECT u FROM MuzichCoreBundle:User u
71
+        WHERE u.slug = :str
72
+      ")
73
+      ->setParameters(array(
74
+        'str' => $slug
75
+      ))
76
+    ;
77
+  }
78
+  
59 79
 }
60 80
   

+ 62 - 0
src/Muzich/HomeBundle/Controller/ShowController.php View File

@@ -0,0 +1,62 @@
1
+<?php
2
+
3
+namespace Muzich\HomeBundle\Controller;
4
+
5
+use Muzich\CoreBundle\lib\Controller;
6
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
+
8
+class ShowController extends Controller
9
+{
10
+  
11
+  /**
12
+   * 
13
+   * 
14
+   * @Template()
15
+   */
16
+  public function showUserAction($slug)
17
+  {
18
+    try {
19
+      $viewed_user = $this->getDoctrine()
20
+        ->getRepository('MuzichCoreBundle:User')
21
+        ->findOneBySlug($slug)
22
+        ->getSingleResult()
23
+      ;
24
+    } catch (\Doctrine\ORM\NoResultException $e) {
25
+        throw $this->createNotFoundException('Utilisateur introuvable.');
26
+    }
27
+    
28
+    
29
+    return array(
30
+      'viewed_user' => $viewed_user
31
+    );
32
+  }
33
+  
34
+  /**
35
+   * 
36
+   * 
37
+   * @Template()
38
+   */
39
+  public function showGroupAction($slug)
40
+  {
41
+    try {
42
+      $group = $this->getDoctrine()
43
+        ->getRepository('MuzichCoreBundle:Group')
44
+        ->findOneBySlug($slug)
45
+        ->getSingleResult()
46
+      ;
47
+    } catch (\Doctrine\ORM\NoResultException $e) {
48
+        throw $this->createNotFoundException('Groupe introuvable.');
49
+    }
50
+    
51
+    
52
+    return array(
53
+      'group' => $group
54
+    );
55
+  }
56
+  
57
+  protected function getShowedEntityElements()
58
+  {
59
+    
60
+  }
61
+  
62
+}

+ 9 - 1
src/Muzich/HomeBundle/Resources/config/routing.yml View File

@@ -2,4 +2,12 @@
2 2
 
3 3
 home:
4 4
   pattern:  /
5
-  defaults: { _controller: MuzichHomeBundle:Home:index }
5
+  defaults: { _controller: MuzichHomeBundle:Home:index }
6
+  
7
+show_user:
8
+  pattern: /user/{slug}
9
+  defaults: { _controller: MuzichHomeBundle:Show:showUser }
10
+  
11
+show_group:
12
+  pattern: /group/{slug}
13
+  defaults: { _controller: MuzichHomeBundle:Show:showGroup }

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

@@ -0,0 +1,9 @@
1
+{% extends "MuzichHomeBundle::layout.html.twig" %}
2
+
3
+{% block title %}{% endblock %}
4
+
5
+{% block content %}
6
+    
7
+  <b>{{ group.name }}</b>
8
+    
9
+{% endblock %}

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

@@ -0,0 +1,9 @@
1
+{% extends "MuzichHomeBundle::layout.html.twig" %}
2
+
3
+{% block title %}{% endblock %}
4
+
5
+{% block content %}
6
+    
7
+  <b>{{ viewed_user.name }}</b>
8
+    
9
+{% endblock %}

+ 3 - 3
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/index.html.twig View File

@@ -15,7 +15,7 @@
15 15
     <ul>
16 16
     {% for user in followeds_users %} 
17 17
       <li>
18
-        {{ user.username }}
18
+        <a href="{{ path('show_user', { 'slug': user.slug }) }}">{{ user.username }}</a>
19 19
       </li>
20 20
     {% endfor %}
21 21
     </ul>
@@ -26,7 +26,7 @@
26 26
     <ul>
27 27
     {% for group in followeds_groups %} 
28 28
       <li>
29
-        {{ group.name }}
29
+        <a href="{{ path('show_group', { 'slug': group.slug }) }}">{{ group.name }}</a>
30 30
       </li>
31 31
     {% endfor %}
32 32
     </ul>
@@ -37,7 +37,7 @@
37 37
     <ul>
38 38
     {% for user in followers_users %} 
39 39
       <li>
40
-        {{ user.username }}
40
+        <a href="{{ path('show_user', { 'slug': user.slug }) }}">{{ user.username }}</a>
41 41
       </li>
42 42
     {% endfor %}
43 43
     </ul>