Browse Source

Bug fix: Correction de la requete sql pour search. Il manqué les parenthéses sur le where des tags.

bastien 13 years ago
parent
commit
8515eb24de
1 changed files with 25 additions and 14 deletions
  1. 25 14
      src/Muzich/CoreBundle/Repository/ElementRepository.php

+ 25 - 14
src/Muzich/CoreBundle/Repository/ElementRepository.php View File

@@ -32,29 +32,18 @@ class ElementRepository extends EntityRepository
32 32
    * @return Doctrine\ORM\Query
33 33
    */
34 34
   public function findBySearch(ElementSearcher $searcher, $user_id)
35
-  {;
35
+  {
36 36
     $params = array();
37 37
     $join_personal = '';
38 38
     //$query_with = '';
39 39
     $where = '';
40
-    
41
-    // Ajout du filtre limitant au réseau personel si c'est le cas
42
-    if ($searcher->getNetwork() == ElementSearcher::NETWORK_PERSONAL)
43
-    {
44
-      $join_personal = "
45
-        LEFT JOIN eu.followers_users f WITH f.follower = :userid "
46
-        ."JOIN g.followers gf WITH gf.follower = :useridg"
47
-        ;
48
-      $params['userid'] = $user_id;
49
-      $params['useridg'] = $user_id;
50
-    }
51
-    
40
+        //die(var_dump($searcher));
52 41
     // ajout du filtres de trie avec les tags transmis
53 42
     foreach ($searcher->getTags() as $tag_id)
54 43
     {
55 44
       if ($where == '')
56 45
       {
57
-        $where .= 'WHERE t.id = :tid'.$tag_id;
46
+        $where .= 'WHERE (t.id = :tid'.$tag_id;
58 47
       }
59 48
       else
60 49
       {
@@ -63,6 +52,27 @@ class ElementRepository extends EntityRepository
63 52
       $params['tid'.$tag_id] = $tag_id;
64 53
     }
65 54
     
55
+    if (count($searcher->getTags()))
56
+    {
57
+      // Si on ne met pas les parenthéses, lorsqu'il y a d'autre where (AND, OR)
58
+      // On perd la précision et des résultats se retrouvent dans le tas
59
+      $where .= ')';
60
+    }
61
+    
62
+    // Ajout du filtre limitant au réseau personel si c'est le cas
63
+    $where_network = '';
64
+    if ($searcher->getNetwork() == ElementSearcher::NETWORK_PERSONAL)
65
+    {  
66
+      $join_personal = 
67
+       " LEFT JOIN eu.followers_users f"
68
+      ." LEFT JOIN g.followers gf"
69
+      ;
70
+      $where_network = ($where != '') ? ' AND' : ' WHERE';
71
+      $where_network .= ' (f.follower = :userid OR gf.follower = :useridg)';
72
+      $params['userid'] = $user_id;
73
+      $params['useridg'] = $user_id;
74
+    }
75
+    
66 76
     // ajout du filtre sur un user si c'est le cas
67 77
     $where_user = '';
68 78
     //                                                  Si c'est une recherche 
@@ -118,6 +128,7 @@ class ElementRepository extends EntityRepository
118 128
       $join_favorite
119 129
       JOIN e.owner eu $join_personal
120 130
       $where
131
+      $where_network
121 132
       $where_user
122 133
       $where_group
123 134
       $where_favorite