mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
attempts to submit reassign form
This commit is contained in:
@@ -16,10 +16,12 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Templating\Entity\UserRender;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
|
||||
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\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -45,7 +47,21 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security, UserRender $userRender)
|
||||
private AccompanyingPeriodRepository $courseRepository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(
|
||||
AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository,
|
||||
UserRepository $userRepository,
|
||||
AccompanyingPeriodRepository $courseRepository,
|
||||
EngineInterface $engine,
|
||||
FormFactoryInterface $formFactory,
|
||||
PaginatorFactory $paginatorFactory,
|
||||
Security $security,
|
||||
UserRender $userRender,
|
||||
EntityManagerInterface $em
|
||||
)
|
||||
{
|
||||
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
|
||||
$this->engine = $engine;
|
||||
@@ -54,6 +70,8 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
$this->security = $security;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->userRender = $userRender;
|
||||
$this->courseRepository = $courseRepository;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,9 +83,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
|
||||
$periodIds = [];
|
||||
|
||||
$form = $this->buildFilterForm($periodIds);
|
||||
$form = $this->buildFilterForm();
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
@@ -83,14 +99,66 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
$paginator->getCurrentPageFirstItemNumber()
|
||||
);
|
||||
|
||||
foreach ($periods as $period) {
|
||||
$periodIds[] = $period->getId();
|
||||
// foreach ($periods as $period) {
|
||||
// $periodIds[] = $period->getId();
|
||||
// }
|
||||
|
||||
// $assignForm= $this->buildReassignForm($periods);
|
||||
$assignData = [];
|
||||
$assignForm = $this->createFormBuilder($assignData)
|
||||
->add('periods', ChoiceType::class, [
|
||||
// 'data' => serialize($periods),
|
||||
'choices' => $periods,
|
||||
'multiple' => true,
|
||||
'expanded' => true
|
||||
])
|
||||
->add('user', EntityType::class, [
|
||||
'class' => User::class,
|
||||
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
|
||||
'choice_label' => function (User $u) {
|
||||
return $this->userRender->renderString($u, []);
|
||||
},
|
||||
'placeholder' => 'Choose a user to reassign to',
|
||||
'multiple' => false,
|
||||
'label' => 'User',
|
||||
'required' => true,
|
||||
])
|
||||
->getForm();
|
||||
|
||||
$assignForm->handleRequest($request);
|
||||
|
||||
if ($assignForm->isSubmitted()) {
|
||||
|
||||
$periods = $assignForm->get('periods')->getData();
|
||||
$userAssign = $assignForm->get('user')->getData();
|
||||
|
||||
foreach($periods as $periodId) {
|
||||
$reassignPeriod = $this->courseRepository->find($periodId);
|
||||
$reassignPeriod->setUser($userAssign);
|
||||
$this->em->persist($reassignPeriod);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
$remainingPeriods = $this->accompanyingPeriodACLAwareRepository
|
||||
->findByUserOpenedAccompanyingPeriod(
|
||||
$form['user']->getData(),
|
||||
['openingDate' => 'ASC'],
|
||||
$paginator->getItemsPerPage(),
|
||||
$paginator->getCurrentPageFirstItemNumber()
|
||||
);
|
||||
|
||||
return new Response(
|
||||
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
|
||||
'paginator' => $paginator,
|
||||
'periods' => $remainingPeriods,
|
||||
'form' => $form->createView(),
|
||||
'assignForm' => $assignForm->createView()
|
||||
])
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$assignForm= $this->buildFilterForm($periodIds);
|
||||
|
||||
dump($assignForm->get('periods'));
|
||||
|
||||
return new Response(
|
||||
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
|
||||
'paginator' => $paginator,
|
||||
@@ -101,7 +169,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
private function buildFilterForm(array $periodIds): FormInterface
|
||||
private function buildFilterForm(): FormInterface
|
||||
{
|
||||
$data = [
|
||||
'user' => null,
|
||||
@@ -119,9 +187,40 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
'multiple' => false,
|
||||
'label' => 'User',
|
||||
'required' => false,
|
||||
]);
|
||||
// ->add('periods', HiddenType::class, [
|
||||
// 'data' => serialize($periodIds),
|
||||
// ]);
|
||||
|
||||
return $builder->getForm();
|
||||
}
|
||||
|
||||
private function buildReassignForm(array $periods): FormInterface
|
||||
{
|
||||
$defaultData = [
|
||||
'user' => [],
|
||||
'periods' => $periods
|
||||
];
|
||||
|
||||
$builder = $this->formFactory->createBuilder(FormType::class, $defaultData, ['csrf_protection' => false, ]);
|
||||
|
||||
$builder
|
||||
->add('periods', ChoiceType::class, [
|
||||
// 'data' => serialize($periods),
|
||||
'choices' => $periods,
|
||||
'multiple' => true,
|
||||
'expanded' => true
|
||||
])
|
||||
->add('periods', HiddenType::class, [
|
||||
'data' => serialize($periodIds),
|
||||
->add('user', EntityType::class, [
|
||||
'class' => User::class,
|
||||
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
|
||||
'choice_label' => function (User $u) {
|
||||
return $this->userRender->renderString($u, []);
|
||||
},
|
||||
'placeholder' => 'Choose a user to reassign to',
|
||||
'multiple' => false,
|
||||
'label' => 'User',
|
||||
'required' => true,
|
||||
]);
|
||||
|
||||
return $builder->getForm();
|
||||
|
Reference in New Issue
Block a user