From 9f064784f2abc600959570c988730cc4f80bbe45 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 25 Mar 2022 13:01:33 +0100 Subject: [PATCH] first commit --- .../ReassignAccompanyingPeriodController.php | 19 +++++++++++++-- .../reassign_list.html.twig | 24 +++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php index 4abf5e93c..eb8dcc70e 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php @@ -19,6 +19,7 @@ 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; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; @@ -64,7 +65,9 @@ class ReassignAccompanyingPeriodController extends AbstractController throw new AccessDeniedException(); } - $form = $this->buildFilterForm(); + $periodIds = []; + + $form = $this->buildFilterForm($periodIds); $form->handleRequest($request); @@ -80,16 +83,25 @@ class ReassignAccompanyingPeriodController extends AbstractController $paginator->getCurrentPageFirstItemNumber() ); + foreach ($periods as $period) { + $periodIds[] = $period->getId(); + } + + $assignForm= $this->buildFilterForm($periodIds); + + dump($assignForm->get('periods')); + return new Response( $this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [ 'paginator' => $paginator, 'periods' => $periods, 'form' => $form->createView(), + 'assignForm' => $assignForm->createView() ]) ); } - private function buildFilterForm(): FormInterface + private function buildFilterForm(array $periodIds): FormInterface { $data = [ 'user' => null, @@ -107,6 +119,9 @@ class ReassignAccompanyingPeriodController extends AbstractController 'multiple' => false, 'label' => 'User', 'required' => false, + ]) + ->add('periods', HiddenType::class, [ + 'data' => serialize($periodIds), ]); return $builder->getForm(); 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 87166d990..2b36a175f 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig @@ -14,7 +14,7 @@ {% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %}
{% set job_id = null %} - {% if period.job is defined %} + {% if period.job is defined and period.job is not null %} {% set job_id = period.job.id %} {% endif %}
  • {{ form_end(form) }} +
    +

    {{ 'Attribute all parcours in this list to the following users,'|trans }}

    + {{ form_start(assignForm) }} +
    +
    + {{ form_label(assignForm.user ) }} + {{ form_widget(assignForm.user, {'attr': {'class': 'select2'}}) }} +
    +
    + +
      +
    • + +
    • +
    + {{ form_end(assignForm) }} +
    + {% if form.user.vars.value is empty %}

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

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