Browse Source

Merge branch 'feature/viewprofile' into unstable

bastien 13 years ago
parent
commit
6d42154d24

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

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
    * Set description
152
    * Set description
133
    *
153
    *
134
    * @param string $description
154
    * @param string $description

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

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 View File

64
       FROM MuzichCoreBundle:Element e 
64
       FROM MuzichCoreBundle:Element e 
65
       LEFT JOIN e.group g JOIN e.type et JOIN e.tags t $query_with 
65
       LEFT JOIN e.group g JOIN e.type et JOIN e.tags t $query_with 
66
         JOIN e.owner eu $join_personal
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
     $query = $this->getEntityManager()
70
     $query = $this->getEntityManager()
76
     return $query;
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 View File

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

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
    * La recherche est effectué sur le username.
80
    * La recherche est effectué sur le username.
80
    * 
81
    * 
81
    * @param type $string
82
    * @param type $string
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 View File

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 View File

2
 
2
 
3
 home:
3
 home:
4
   pattern:  /
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 View File

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 View File

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 View File

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