fixes for reasign list

* use existing method in UserRepository and use a method instead of
building a query outside of the repository;
* use renderString to render users
* fix building of filter form (add $data). This make the use of the
method "get" instead of post
This commit is contained in:
Julien Fastré 2022-03-21 13:35:14 +01:00
parent f084078cf2
commit 293efc03b4
3 changed files with 14 additions and 19 deletions

View File

@ -51,11 +51,6 @@ final class UserRepository implements ObjectRepository
return (int) $qb->getQuery()->getSingleScalarResult();
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
public function find($id, $lockMode = null, $lockVersion = null): ?User
{
return $this->repository->find($id, $lockMode, $lockVersion);

View File

@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -39,9 +40,11 @@ class ReassignAccompanyingPeriodController extends AbstractController
private Security $security;
private UserRender $userRender;
private UserRepository $userRepository;
public function __construct(AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security)
public function __construct(AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security, UserRender $userRender)
{
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
$this->engine = $engine;
@ -49,6 +52,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
$this->paginatorFactory = $paginatorFactory;
$this->security = $security;
$this->userRepository = $userRepository;
$this->userRender = $userRender;
}
/**
@ -86,22 +90,18 @@ class ReassignAccompanyingPeriodController extends AbstractController
private function buildFilterForm(): FormInterface
{
$builder = $this->formFactory->createBuilder(FormType::class, [
$data = [
'user' => null,
];
$builder = $this->formFactory->createBuilder(FormType::class, $data, [
'method' => 'get', 'csrf_protection' => false, ]);
$builder
->add('user', EntityType::class, [
'class' => User::class,
'query_builder' => function () {
$qb = $this->userRepository->createQueryBuilder('u');
$qb->where('u.enabled = true')
->orderBy('u.username', 'ASC');
return $qb;
},
'choice_label' => static function (User $u) {
return $u->getUsername();
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
'choice_label' => function (User $u) {
return $this->userRender->renderString($u, []);
},
'multiple' => false,
'label' => 'User',

View File

@ -42,8 +42,8 @@
<h1>{{ block('title') }}</h1>
{{ form_start(form) }}
<div class="row filter-box" style="padding: 2rem 2rem 2rem 0;">
<div class="col-md-6" style="display: flex; justify-content: space-between;">
<div class="row filter-box">
<div class="col-md-6">
{{ form_label(form.user ) }}
{{ form_widget(form.user, {'attr': {'class': 'select2'}}) }}
</div>