mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14:23 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
adbc59ec76
@ -23,6 +23,7 @@ services:
|
|||||||
- "@doctrine.orm.entity_manager"
|
- "@doctrine.orm.entity_manager"
|
||||||
- "@security.token_storage"
|
- "@security.token_storage"
|
||||||
- "@chill.main.security.authorization.helper"
|
- "@chill.main.security.authorization.helper"
|
||||||
|
- "@chill_main.paginator_factory"
|
||||||
calls:
|
calls:
|
||||||
- ['setContainer', ["@service_container"]]
|
- ['setContainer', ["@service_container"]]
|
||||||
tags:
|
tags:
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
<p>{{ '%total% persons matching the search %pattern%'|transchoice( total, {'%pattern%': pattern, '%total%' : total}) }}</p>
|
<p>{{ '%total% persons matching the search %pattern%'|transchoice( total, {'%pattern%': pattern, '%total%' : total}) }}</p>
|
||||||
|
|
||||||
|
<p>{{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + persons|length, '%total%' : total } ) }}</p>
|
||||||
|
|
||||||
{% if persons|length > 0 %}
|
{% if persons|length > 0 %}
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
@ -55,4 +57,25 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_person_new') }}" class="sc-button btn-create">
|
||||||
|
{{ 'Add a person'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% if preview == true and persons|length < total %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ path('chill_main_search', { "name": search_name, "q" : pattern }) }}" class="sc-button">
|
||||||
|
{{ 'See all results'|trans }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if preview == false %}
|
||||||
|
{{ chill_pagination(paginator) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
@ -22,20 +22,21 @@ namespace Chill\PersonBundle\Search;
|
|||||||
use Chill\MainBundle\Search\AbstractSearch;
|
use Chill\MainBundle\Search\AbstractSearch;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Chill\MainBundle\Search\SearchInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||||
use Chill\MainBundle\Search\ParsingException;
|
use Chill\MainBundle\Search\ParsingException;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
|
|
||||||
class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
||||||
{
|
{
|
||||||
use ContainerAwareTrait;
|
use ContainerAwareTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var EntityManagerInterface
|
* @var EntityManagerInterface
|
||||||
*/
|
*/
|
||||||
private $em;
|
private $em;
|
||||||
@ -48,17 +49,29 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var AuthorizationHelper
|
* @var AuthorizationHelper
|
||||||
*/
|
*/
|
||||||
private $helper;
|
private $helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var PaginatorFactory
|
||||||
|
*/
|
||||||
|
protected $paginatorFactory;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em,
|
const NAME = "person_regular";
|
||||||
TokenStorage $tokenStorage, AuthorizationHelper $helper)
|
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
EntityManagerInterface $em,
|
||||||
|
TokenStorage $tokenStorage,
|
||||||
|
AuthorizationHelper $helper,
|
||||||
|
PaginatorFactory $paginatorFactory)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->user = $tokenStorage->getToken()->getUser();
|
$this->user = $tokenStorage->getToken()->getUser();
|
||||||
$this->helper = $helper;
|
$this->helper = $helper;
|
||||||
|
$this->paginatorFactory = $paginatorFactory;
|
||||||
|
|
||||||
// throw an error if user is not a valid user
|
// throw an error if user is not a valid user
|
||||||
if (!$this->user instanceof \Chill\MainBundle\Entity\User) {
|
if (!$this->user instanceof \Chill\MainBundle\Entity\User) {
|
||||||
@ -96,18 +109,24 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
|||||||
*/
|
*/
|
||||||
public function renderResult(array $terms, $start = 0, $limit = 50, array $options = array())
|
public function renderResult(array $terms, $start = 0, $limit = 50, array $options = array())
|
||||||
{
|
{
|
||||||
|
$total = $this->count($terms);
|
||||||
|
$paginator = $this->paginatorFactory->create($total);
|
||||||
|
|
||||||
return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig',
|
return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig',
|
||||||
array(
|
array(
|
||||||
'persons' => $this->search($terms, $start, $limit, $options),
|
'persons' => $this->search($terms, $start, $limit, $options),
|
||||||
'pattern' => $this->recomposePattern($terms, array('nationality',
|
'pattern' => $this->recomposePattern($terms, array('nationality',
|
||||||
'firstname', 'lastname', 'birthdate', 'gender'), $terms['_domain']),
|
'firstname', 'lastname', 'birthdate', 'gender'), $terms['_domain']),
|
||||||
'total' => $this->count($terms)
|
'total' => $total,
|
||||||
|
'start' => $start,
|
||||||
|
'search_name' => self::NAME,
|
||||||
|
'preview' => $options[SearchInterface::SEARCH_PREVIEW_OPTION],
|
||||||
|
'paginator' => $paginator
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $pattern
|
* @param string $pattern
|
||||||
* @param int $start
|
* @param int $start
|
||||||
* @param int $limit
|
* @param int $limit
|
||||||
@ -143,11 +162,11 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
|||||||
private $_cacheQuery = array();
|
private $_cacheQuery = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param array $terms
|
* @param array $terms
|
||||||
* @return \Doctrine\ORM\QueryBuilder
|
* @return \Doctrine\ORM\QueryBuilder
|
||||||
*/
|
*/
|
||||||
protected function createQuery(array $terms)
|
protected function createQuery(array $terms)
|
||||||
{
|
{
|
||||||
//get from cache
|
//get from cache
|
||||||
$cacheKey = md5(serialize($terms));
|
$cacheKey = md5(serialize($terms));
|
||||||
@ -219,7 +238,7 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
//restraint center for security
|
//restraint center for security
|
||||||
$reachableCenters = $this->helper->getReachableCenters($this->user,
|
$reachableCenters = $this->helper->getReachableCenters($this->user,
|
||||||
new Role('CHILL_PERSON_SEE'));
|
new Role('CHILL_PERSON_SEE'));
|
||||||
$qb->andWhere($qb->expr()
|
$qb->andWhere($qb->expr()
|
||||||
->in('p.center', ':centers'))
|
->in('p.center', ':centers'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user