diff --git a/Search/EventSearch.php b/Search/EventSearch.php index c2b4e4e80..882dd2a77 100644 --- a/Search/EventSearch.php +++ b/Search/EventSearch.php @@ -13,6 +13,17 @@ use Symfony\Component\Security\Core\Role\Role; /** * Search within Events. + * + * available terms : + * - name: to search within the name + * - date: search the event at a the given date + * - date-from: search the event after the given date + * - date-to : search the event before the given date + * + * Default terms search within the name, but the term "name" has precedence. This + * means that if the search string is `@event xyz name:"abc"`, the searched + * string will be "abc" and not xyz + * * * @author Julien Fastré * @author Champs Libres @@ -65,7 +76,7 @@ class EventSearch extends AbstractSearch public function isActiveByDefault() { - return false; + return true; } public function getOrder() @@ -136,6 +147,39 @@ class EventSearch extends AbstractSearch $qb->andWhere($orWhere); } + if (isset($terms['name']) OR isset($terms['_default'])) { + // the form with name:"xyz" has precedence + $name = isset($terms['name']) ? $terms['name'] : $terms['_default']; + + $where = $qb->expr()->like('UNACCENT(LOWER(e.name))', ':name'); + $qb->setParameter('name', '%'.$name.'%'); + $qb->andWhere($where); + } + + if (isset($terms['date'])) { + $date = $this->parseDate($terms['date']); + + $where = $qb->expr()->eq('e.date', ':date'); + $qb->setParameter('date', $date); + $qb->andWhere($where); + } + + if (isset($terms['date-from'])) { + $date = $this->parseDate($terms['date-from']); + + $where = $qb->expr()->gte('e.date', ':datefrom'); + $qb->setParameter('datefrom', $date); + $qb->andWhere($where); + } + + if (isset($terms['date-to'])) { + $date = $this->parseDate($terms['date-to']); + + $where = $qb->expr()->lte('e.date', ':dateto'); + $qb->setParameter('dateto', $date); + $qb->andWhere($where); + } + return $qb;