ソースを参照

Merge branch 'feature/viewprofile' into unstable

bastien 13 年 前
コミット
6d42154d24

+ 20 - 0
src/Muzich/CoreBundle/Entity/Group.php ファイルの表示

@@ -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 ファイルの表示

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

+ 49 - 1
src/Muzich/CoreBundle/Repository/ElementRepository.php ファイルの表示

@@ -64,7 +64,7 @@ class ElementRepository extends EntityRepository
64 64
       FROM MuzichCoreBundle:Element e 
65 65
       LEFT JOIN e.group g JOIN e.type et JOIN e.tags t $query_with 
66 66
         JOIN e.owner eu $join_personal
67
-      ORDER BY e.date_added DESC "
67
+      ORDER BY e.created DESC "
68 68
     ;
69 69
     
70 70
     $query = $this->getEntityManager()
@@ -76,4 +76,52 @@ 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, u, g, t FROM MuzichCoreBundle:Element e
92
+        JOIN e.owner u
93
+        JOIN e.group g
94
+        JOIN e.tags t
95
+        WHERE u.id = :uid
96
+        ORDER BY e.created DESC'
97
+      )
98
+      ->setParameter('uid', $user_id)
99
+      ->setMaxResults($limit)
100
+    ;
101
+  }
102
+  
103
+  /**
104
+   * Retourne une requete selectionnant les Elements en fonction du
105
+   * groupe.
106
+   * 
107
+   * @param int $user_id
108
+   * @param int $limit
109
+   * @return type Doctrine\ORM\Query
110
+   */
111
+  public function findByGroup($group_id, $limit)
112
+  {
113
+    return $this->getEntityManager()
114
+      ->createQuery('
115
+        SELECT e, u, g, t FROM MuzichCoreBundle:Element e
116
+        JOIN e.owner u
117
+        JOIN e.group g
118
+        JOIN e.tags t
119
+        WHERE g.id = :gid
120
+        ORDER BY e.created DESC'
121
+      )
122
+      ->setParameter('gid', $group_id)
123
+      ->setMaxResults($limit)
124
+    ;
125
+  }
126
+  
79 127
 }

+ 19 - 0
src/Muzich/CoreBundle/Repository/GroupRepository.php ファイルの表示

@@ -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 ファイルの表示

@@ -75,7 +75,8 @@ class UserRepository extends EntityRepository
75 75
   }
76 76
   
77 77
   /**
78
-   * Retourne un tableau d'user correspondant a un chaine de caractère
78
+   * Retourne la requete selectionnant les user correspondant a une 
79
+   * chaine de caractère
79 80
    * La recherche est effectué sur le username.
80 81
    * 
81 82
    * @param type $string
@@ -96,5 +97,24 @@ class UserRepository extends EntityRepository
96 97
     ;
97 98
   }
98 99
   
100
+  /**
101
+   * Retourne une Query sleectionnant un User par son slug
102
+   * 
103
+   * @param type string 
104
+   * @return Doctrine\ORM\Query
105
+   */
106
+  public function findOneBySlug($slug)
107
+  {
108
+    return $this->getEntityManager()
109
+      ->createQuery("
110
+        SELECT u FROM MuzichCoreBundle:User u
111
+        WHERE u.slug = :str
112
+      ")
113
+      ->setParameters(array(
114
+        'str' => $slug
115
+      ))
116
+    ;
117
+  }
118
+  
99 119
 }
100 120
   

+ 74 - 0
src/Muzich/HomeBundle/Controller/ShowController.php ファイルの表示

@@ -0,0 +1,74 @@
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
+    return array(
29
+      'viewed_user' => $viewed_user,
30
+      'elements' => $this->getShowedEntityElements($viewed_user->getId(), '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
+    return array(
52
+      'group' => $group,
53
+      'elements' => $this->getShowedEntityElements($group->getId(), 'Group')
54
+    );
55
+  }
56
+  
57
+  /**
58
+   *
59
+   * @param Entity $entity
60
+   * @param string $type
61
+   * @return array 
62
+   */
63
+  protected function getShowedEntityElements($entity_id, $type)
64
+  {
65
+    $findBy = 'findBy'.$type;
66
+    return $this->getDoctrine()
67
+      ->getRepository('MuzichCoreBundle:Element')
68
+      ->$findBy($entity_id, 10)
69
+      
70
+      ->execute()
71
+    ;
72
+  }
73
+  
74
+}

+ 9 - 1
src/Muzich/HomeBundle/Resources/config/routing.yml ファイルの表示

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

+ 11 - 0
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig ファイルの表示

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

+ 11 - 0
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig ファイルの表示

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

+ 3 - 3
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/index.html.twig ファイルの表示

@@ -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>