From 740301227f0f246e7c5345a69acd0998cafcc80f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 25 Nov 2014 14:50:05 +0100 Subject: [PATCH 1/3] add search possibility throught all bundles, and remove deps between mainbundle and person bundle. refs #223 --- Resources/config/routing.yml | 2 +- Resources/config/services.yml | 9 ++ Resources/translations/messages.fr.yml | 7 +- Resources/views/Person/list.html.twig | 12 +-- Search/PersonSearch.php | 111 +++++++++++++++++++++++++ 5 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 Search/PersonSearch.php diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 9459c2061..b51211203 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -37,7 +37,7 @@ chill_person_create: defaults: {_controller: ChillPersonBundle:Person:create } chill_person_search: - pattern: /{_locale}/search + pattern: /{_locale}/person/search defaults: { _controller: ChillPersonBundle:Person:search } options: menus: diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 7130fde11..d52e89cc2 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -14,3 +14,12 @@ services: - "@request" tags: - { name: form.type, alias: closing_motive } + + chill.person.search_person: + class: Chill\PersonBundle\Search\PersonSearch + arguments: + - "@doctrine.orm.entity_manager" + calls: + - ['setContainer', ["@service_container"]] + tags: + - { name: chill.search, alias: 'person_search' } diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 1f11493d4..c101b8e85 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -67,12 +67,15 @@ 'Person Menu': "Menu personne" #Person Controller -'Your query is empty. Be more explicive': Votre requête est vide. Veuillez introduire un terme de recherche -'Your query %q% gives no results': La requête %q% ne renvoie aucun résultat. 'The person data are not valid': Les données de votre formulaire sont invalides. '%nb% person with similar name. Please verify that this is a new person': %nb% personnes ont un nom similaire. Vérifiez qu'il ne s'agit pas de l'une d'elles. 'The person has been created': Le dossier a été créé +#search +'Person search results': Recherche de personnes +'No persons matching search %pattern%': Aucune personne ne correpond à votre recherche "%pattern%". +'%total% persons matching the search %pattern%': %total% personnes correspondent aux termes de recherche "%pattern%". + #History 'Last opening since %last_opening%': Dernière ouverture le %last_opening%. 'Close person history': Clotûrer diff --git a/Resources/views/Person/list.html.twig b/Resources/views/Person/list.html.twig index bb59fd69c..c464111ae 100644 --- a/Resources/views/Person/list.html.twig +++ b/Resources/views/Person/list.html.twig @@ -14,10 +14,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . #} -{% extends "ChillMainBundle::layout.html.twig" %} -{% block title %}Recherche {{ pattern }}{% endblock %} - -{% block content %} +

{{ 'Person search results'|trans }}

+{% if persons|length == 0 %} +

{{ 'No persons matching search %pattern%'|trans({'%pattern%' : pattern}) }}

+{% else %} +

{{ '%total% persons matching the search %pattern%'|trans({'%pattern%': pattern, '%total%' : total}) }}

+ @@ -53,4 +55,4 @@ {% endfor %}
-{% endblock %} \ No newline at end of file +{% endif %} diff --git a/Search/PersonSearch.php b/Search/PersonSearch.php new file mode 100644 index 000000000..812fea242 --- /dev/null +++ b/Search/PersonSearch.php @@ -0,0 +1,111 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\PersonBundle\Search; + +use Chill\MainBundle\Search\AbstractSearch; +use Doctrine\Common\Persistence\ObjectManager; +use Chill\PersonBundle\Entity\Person; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\DependencyInjection\ContainerAwareTrait; + +class PersonSearch extends AbstractSearch +{ + use ContainerAwareTrait; + + /** + * + * @var ObjectManager + */ + private $om; + + + public function __construct(ObjectManager $om) + { + $this->om = $om; + } + + /* + * (non-PHPdoc) + * @see \Chill\MainBundle\Search\SearchInterface::getLabel() + */ + public function getLabel() + { + return 'person_default'; + } + + /* + * (non-PHPdoc) + * @see \Chill\MainBundle\Search\SearchInterface::getOrder() + */ + public function getOrder() + { + return 100; + } + + /* + * (non-PHPdoc) + * @see \Chill\MainBundle\Search\SearchInterface::isActiveByDefault() + */ + public function isActiveByDefault() + { + return true; + } + + /* + * (non-PHPdoc) + * @see \Chill\MainBundle\Search\SearchInterface::renderResult() + */ + public function renderResult($pattern, $start = 0, $limit = 50, array $options = array()) + { + + $persons = $this->search($pattern, $start, $limit, $options); + + return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig', + array( + 'persons' => $persons, + 'pattern' => trim($pattern), + 'total' => count($persons) + )); + } + + /** + * + * @param string $pattern + * @param int $start + * @param int $limit + * @param array $options + * @return Person[] + */ + protected function search($pattern, $start, $limit, array $options = array()) + { + $dql = 'SELECT p FROM ChillPersonBundle:Person p' + . ' WHERE' + . ' LOWER(p.firstName) like LOWER(:q)' + . ' OR LOWER(p.lastName) like LOWER(:q)'; + + $query = $this->om->createQuery($dql) + ->setParameter('q', '%'.trim($pattern).'%') + ->setFirstResult($start) + ->setMaxResults($limit); + + return $query->getResult() ; + } +} \ No newline at end of file From d340520581a247ed830483f28c66d5343481b0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 25 Nov 2014 15:20:23 +0100 Subject: [PATCH 2/3] make messages more consistent with the new 'search' feature --- Resources/config/routing.yml | 2 +- Resources/translations/messages.fr.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index b51211203..bc4e467b3 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -43,7 +43,7 @@ chill_person_search: menus: main: order: 30 - label: Chercher une personne + label: Search within persons chill_person_history_list: pattern: /{_locale}/person/{person_id}/history diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index c101b8e85..3f11beeaf 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -73,6 +73,7 @@ #search 'Person search results': Recherche de personnes +'Search within persons': Recherche parmi les personnes 'No persons matching search %pattern%': Aucune personne ne correpond à votre recherche "%pattern%". '%total% persons matching the search %pattern%': %total% personnes correspondent aux termes de recherche "%pattern%". From 6045578bb2f180ca996044cc837fe513cb89f6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 25 Nov 2014 15:34:11 +0100 Subject: [PATCH 3/3] add locale for test environment (temp) refs #331 --- Tests/Fixtures/App/app/config/parameters.travis.yml | 3 ++- Tests/Fixtures/App/app/config/parameters.yml.dist | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/Fixtures/App/app/config/parameters.travis.yml b/Tests/Fixtures/App/app/config/parameters.travis.yml index e4a7826c0..28d5cd26c 100644 --- a/Tests/Fixtures/App/app/config/parameters.travis.yml +++ b/Tests/Fixtures/App/app/config/parameters.travis.yml @@ -3,4 +3,5 @@ parameters: database_port: 5432 database_name: test0 database_user: postgres - database_password: postgres \ No newline at end of file + database_password: postgres + locale: fr \ No newline at end of file diff --git a/Tests/Fixtures/App/app/config/parameters.yml.dist b/Tests/Fixtures/App/app/config/parameters.yml.dist index fa3e55dae..3221c992b 100644 --- a/Tests/Fixtures/App/app/config/parameters.yml.dist +++ b/Tests/Fixtures/App/app/config/parameters.yml.dist @@ -3,4 +3,5 @@ parameters: database_port: 5434 database_name: symfony database_user: symfony - database_password: symfony \ No newline at end of file + database_password: symfony + locale: fr \ No newline at end of file