diff --git a/src/Bundle/ChillMainBundle/Repository/UserRepository.php b/src/Bundle/ChillMainBundle/Repository/UserRepository.php index 56a82de3d..0616878ff 100644 --- a/src/Bundle/ChillMainBundle/Repository/UserRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/UserRepository.php @@ -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); diff --git a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php index 66a460199..04e38da13 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php @@ -1,11 +1,19 @@ 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(); } - -} \ No newline at end of file +} diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php index 735227ced..47e1ee441 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php @@ -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(); - } } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig index 673b8a36d..d7e11f6ee 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig @@ -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) %}
{% 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 %}Choisissez un référent pour afficher ses parcours.
{% elseif periods|length == 0 and form.user.vars.value is not empty %} -Aucun parcour à réassigner pour cet utilisateur.
+Aucun parcours actifs pour ce référent.
{% else %} -Amount of parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})
+{{ paginator.totalItems }} parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})