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);
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
public function countBy(array $criteria): int
{
return $this->repository->count($criteria);
@ -56,6 +51,11 @@ 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

@ -1,11 +1,19 @@
<?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;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -56,24 +64,22 @@ class ReassignAccompanyingPeriodController extends AbstractController
$form->handleRequest($request);
// $total = $this->accompanyingPeriodACLAwareRepository->countByUserConfirmed(
// $form['jobs']->getData(),
// $form['services']->getData(),
// $form['locations']->getData(),
// );
// $paginator = $this->paginatorFactory->create($total);
$total = $this->accompanyingPeriodACLAwareRepository->countByUserConfirmed(
$form['user']->getData()
);
$paginator = $this->paginatorFactory->create($total);
$periods = $this->accompanyingPeriodACLAwareRepository
->findByUserConfirmed(
$form['user']->getData(),
1,
1
$paginator->getItemsPerPage(),
$paginator->getCurrentPageFirstItemNumber()
);
return new Response(
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
// 'paginator' => $paginator,
'paginator' => $paginator,
'periods' => $periods,
'form' => $form->createView()
'form' => $form->createView(),
])
);
}
@ -81,7 +87,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
private function buildFilterForm(): FormInterface
{
$builder = $this->formFactory->createBuilder(FormType::class, [
'method' => 'get', 'csrf_protection' => false]);
'method' => 'get', 'csrf_protection' => false, ]);
$builder
->add('user', EntityType::class, [
@ -94,7 +100,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
return $qb;
},
'choice_label' => function (User $u) {
'choice_label' => static function (User $u) {
return $u->getUsername();
},
'multiple' => false,
@ -104,5 +110,4 @@ class ReassignAccompanyingPeriodController extends AbstractController
return $builder->getForm();
}
}
}

View File

@ -42,6 +42,33 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
$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(
Person $person,
string $role,
@ -103,16 +130,8 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
return [];
}
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap');
$qb->where($qb->expr()->eq('ap.user', ':user'))
->andWhere(
$qb->expr()->eq('ap.step', ':confirmed')
)
->setParameter('user', $user)
->setParameter('confirmed', AccompanyingPeriod::STEP_CONFIRMED);
$qb = $this->buildQueryByUser($user);
return $qb->getQuery()->getResult();
}
}

View File

@ -1,6 +1,6 @@
{% extends 'ChillMainBundle::layout.html.twig' %}
{% block title "Liste de parcours à réassigner" %}
{% block title "Liste de parcours à réassigner pour un utilisateur" %}
{% block js %}
{{ encore_entry_script_tags('mod_set_referrer') }}
@ -10,7 +10,7 @@
{{ encore_entry_link_tags('mod_set_referrer') }}
{% endblock %}
{# {% macro period_meta(period) %}
{% macro period_meta(period) %}
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %}
<div class="item-col item-meta">
{% set job_id = null %}
@ -24,7 +24,8 @@
></span>
</div>
{% endif %}
{% endmacro %} #}
{% endmacro %}
{% macro period_actions(period) %}
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', period) %}
@ -61,19 +62,19 @@
{% if form.user.vars.value is empty %}
<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 %}
<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 %}
<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">
{% for period in periods %}
{% 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 %}
</div>
{% endif %}
{# {{ chill_pagination(paginator) }} #}
{{ chill_pagination(paginator) }}
</div>
{% endblock %}