123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
-
- namespace Muzich\CoreBundle\Searcher;
-
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Bundle\DoctrineBundle\Registry;
-
- /**
- *
- */
- class GlobalSearcher extends Searcher implements SearcherInterface
- {
-
- /**
- * Chaine de caractère représentant la recherche.
- *
- * @var string
- * @Assert\NotBlank()
- * @Assert\Type("string")
- * @Assert\MinLength(3)
- */
- protected $string;
-
- /**
- * @see SearcherInterface
- * @param array $params
- */
- public function init($params)
- {
- // Control des parametres transmis.
- $this->checkParams($params, array(
- 'string' => "Muzich\CoreBundle\Searcher\GlobalSearch::init():"
- ." \$params: Un string est nécéssaire"
- ));
-
- // Mise a jour des attributs
- $this->setAttributes(array('string', 'min_lenght'), $params);
- }
-
- /**
- * @see SearcherInterface
- * @param array $params
- */
- public function update($params)
- {
- // Mise a jour des attributs
- $this->setAttributes(array(
- 'string', 'min_length'
- ), $params);
- }
-
- /**
- * @see SearcherInterface
- *
- * @return array
- */
- public function getParams()
- {
- return array(
- 'string' => $this->string,
- 'min_length' => $this->min_length
- );
- }
-
- public function getString()
- {
- return $this->string;
- }
-
- public function setString($string)
- {
- $this->string = $string;
- }
-
- /**
- * Retourne les user et groupes correspondant a la recherche
- *
- * @param Registry $doctrine
- * @return array
- */
- public function getResults(Registry $doctrine)
- {
-
- // instancier objet SearchUser and groups;
- // puis faire recherche sur elements
-
- // On remplace le caratcère '%' au cas ou un malin l'insére.
- $string = str_replace('%', '#', $this->string);
-
- $users = $doctrine
- ->getRepository('MuzichCoreBundle:User')
- ->findByString($string)
- ->execute()
- ;
-
- $groups = $doctrine
- ->getRepository('MuzichCoreBundle:Group')
- ->findByString($string)
- ->execute()
- ;
-
- return array(
- 'users' => $users,
- 'groups' => $groups
- );
- }
-
-
-
-
-
-
-
- }
|