adding custom filtering on personListWidget

This commit is contained in:
2016-10-06 11:46:37 +02:00
parent de4844fb9d
commit 82c7434871
4 changed files with 117 additions and 6 deletions

View File

@@ -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);