paginator added + phpcsfixes

This commit is contained in:
Julie Lenaerts 2022-03-17 14:13:21 +01:00
parent 6adb647ccc
commit 72ba2c6bca
4 changed files with 61 additions and 36 deletions

View File

@ -32,11 +32,6 @@ final class UserRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(User::class); $this->repository = $entityManager->getRepository(User::class);
} }
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
public function countBy(array $criteria): int public function countBy(array $criteria): int
{ {
return $this->repository->count($criteria); return $this->repository->count($criteria);
@ -56,6 +51,11 @@ final class UserRepository implements ObjectRepository
return (int) $qb->getQuery()->getSingleScalarResult(); 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 public function find($id, $lockMode = null, $lockVersion = null): ?User
{ {
return $this->repository->find($id, $lockMode, $lockVersion); return $this->repository->find($id, $lockMode, $lockVersion);

View File

@ -1,11 +1,19 @@
<?php <?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Controller; namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\UserRepository; use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository; use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -56,24 +64,22 @@ class ReassignAccompanyingPeriodController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
// $total = $this->accompanyingPeriodACLAwareRepository->countByUserConfirmed( $total = $this->accompanyingPeriodACLAwareRepository->countByUserConfirmed(
// $form['jobs']->getData(), $form['user']->getData()
// $form['services']->getData(), );
// $form['locations']->getData(), $paginator = $this->paginatorFactory->create($total);
// );
// $paginator = $this->paginatorFactory->create($total);
$periods = $this->accompanyingPeriodACLAwareRepository $periods = $this->accompanyingPeriodACLAwareRepository
->findByUserConfirmed( ->findByUserConfirmed(
$form['user']->getData(), $form['user']->getData(),
1, $paginator->getItemsPerPage(),
1 $paginator->getCurrentPageFirstItemNumber()
); );
return new Response( return new Response(
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [ $this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
// 'paginator' => $paginator, 'paginator' => $paginator,
'periods' => $periods, 'periods' => $periods,
'form' => $form->createView() 'form' => $form->createView(),
]) ])
); );
} }
@ -81,7 +87,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
private function buildFilterForm(): FormInterface private function buildFilterForm(): FormInterface
{ {
$builder = $this->formFactory->createBuilder(FormType::class, [ $builder = $this->formFactory->createBuilder(FormType::class, [
'method' => 'get', 'csrf_protection' => false]); 'method' => 'get', 'csrf_protection' => false, ]);
$builder $builder
->add('user', EntityType::class, [ ->add('user', EntityType::class, [
@ -94,7 +100,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
return $qb; return $qb;
}, },
'choice_label' => function (User $u) { 'choice_label' => static function (User $u) {
return $u->getUsername(); return $u->getUsername();
}, },
'multiple' => false, 'multiple' => false,
@ -104,5 +110,4 @@ class ReassignAccompanyingPeriodController extends AbstractController
return $builder->getForm(); return $builder->getForm();
} }
} }

View File

@ -42,6 +42,33 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
$this->centerResolverDispatcher = $centerResolverDispatcher; $this->centerResolverDispatcher = $centerResolverDispatcher;
} }
public function buildQueryByUser(?User $user)
{
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap');
$qb->where($qb->expr()->eq('ap.user', ':user'))
->andWhere(
$qb->expr()->eq('ap.step', ':confirmed'),
$qb->expr()->eq('ap.confidential', 'false')
)
->setParameter('user', $user)
->setParameter('confirmed', AccompanyingPeriod::STEP_CONFIRMED);
return $qb;
}
public function countByUserConfirmed(?User $user)
{
if (null === $user) {
return 0;
}
return $this->buildQueryByUser($user)
->select('COUNT(ap)')
->getQuery()
->getSingleScalarResult();
}
public function findByPerson( public function findByPerson(
Person $person, Person $person,
string $role, string $role,
@ -103,16 +130,8 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
return []; return [];
} }
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap'); $qb = $this->buildQueryByUser($user);
$qb->where($qb->expr()->eq('ap.user', ':user'))
->andWhere(
$qb->expr()->eq('ap.step', ':confirmed')
)
->setParameter('user', $user)
->setParameter('confirmed', AccompanyingPeriod::STEP_CONFIRMED);
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
} }
} }

View File

@ -1,6 +1,6 @@
{% extends 'ChillMainBundle::layout.html.twig' %} {% extends 'ChillMainBundle::layout.html.twig' %}
{% block title "Liste de parcours à réassigner" %} {% block title "Liste de parcours à réassigner pour un utilisateur" %}
{% block js %} {% block js %}
{{ encore_entry_script_tags('mod_set_referrer') }} {{ encore_entry_script_tags('mod_set_referrer') }}
@ -10,7 +10,7 @@
{{ encore_entry_link_tags('mod_set_referrer') }} {{ encore_entry_link_tags('mod_set_referrer') }}
{% endblock %} {% endblock %}
{# {% macro period_meta(period) %} {% macro period_meta(period) %}
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %} {% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %}
<div class="item-col item-meta"> <div class="item-col item-meta">
{% set job_id = null %} {% set job_id = null %}
@ -24,7 +24,8 @@
></span> ></span>
</div> </div>
{% endif %} {% endif %}
{% endmacro %} #} {% endmacro %}
{% macro period_actions(period) %} {% macro period_actions(period) %}
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', period) %} {% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', period) %}
@ -61,19 +62,19 @@
{% if form.user.vars.value is empty %} {% if form.user.vars.value is empty %}
<p class="chill-no-data-statement">Choisissez un référent pour afficher ses parcours.</p> <p class="chill-no-data-statement">Choisissez un référent pour afficher ses parcours.</p>
{% elseif periods|length == 0 and form.user.vars.value is not empty %} {% elseif periods|length == 0 and form.user.vars.value is not empty %}
<p class="chill-no-data-statement">Aucun parcour à réassigner pour cet utilisateur.</p> <p class="chill-no-data-statement">Aucun parcours actifs pour ce référent.</p>
{% else %} {% else %}
<p><span class="badge rounded-pill bg-primary">Amount of</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p> <p><span class="badge rounded-pill bg-primary">{{ paginator.totalItems }}</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p>
<div class="flex-table"> <div class="flex-table">
{% for period in periods %} {% for period in periods %}
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period, {% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
'recordAction': m.period_actions(period) } %} 'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %}
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
{# {{ chill_pagination(paginator) }} #} {{ chill_pagination(paginator) }}
</div> </div>
{% endblock %} {% endblock %}