mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
issue649: adapt existing UserCurrentLocationType to use select2 with AdministrativeLocationFilter
This commit is contained in:
@@ -11,22 +11,26 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
//use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\UserCurrentLocationType;
|
||||
//use Chill\MainBundle\Repository\LocationRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class AdministrativeLocationFilter implements FilterInterface
|
||||
{
|
||||
//private LocationRepository $locationRepository;
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
//LocationRepository $locationRepository,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
) {
|
||||
//$this->locationRepository = $locationRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
@@ -37,17 +41,10 @@ class AdministrativeLocationFilter implements FilterInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->in('acp.administrativeLocation', ':locations');
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('locations', $data['accepted_locations']);
|
||||
$qb
|
||||
->andWhere($clause)
|
||||
->setParameter('locations', $data['accepted_locations']);
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
@@ -57,13 +54,23 @@ class AdministrativeLocationFilter implements FilterInterface
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('accepted_locations', EntityType::class, [
|
||||
'class' => Location::class,
|
||||
'choice_label' => function (Location $l) {
|
||||
return $l->getName() . ' (' . $this->translatableStringHelper->localize($l->getLocationType()->getTitle()) . ')';
|
||||
},
|
||||
|
||||
//$builder->add('accepted_locations', EntityType::class, [
|
||||
// 'class' => Location::class,
|
||||
// 'choices' => $this->locationRepository->findByPublicLocations(),
|
||||
// 'choice_label' => function (Location $l) {
|
||||
// return $l->getName() . ' (' . $this->translatableStringHelper->localize($l->getLocationType()->getTitle()) . ')';
|
||||
// },
|
||||
// 'multiple' => true,
|
||||
// 'expanded' => true,
|
||||
//]);
|
||||
|
||||
$builder->add('accepted_locations', UserCurrentLocationType::class, [
|
||||
'label' => 'Accepted locations',
|
||||
'label_attr' => [
|
||||
//'class' => 'd-none'
|
||||
],
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user