diff --git a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php index 24de2d7db..ac5b6dfab 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\UserRepository; use Chill\MainBundle\Templating\Entity\UserRender; use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository; +use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\FormType; @@ -30,7 +31,7 @@ use Symfony\Component\Templating\EngineInterface; class ReassignAccompanyingPeriodController extends AbstractController { - private AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository; + private AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository; private EngineInterface $engine; @@ -44,7 +45,7 @@ class ReassignAccompanyingPeriodController extends AbstractController private UserRepository $userRepository; - public function __construct(AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security, UserRender $userRender) + public function __construct(AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security, UserRender $userRender) { $this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository; $this->engine = $engine; @@ -68,13 +69,14 @@ class ReassignAccompanyingPeriodController extends AbstractController $form->handleRequest($request); - $total = $this->accompanyingPeriodACLAwareRepository->countByUserConfirmed( + $total = $this->accompanyingPeriodACLAwareRepository->countByUserOpenedAccompanyingPeriod( $form['user']->getData() ); $paginator = $this->paginatorFactory->create($total); $periods = $this->accompanyingPeriodACLAwareRepository - ->findByUserConfirmed( + ->findByUserOpenedAccompanyingPeriod( $form['user']->getData(), + ['openingDate' => 'ASC'], $paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber() ); diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php index 47e1ee441..f4c9a52a3 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php @@ -42,28 +42,32 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC $this->centerResolverDispatcher = $centerResolverDispatcher; } - public function buildQueryByUser(?User $user) + public function buildQueryOpenedAccompanyingCourseByUser(?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') + $qb->expr()->neq('ap.step', ':draft'), + $qb->expr()->orX( + $qb->expr()->isNull('ap.closingDate'), + $qb->expr()->gt('ap.closingDate', ':now') + ) ) ->setParameter('user', $user) - ->setParameter('confirmed', AccompanyingPeriod::STEP_CONFIRMED); + ->setParameter('now', new \DateTime('now')) + ->setParameter('draft', AccompanyingPeriod::STEP_DRAFT); return $qb; } - public function countByUserConfirmed(?User $user) + public function countByUserOpenedAccompanyingPeriod(?User $user): int { if (null === $user) { return 0; } - return $this->buildQueryByUser($user) + return $this->buildQueryOpenedAccompanyingCourseByUser($user) ->select('COUNT(ap)') ->getQuery() ->getSingleScalarResult(); @@ -124,13 +128,20 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC /** * @return array|AccompanyingPeriod[] */ - public function findByUserConfirmed(?User $user, int $limit, int $offset): array + public function findByUserOpenedAccompanyingPeriod(?User $user, array $orderBy = [], int $limit = 0, int $offset = 50): array { if (null === $user) { return []; } - $qb = $this->buildQueryByUser($user); + $qb = $this->buildQueryOpenedAccompanyingCourseByUser($user); + + $qb->setFirstResult($offset) + ->setMaxResults($limit); + + foreach ($orderBy as $field => $direction) { + $qb->addOrderBy('ap.'.$field, $direction); + } return $qb->getQuery()->getResult(); } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepositoryInterface.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepositoryInterface.php index 778e8d8fe..0c5af217f 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepositoryInterface.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepositoryInterface.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Repository; +use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\Person; interface AccompanyingPeriodACLAwareRepositoryInterface @@ -22,4 +23,8 @@ interface AccompanyingPeriodACLAwareRepositoryInterface ?int $limit = null, ?int $offset = null ): array; + + public function findByUserOpenedAccompanyingPeriod(?User $user, array $orderBy = [], int $limit = 0, int $offset = 50): array; + + public function countByUserOpenedAccompanyingPeriod(?User $user): int; } 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 55b932751..87166d990 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 pour un utilisateur" %} +{% block title 'period_by_user_list.Period by user'|trans %} {% block js %} {{ encore_entry_script_tags('mod_set_referrer') }} @@ -60,9 +60,10 @@ {{ form_end(form) }} {% if form.user.vars.value is empty %} -

Choisissez un référent pour afficher ses parcours.

+

{{ 'period_by_user_list.Pick a user'|trans }}

{% elseif periods|length == 0 and form.user.vars.value is not empty %} -

Aucun parcours actifs pour ce référent.

+

{{ 'period_by_user_list.Any course or no authorization to see them'|trans }}

+ {% else %}

{{ paginator.totalItems }} parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})

diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index bb5e5e846..d6e739632 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -579,3 +579,8 @@ My accompanying periods in draft: Mes parcours brouillons workflow: Doc for evaluation (n°%eval%): Document de l'évaluation n°%eval% + +period_by_user_list: + Period by user: Parcours d'accompagnement par utilisateur + Pick a user: Choisissez un utilisateur pour obtenir la liste de ses parcours + Any course or no authorization to see them: Aucun parcours pour ce référent, ou aucun droit pour visualiser les parcours de ce référent.