Browse Source

UserAndGroupSearcher: Inclusion de la récupération des objets dans la requête.

bastien 13 years ago
parent
commit
b907c7c768

+ 30 - 0
src/Muzich/CoreBundle/Searcher/UserAndGroupSearcher.php View File

3
 namespace Muzich\CoreBundle\Searcher;
3
 namespace Muzich\CoreBundle\Searcher;
4
 
4
 
5
 use Symfony\Component\Validator\Constraints as Assert;
5
 use Symfony\Component\Validator\Constraints as Assert;
6
+use Symfony\Bundle\DoctrineBundle\Registry;
6
 
7
 
7
 class UserAndGroupSearcher extends Searcher implements SearcherInterface
8
 class UserAndGroupSearcher extends Searcher implements SearcherInterface
8
 {
9
 {
67
     $this->string = $string;
68
     $this->string = $string;
68
   }
69
   }
69
   
70
   
71
+  /**
72
+   * Retourne les user et groupes correspondant a la recherche
73
+   *
74
+   * @param Registry $doctrine
75
+   * @return array
76
+   */
77
+  public function getResults(Registry $doctrine)
78
+  {
79
+    // On remplace le caratcère '%' au cas ou un malin l'insére.
80
+    $string = str_replace('%', '#', $this->string);
81
+    
82
+    $users = $doctrine
83
+      ->getRepository('MuzichCoreBundle:User')
84
+      ->findByString($string)
85
+      ->execute()
86
+    ;
87
+    
88
+    $groups = $doctrine
89
+      ->getRepository('MuzichCoreBundle:Group')
90
+      ->findByString($string)
91
+      ->execute()
92
+    ;
93
+    
94
+    return array(
95
+      'users'  => $users,
96
+      'groups' => $groups
97
+    );
98
+  }
99
+  
70
 }
100
 }

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

54
       $search_form->bindRequest($request);
54
       $search_form->bindRequest($request);
55
       if ($search_form->isValid())
55
       if ($search_form->isValid())
56
       {
56
       {
57
-        $results = $this->doSearchAction($search);
57
+        $results = $search->getResults($this->getDoctrine());
58
       }
58
       }
59
     }
59
     }
60
     
60
     
72
     }
72
     }
73
   }
73
   }
74
   
74
   
75
-  /**
76
-   * Retourne le résultat de recherche sur les users et groupes.
77
-   * 
78
-   * @param string $search
79
-   * @return array 
80
-   */
81
-  protected function doSearchAction($search)
82
-  {
83
-    $string = str_replace('%', '#', $search->getString());
84
-    
85
-    $users = $this->getDoctrine()
86
-      ->getRepository('MuzichCoreBundle:User')
87
-      ->findByString($string)
88
-      ->execute()
89
-    ;
90
-    
91
-    $groups = $this->getDoctrine()
92
-      ->getRepository('MuzichCoreBundle:Group')
93
-      ->findByString($string)
94
-      ->execute()
95
-    ;
96
-    
97
-    return array(
98
-      'users'  => $users,
99
-      'groups' => $groups
100
-    );
101
-  }
102
-  
103
 }
75
 }