diff --git a/src/Bundle/ChillMainBundle/Repository/UserRepository.php b/src/Bundle/ChillMainBundle/Repository/UserRepository.php index fc3a6e187..56a82de3d 100644 --- a/src/Bundle/ChillMainBundle/Repository/UserRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/UserRepository.php @@ -32,6 +32,11 @@ 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); diff --git a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php new file mode 100644 index 000000000..66a460199 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php @@ -0,0 +1,108 @@ +accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository; + $this->engine = $engine; + $this->formFactory = $formFactory; + $this->paginatorFactory = $paginatorFactory; + $this->security = $security; + $this->userRepository = $userRepository; + } + + /** + * @Route("/{_locale}/person/accompanying-periods/reassign", name="chill_course_list_reassign") + */ + public function listAction(Request $request): Response + { + if (!$this->security->isGranted('ROLE_USER') || !$this->security->getUser() instanceof User) { + throw new AccessDeniedException(); + } + + $form = $this->buildFilterForm(); + + $form->handleRequest($request); + + // $total = $this->accompanyingPeriodACLAwareRepository->countByUserConfirmed( + // $form['jobs']->getData(), + // $form['services']->getData(), + // $form['locations']->getData(), + // ); + // $paginator = $this->paginatorFactory->create($total); + $periods = $this->accompanyingPeriodACLAwareRepository + ->findByUserConfirmed( + $form['user']->getData(), + 1, + 1 + ); + + return new Response( + $this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [ + // 'paginator' => $paginator, + 'periods' => $periods, + 'form' => $form->createView() + ]) + ); + } + + private function buildFilterForm(): FormInterface + { + $builder = $this->formFactory->createBuilder(FormType::class, [ + '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' => function (User $u) { + return $u->getUsername(); + }, + 'multiple' => false, + 'label' => 'User', + 'required' => false, + ]); + + return $builder->getForm(); + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Controller/UserAccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/UserAccompanyingPeriodController.php index 774b272c5..321f212d5 100644 --- a/src/Bundle/ChillPersonBundle/Controller/UserAccompanyingPeriodController.php +++ b/src/Bundle/ChillPersonBundle/Controller/UserAccompanyingPeriodController.php @@ -11,17 +11,11 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; -use Chill\MainBundle\Entity\User; use Chill\MainBundle\Pagination\PaginatorFactory; -use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; -use Doctrine\ORM\EntityRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; -use Symfony\Component\Security\Core\Security; class UserAccompanyingPeriodController extends AbstractController { @@ -29,13 +23,10 @@ class UserAccompanyingPeriodController extends AbstractController private PaginatorFactory $paginatorFactory; - private Security $security; - - public function __construct(AccompanyingPeriodRepository $accompanyingPeriodRepository, PaginatorFactory $paginatorFactory, Security $security) + public function __construct(AccompanyingPeriodRepository $accompanyingPeriodRepository, PaginatorFactory $paginatorFactory) { $this->accompanyingPeriodRepository = $accompanyingPeriodRepository; $this->paginatorFactory = $paginatorFactory; - $this->security = $security; } /** @@ -77,58 +68,4 @@ class UserAccompanyingPeriodController extends AbstractController 'pagination' => $pagination, ]); } - - /** - * @Route("/{_locale}/person/accompanying-periods/my/drafts", name="chill_person_accompanying_period_draft_user") - */ - public function listConfirmedAction(Request $request) - { - if (!$this->security->isGranted('ROLE_USER') || !$this->security->getUser() instanceof User) { - throw new AccessDeniedException(); - } - - $form = $this->buildUserSelectionForm(); - - $form->handleRequest($request); - if ($form->isSubmitted() && $form->isValid()) { - $user = $_POST['user']; - - $periods = $this->getDoctrine()->getRepository(AccompanyingPeriod::class)->findConfirmedByUser($user); - - return $this->render('@ChillPerson/AccompanyingPeriod/user_reassign_periods_list.html.twig', [ - 'accompanyingPeriods' => $periods, - ]); - } - - return $this->render('@ChillPerson/AccompanyingPeriod/user_reassign_periods_list.html.twig', [ - 'form' => $form - ]); - } - - private function buildUserSelectionForm(): FormInterface - { - $data = [ - 'users' => [], - ]; - - $builder = $this->formFactory->createBuilder(FormType::class, $data, [ - 'method' => 'get', 'csrf_protection' => false]); - - $builder - ->add('users', EntityType::class, [ - 'class' => User::class, - 'query_builder' => function (EntityRepository $er) { - $qb = $er->createQueryBuilder('u'); - return $qb; - }, - 'choice_label' => function(User $u) { - return $u->getUsername(); - }, - 'multiple' => false, - 'label' => 'User', - 'required' => false, - ]); - - return $builder->getForm(); - } } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php index 6e6c3ca44..735227ced 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodACLAwareRepository.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Repository; +use Chill\MainBundle\Entity\User; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; @@ -92,4 +93,26 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC return $qb->getQuery()->getResult(); } + + /** + * @return array|AccompanyingPeriod[] + */ + public function findByUserConfirmed(?User $user, int $limit, int $offset): array + { + if (null === $user) { + 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); + + 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 new file mode 100644 index 000000000..673b8a36d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig @@ -0,0 +1,80 @@ +{% extends 'ChillMainBundle::layout.html.twig' %} + +{% block title "Liste de parcours à réassigner" %} + +{% block js %} + {{ encore_entry_script_tags('mod_set_referrer') }} +{% endblock %} + +{% block css %} + {{ encore_entry_link_tags('mod_set_referrer') }} +{% endblock %} + +{# {% macro period_meta(period) %} + {% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %} +
+ {% set job_id = null %} + {% if period.job is defined %} + {% set job_id = period.job.id %} + {% endif %} + +
+ {% endif %} +{% endmacro %} #} + +{% macro period_actions(period) %} + {% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', period) %} +
  • + +
  • + {% endif %} +{% endmacro %} + +{% import _self as m %} + +{% block content %} +
    +

    {{ block('title') }}

    + + {{ form_start(form) }} +
    +
    + {{ form_label(form.user ) }} + {{ form_widget(form.user, {'attr': {'class': 'select2'}}) }} +
    +
    + + + + {{ form_end(form) }} + + {% 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.

    + {% else %} +

    Amount of parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})

    + +
    + {% for period in periods %} + {% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period, + 'recordAction': m.period_actions(period) } %} + {% endfor %} +
    + {% endif %} + + {# {{ chill_pagination(paginator) }} #} + +
    +{% endblock %} + diff --git a/src/Bundle/ChillPersonBundle/config/services/controller.yaml b/src/Bundle/ChillPersonBundle/config/services/controller.yaml index 22d58ccbe..67c724093 100644 --- a/src/Bundle/ChillPersonBundle/config/services/controller.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/controller.yaml @@ -41,6 +41,11 @@ services: autowire: true tags: ['controller.service_arguments'] + Chill\PersonBundle\Controller\ReassignAccompanyingPeriodController: + autoconfigure: true + autowire: true + tags: ['controller.service_arguments'] + Chill\PersonBundle\Controller\PersonApiController: arguments: $authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'