Procházet zdrojové kódy

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

bastien před 13 roky
rodič
revize
458e20e3a5

+ 1 - 1
src/Muzich/CoreBundle/Entity/FollowGroup.php Zobrazit soubor

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

+ 2 - 2
src/Muzich/CoreBundle/Entity/FollowUser.php Zobrazit soubor

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

+ 40 - 0
src/Muzich/CoreBundle/Repository/UserRepository.php Zobrazit soubor

@@ -8,6 +8,46 @@ class UserRepository extends EntityRepository
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 51
    * Retourne les tag id préférés de l'user.
12 52
    * 
13 53
    * @param int $user_id

+ 13 - 2
src/Muzich/CoreBundle/lib/Controller.php Zobrazit soubor

@@ -59,11 +59,22 @@ class Controller extends BaseController
59 59
   /**
60 60
    * Retourne l'objet User.
61 61
    * 
62
+   * @param array $params
62 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 Zobrazit soubor

@@ -15,7 +15,9 @@ class MynetworkController extends Controller
15 15
    */
16 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 22
     $followeds_users = $user->getFollowedsUsers();
21 23
     $followeds_groups = $user->getFollowedGroups();
@@ -68,6 +70,12 @@ class MynetworkController extends Controller
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 79
   protected function doSearchAction($search)
72 80
   {
73 81
     $string = str_replace('%', '#', $search->getString());