mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
use pick dynamic user type for reassigning + layout stuffs
This commit is contained in:
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Templating\Entity\UserRender;
|
||||
@@ -31,7 +32,10 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Component\Validator\Constraints\NotEqualTo;
|
||||
use Symfony\Component\Validator\Constraints\NotIdenticalTo;
|
||||
use function is_int;
|
||||
|
||||
class ReassignAccompanyingPeriodController extends AbstractController
|
||||
@@ -129,18 +133,17 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
$this->em->flush();
|
||||
|
||||
// redirect to the first page
|
||||
return $this->redirectToRoute('chill_course_list_reassign', [
|
||||
'form' => ['user' => $userFrom->getId()],
|
||||
]);
|
||||
return $this->redirectToRoute('chill_course_list_reassign', $request->query->all());
|
||||
}
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
|
||||
'assignForm' => $assignForm->createView(),
|
||||
'form' => $form->createView(),
|
||||
'paginator' => $paginator,
|
||||
'periods' => $periods,
|
||||
'form' => $form->createView(),
|
||||
'assignForm' => $assignForm->createView(),
|
||||
'userFrom' => $userFrom,
|
||||
])
|
||||
);
|
||||
}
|
||||
@@ -154,15 +157,11 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
'method' => 'get', 'csrf_protection' => false, ]);
|
||||
|
||||
$builder
|
||||
->add('user', EntityType::class, [
|
||||
'class' => User::class, // pickUserType or PickDyamicUserType
|
||||
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
|
||||
'choice_label' => function (User $u) {
|
||||
return $this->userRender->renderString($u, []);
|
||||
},
|
||||
->add('user', PickUserDynamicType::class, [
|
||||
'multiple' => false,
|
||||
'label' => 'User',
|
||||
'label' => 'reassign.Current user',
|
||||
'required' => false,
|
||||
'help' => 'reassign.Choose a user and click on "Filter" to apply',
|
||||
]);
|
||||
|
||||
return $builder->getForm();
|
||||
@@ -173,26 +172,23 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
$defaultData = [
|
||||
'userFrom' => $userFrom,
|
||||
'periods' => json_encode($periodIds),
|
||||
'assignTo' => null,
|
||||
];
|
||||
|
||||
$builder = $this->formFactory->createBuilder(FormType::class, $defaultData);
|
||||
$builder = $this->formFactory->createNamedBuilder('reassign', FormType::class, $defaultData);
|
||||
|
||||
if (null !== $userFrom) {
|
||||
$constraints = [new NotIdenticalTo(['value' => $userFrom])];
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('periods', HiddenType::class)
|
||||
->add('userFrom', HiddenType::class)
|
||||
->add('userTo', EntityType::class, [
|
||||
'class' => User::class, // PickUserType
|
||||
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
|
||||
'choice_label' => function (User $u) {
|
||||
return $this->userRender->renderString($u, []);
|
||||
},
|
||||
'placeholder' => 'Choose a user to reassign to',
|
||||
->add('userTo', PickUserDynamicType::class, [
|
||||
'multiple' => false,
|
||||
'label' => 'User',
|
||||
'label' => 'reassign.Next user',
|
||||
'required' => true,
|
||||
// add a constraint: userFrom is not equal to userTo
|
||||
//'constraints' => NotEqualToh
|
||||
'help' => 'reassign.All periods on this list will be reassigned to this user, excepted the one you manually reassigned before',
|
||||
'constraints' => $constraints ?? [],
|
||||
]);
|
||||
|
||||
$builder->get('userFrom')->addModelTransformer(new CallbackTransformer(
|
||||
|
Reference in New Issue
Block a user