mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
adding custom filtering on personListWidget
This commit is contained in:
@@ -28,6 +28,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* add a widget with person list.
|
||||
@@ -44,6 +45,13 @@ class PersonListWidget implements WidgetInterface
|
||||
*/
|
||||
protected $personRepository;
|
||||
|
||||
/**
|
||||
* The entity manager
|
||||
*
|
||||
* @var EntityManager
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* the authorization helper
|
||||
*
|
||||
@@ -65,13 +73,14 @@ class PersonListWidget implements WidgetInterface
|
||||
|
||||
public function __construct(
|
||||
EntityRepository $personRepostory,
|
||||
EntityManager $em,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
TokenStorage $tokenStorage
|
||||
) {
|
||||
$this->personRepository = $personRepostory;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->tokenStorage = $tokenStorage;
|
||||
|
||||
$this->entityManager = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +103,7 @@ class PersonListWidget implements WidgetInterface
|
||||
$qb->setParameter('centers', $centers);
|
||||
|
||||
|
||||
|
||||
// add the "only active" query
|
||||
if ($config['only_active'] === true) {
|
||||
$qb->join('person.accompanyingPeriods', 'ap');
|
||||
$or = new Expr\Orx();
|
||||
@@ -110,6 +119,23 @@ class PersonListWidget implements WidgetInterface
|
||||
$and->add($or);
|
||||
$qb->setParameter('now', new \DateTime(), Type::DATE);
|
||||
}
|
||||
|
||||
|
||||
if ($config['filtering_class'] !== NULL) {
|
||||
$filteringClass = new $config['filtering_class'];
|
||||
if ( ! $filteringClass instanceof PersonListWidget\PersonFilteringInterface) {
|
||||
throw new \UnexpectedValueException(sprintf("the class %s does not "
|
||||
. "implements %s", $config['filtering_class'],
|
||||
PersonListWidget\PersonFilteringInterface::class));
|
||||
}
|
||||
$ids = $filteringClass->getPersonIds($this->entityManager,
|
||||
$this->getUser());
|
||||
$in = (new Expr())->in('person.id', ':ids');
|
||||
$and->add($in);
|
||||
$qb->setParameter('ids', $ids);
|
||||
}
|
||||
|
||||
// adding the where clause to the query
|
||||
$qb->where($and);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user