|
@@ -4,6 +4,7 @@ namespace Muzich\CoreBundle\Searcher;
|
4
|
4
|
|
5
|
5
|
use Symfony\Component\Validator\Constraints as Assert;
|
6
|
6
|
use Symfony\Bundle\DoctrineBundle\Registry;
|
|
7
|
+use Muzich\CoreBundle\Searcher\UserAndGroupSearcher;
|
7
|
8
|
|
8
|
9
|
/**
|
9
|
10
|
*
|
|
@@ -20,33 +21,15 @@ class GlobalSearcher extends Searcher implements SearcherInterface
|
20
|
21
|
* @Assert\MinLength(3)
|
21
|
22
|
*/
|
22
|
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,21 +40,10 @@ class GlobalSearcher extends Searcher implements SearcherInterface
|
57
|
40
|
public function getParams()
|
58
|
41
|
{
|
59
|
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
|
48
|
* Retourne les user et groupes correspondant a la recherche
|
77
|
49
|
*
|
|
@@ -80,6 +52,9 @@ class GlobalSearcher extends Searcher implements SearcherInterface
|
80
|
52
|
*/
|
81
|
53
|
public function getResults(Registry $doctrine)
|
82
|
54
|
{
|
|
55
|
+ $ug_searcher = new UserAndGroupSearcher();
|
|
56
|
+ $ug_searcher->setString($this->string);
|
|
57
|
+
|
83
|
58
|
|
84
|
59
|
// instancier objet SearchUser and groups;
|
85
|
60
|
// puis faire recherche sur elements
|
|
@@ -87,22 +62,7 @@ class GlobalSearcher extends Searcher implements SearcherInterface
|
87
|
62
|
// On remplace le caratcère '%' au cas ou un malin l'insére.
|
88
|
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
|
|