diff --git a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php index 2a807ecde..99279ae84 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php @@ -20,7 +20,7 @@ use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; @@ -99,22 +99,25 @@ class ReassignAccompanyingPeriodController extends AbstractController $paginator->getCurrentPageFirstItemNumber() ); - $assignForm = $this->buildReassignForm($periods); + $periodIds = []; + + foreach ($periods as $period) { + $periodIds[] = $period->getId(); + } + + $assignForm = $this->buildReassignForm($periodIds); $assignForm->handleRequest($request); if ($assignForm->isSubmitted()) { - $periods = $assignForm->get('periods')->getData(); + $assignPeriodIds = json_decode($assignForm->get('periods')->getData(), true); $userAssign = $assignForm->get('assignUser')->getData(); - dump($periods); - dump($userAssign); - - foreach($periods as $periodId) { - $reassignPeriod = $this->courseRepository->find($periodId); - $reassignPeriod->setUser($userAssign); - $this->em->persist($reassignPeriod); + foreach($assignPeriodIds as $assignPeriodId) { + $assignPeriod = $this->courseRepository->find($assignPeriodId); + $assignPeriod->setUser($userAssign); + $this->em->persist($assignPeriod); } $this->em->flush(); @@ -171,17 +174,20 @@ class ReassignAccompanyingPeriodController extends AbstractController return $builder->getForm(); } - private function buildReassignForm(array $periods): FormInterface + private function buildReassignForm(array $periodIds): FormInterface { - $defaultData = []; + $defaultData = [ + 'user' => null, + 'periods' => [] + ]; + + $periodsJson = json_encode($periodIds); $builder = $this->formFactory->createBuilder(FormType::class, $defaultData, ['csrf_protection' => false, ]); $builder - ->add('periods', ChoiceType::class, [ - 'choices' => $periods, - 'multiple' => true, - 'expanded' => true + ->add('periods', HiddenType::class, [ + 'data' => $periodsJson, ]) ->add('assignUser', EntityType::class, [ 'class' => User::class, 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 d86b30bc0..9f77faeef 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig @@ -74,24 +74,6 @@ {{ form_widget(assignForm.assignUser, {'attr': {'class': 'select2'}}) }} - -
-
- {{ dump(assignForm.periods.vars.choices) }} - {% for choice in assignForm.periods.vars.choices %} -
- - -
- {% endfor %} -
-
- {% do assignForm.periods.setRendered() %} - {{ form_end(assignForm) }} - {#
+
{% for period in periods %} {% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period, 'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %} {% endfor %} -
#} +
{% endif %} {{ chill_pagination(paginator) }}