Browse Source

Evolution #166: La recherche

bastien 12 years ago
parent
commit
17fecf0dec

+ 1 - 0
src/Muzich/CoreBundle/Controller/SearchController.php View File

306
     {
306
     {
307
       $results = $searcher->getResults($this->getDoctrine());
307
       $results = $searcher->getResults($this->getDoctrine());
308
     }
308
     }
309
+    
309
     return array(
310
     return array(
310
       'form' => $form->createView(),
311
       'form' => $form->createView(),
311
       'results'     => $results
312
       'results'     => $results

+ 11 - 51
src/Muzich/CoreBundle/Searcher/GlobalSearcher.php View File

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
 use Symfony\Bundle\DoctrineBundle\Registry;
7
+use Muzich\CoreBundle\Searcher\UserAndGroupSearcher;
7
 
8
 
8
 /**
9
 /**
9
  * 
10
  * 
20
    * @Assert\MinLength(3)
21
    * @Assert\MinLength(3)
21
    */
22
    */
22
   protected $string;
23
   protected $string;
23
-  
24
-  /**
25
-   * @see SearcherInterface
26
-   * @param array $params 
27
-   */
28
-  public function init($params)
29
-  {
30
-    // Control des parametres transmis.
31
-    $this->checkParams($params, array(
32
-      'string' => "Muzich\CoreBundle\Searcher\GlobalSearch::init():"
33
-        ." \$params: Un string est nécéssaire"
34
-    ));
35
     
24
     
36
-    // Mise a jour des attributs
37
-    $this->setAttributes(array('string', 'min_lenght'), $params);
25
+  public function setString($string)
26
+  {
27
+    $this->string = $string;
38
   }
28
   }
39
   
29
   
40
-  /**
41
-   * @see SearcherInterface
42
-   * @param array $params 
43
-   */
44
-  public function update($params)
30
+  public function getString()
45
   {
31
   {
46
-    // Mise a jour des attributs
47
-    $this->setAttributes(array(
48
-      'string', 'min_length'
49
-    ), $params);
32
+    return $this->string;
50
   }
33
   }
51
   
34
   
52
   /**
35
   /**
57
   public function getParams()
40
   public function getParams()
58
   {
41
   {
59
     return array(
42
     return array(
60
-      'string' => $this->string,
61
-      'min_length' => $this->min_length
43
+      'string' => $this->string
62
     );
44
     );
63
   }
45
   }
64
   
46
   
65
-  public function getString()
66
-  {
67
-    return $this->string;
68
-  }
69
-  
70
-  public function setString($string)
71
-  {
72
-    $this->string = $string;
73
-  }
74
-  
75
   /**
47
   /**
76
    * Retourne les user et groupes correspondant a la recherche
48
    * Retourne les user et groupes correspondant a la recherche
77
    *
49
    *
80
    */
52
    */
81
   public function getResults(Registry $doctrine)
53
   public function getResults(Registry $doctrine)
82
   {
54
   {
55
+    $ug_searcher = new UserAndGroupSearcher();
56
+    $ug_searcher->setString($this->string);
57
+    
83
     
58
     
84
     // instancier objet SearchUser and groups;
59
     // instancier objet SearchUser and groups;
85
     // puis faire recherche sur elements
60
     // puis faire recherche sur elements
87
     // On remplace le caratcère '%' au cas ou un malin l'insére.
62
     // On remplace le caratcère '%' au cas ou un malin l'insére.
88
     $string = str_replace('%', '#', $this->string);
63
     $string = str_replace('%', '#', $this->string);
89
     
64
     
90
-    $users = $doctrine
91
-      ->getRepository('MuzichCoreBundle:User')
92
-      ->findByString($string)
93
-      ->execute()
94
-    ;
95
-    
96
-    $groups = $doctrine
97
-      ->getRepository('MuzichCoreBundle:Group')
98
-      ->findByString($string)
99
-      ->execute()
100
-    ;
101
-    
102
-    return array(
103
-      'users'  => $users,
104
-      'groups' => $groups
105
-    );
65
+    return $ug_searcher->getResults($doctrine);
106
   }
66
   }
107
   
67
   
108
   
68
   

+ 3 - 10
src/Muzich/CoreBundle/Searcher/SearcherInterface.php View File

9
 interface SearcherInterface
9
 interface SearcherInterface
10
 {
10
 {
11
   
11
   
12
-  /**
13
-   * Initialisation de l'objet recherche.
14
-   */
15
-  public function init($params);
16
-  
17
-  /**
18
-   * Mise a jour des composant de la recherche.
19
-   */
20
-  public function update($params);
21
-  
12
+  public function setString($string);
13
+  public function getString();
14
+    
22
   /**
15
   /**
23
    * Récupération des paramètres
16
    * Récupération des paramètres
24
    */
17
    */

+ 6 - 34
src/Muzich/CoreBundle/Searcher/UserAndGroupSearcher.php View File

20
    * @Assert\MinLength(3)
20
    * @Assert\MinLength(3)
21
    */
21
    */
22
   protected $string;
22
   protected $string;
23
-  
24
-  /**
25
-   * @see SearcherInterface
26
-   * @param array $params 
27
-   */
28
-  public function init($params)
29
-  {
30
-    // Control des parametres transmis.
31
-    $this->checkParams($params, array(
32
-      'string' => "Muzich\CoreBundle\Searcher\UserAndGroupSearch::init(): \$params: Un string est nécéssaire"
33
-    ));
34
     
23
     
35
-    // Mise a jour des attributs
36
-    $this->setAttributes(array('string', 'min_lenght'), $params);
24
+  public function setString($string)
25
+  {
26
+    $this->string = $string;
37
   }
27
   }
38
   
28
   
39
-  /**
40
-   * @see SearcherInterface
41
-   * @param array $params 
42
-   */
43
-  public function update($params)
29
+  public function getString()
44
   {
30
   {
45
-    // Mise a jour des attributs
46
-    $this->setAttributes(array(
47
-      'string', 'min_length'
48
-    ), $params);
31
+    return $this->string;
49
   }
32
   }
50
   
33
   
51
   /**
34
   /**
56
   public function getParams()
39
   public function getParams()
57
   {
40
   {
58
     return array(
41
     return array(
59
-      'string' => $this->string,
60
-      'min_length' => $this->min_length
42
+      'string' => $this->string
61
     );
43
     );
62
   }
44
   }
63
   
45
   
64
-  public function getString()
65
-  {
66
-    return $this->string;
67
-  }
68
-  
69
-  public function setString($string)
70
-  {
71
-    $this->string = $string;
72
-  }
73
-  
74
   /**
46
   /**
75
    * Retourne les user et groupes correspondant a la recherche
47
    * Retourne les user et groupes correspondant a la recherche
76
    *
48
    *