Browse Source

Mise ne place d'un récupération personalisé de l'User (pour permettre join flexibles).

bastien 13 years ago
parent
commit
458e20e3a5

+ 1 - 1
src/Muzich/CoreBundle/Entity/FollowGroup.php View File

33
   /**
33
   /**
34
    * Groupe suivis
34
    * Groupe suivis
35
    * 
35
    * 
36
-   * @ORM\ManyToOne(targetEntity="Group", inversedBy="follower")
36
+   * @ORM\ManyToOne(targetEntity="Group", inversedBy="followers")
37
    * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
37
    * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
38
    */
38
    */
39
   protected $group;
39
   protected $group;

+ 2 - 2
src/Muzich/CoreBundle/Entity/FollowUser.php View File

25
   /**
25
   /**
26
    * User suiveur
26
    * User suiveur
27
    * 
27
    * 
28
-   * @ORM\ManyToOne(targetEntity="User", inversedBy="followed")
28
+   * @ORM\ManyToOne(targetEntity="User", inversedBy="followeds_users")
29
    * @ORM\JoinColumn(name="follower_id", referencedColumnName="id")
29
    * @ORM\JoinColumn(name="follower_id", referencedColumnName="id")
30
    */
30
    */
31
   protected $follower;
31
   protected $follower;
33
   /**
33
   /**
34
    * User suivis
34
    * User suivis
35
    * 
35
    * 
36
-   * @ORM\ManyToOne(targetEntity="User", inversedBy="follower")
36
+   * @ORM\ManyToOne(targetEntity="User", inversedBy="followers_users")
37
    * @ORM\JoinColumn(name="followed_id", referencedColumnName="id")
37
    * @ORM\JoinColumn(name="followed_id", referencedColumnName="id")
38
    */
38
    */
39
   protected $followed;
39
   protected $followed;

+ 40 - 0
src/Muzich/CoreBundle/Repository/UserRepository.php View File

8
 {
8
 {
9
   
9
   
10
   /**
10
   /**
11
+   * Retourne une Query construite selon les paramètres fournis.
12
+   * 
13
+   * @param int $user_id
14
+   * @param array $join
15
+   * @return  Doctrine\ORM\Query
16
+   */
17
+  public function findOneById($user_id, $join_list)
18
+  {
19
+    $select = 'u';
20
+    $join = '';
21
+    
22
+    if (in_array('followeds_users', $join_list))
23
+    {
24
+      $select .= ', fdu, fdu_u';
25
+      $join   .= ' JOIN u.followeds_users fdu JOIN fdu.followed fdu_u';
26
+    }
27
+    
28
+    if (in_array('followers_users', $join_list))
29
+    {
30
+      $select .= ', fru, fru_u';
31
+      $join   .= ' JOIN u.followers_users fru JOIN fru.follower fru_u';
32
+    }
33
+    
34
+    if (in_array('followeds_groups', $join_list))
35
+    {
36
+      $select .= ', fdg, fdg_g';
37
+      $join   .= ' JOIN u.followed_groups fdg JOIN fdg.group fdg_g';
38
+    }
39
+    
40
+    return $this->getEntityManager()
41
+      ->createQuery("
42
+        SELECT $select FROM MuzichCoreBundle:User u
43
+        $join
44
+        WHERE u.id = :uid
45
+      ")
46
+      ->setParameter('uid', $user_id)
47
+    ;
48
+  }
49
+  
50
+  /**
11
    * Retourne les tag id préférés de l'user.
51
    * Retourne les tag id préférés de l'user.
12
    * 
52
    * 
13
    * @param int $user_id
53
    * @param int $user_id

+ 13 - 2
src/Muzich/CoreBundle/lib/Controller.php View File

59
   /**
59
   /**
60
    * Retourne l'objet User.
60
    * Retourne l'objet User.
61
    * 
61
    * 
62
+   * @param array $params
62
    * @return User
63
    * @return User
63
    */
64
    */
64
-  protected function getUser()
65
+  protected function getUser($personal_query = false, $params = array())
65
   {
66
   {
66
-    return $this->container->get('security.context')->getToken()->getUser();
67
+    if (!$personal_query)
68
+    {
69
+      return $this->container->get('security.context')->getToken()->getUser();
70
+    }
71
+    else
72
+    {
73
+      return $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
74
+        $this->container->get('security.context')->getToken()->getUser()->getId(),
75
+        array_key_exists('join', $params) ? $params['join'] : array()
76
+      )->getSingleResult();
77
+    }
67
   }
78
   }
68
   
79
   
69
   /**
80
   /**

+ 9 - 1
src/Muzich/MynetworkBundle/Controller/MynetworkController.php View File

15
    */
15
    */
16
   public function indexAction()
16
   public function indexAction()
17
   {
17
   {
18
-    $user = $this->getUser();
18
+    $user = $this->getUser(true, array('join' => array(
19
+      'followeds_users', 'followers_users', 'followeds_groups'
20
+    )));
19
     
21
     
20
     $followeds_users = $user->getFollowedsUsers();
22
     $followeds_users = $user->getFollowedsUsers();
21
     $followeds_groups = $user->getFollowedGroups();
23
     $followeds_groups = $user->getFollowedGroups();
68
     }
70
     }
69
   }
71
   }
70
   
72
   
73
+  /**
74
+   * Retourne le résultat de recherche sur les users et groupes.
75
+   * 
76
+   * @param string $search
77
+   * @return array 
78
+   */
71
   protected function doSearchAction($search)
79
   protected function doSearchAction($search)
72
   {
80
   {
73
     $string = str_replace('%', '#', $search->getString());
81
     $string = str_replace('%', '#', $search->getString());