mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
add search possibility throught all bundles, and remove deps between mainbundle and person bundle.
refs #223
This commit is contained in:
parent
0372ed4959
commit
740301227f
@ -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:
|
||||
|
@ -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' }
|
||||
|
@ -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 <span class="research">%q%</span> 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
|
||||
|
@ -14,10 +14,12 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#}
|
||||
{% extends "ChillMainBundle::layout.html.twig" %}
|
||||
{% block title %}Recherche {{ pattern }}{% endblock %}
|
||||
<h2>{{ 'Person search results'|trans }}</h2>
|
||||
{% if persons|length == 0 %}
|
||||
<p>{{ 'No persons matching search %pattern%'|trans({'%pattern%' : pattern}) }}</p>
|
||||
{% else %}
|
||||
<p>{{ '%total% persons matching the search %pattern%'|trans({'%pattern%': pattern, '%total%' : total}) }}</p>
|
||||
|
||||
{% block content %}
|
||||
<table class="striped rounded">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -53,4 +55,4 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
111
Search/PersonSearch.php
Normal file
111
Search/PersonSearch.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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() ;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user