mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Allow the selection of multiple centers to create multiple groupcenters at once
This commit is contained in:
parent
63fc4f1089
commit
0f1604817b
@ -64,11 +64,20 @@ class UserController extends CRUDController
|
|||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
$groupCenter = $this->getPersistedGroupCenter(
|
|
||||||
$form[self::FORM_GROUP_CENTER_COMPOSED]->getData()
|
$formData = $form[self::FORM_GROUP_CENTER_COMPOSED]->getData();
|
||||||
);
|
$selectedCenters = $formData['center'];
|
||||||
|
|
||||||
|
foreach ($selectedCenters as $center) {
|
||||||
|
$groupCenter = new GroupCenter();
|
||||||
|
$groupCenter->setCenter($center);
|
||||||
|
$groupCenter->setPermissionsGroup($formData['permissionsgroup']);
|
||||||
|
|
||||||
$user->addGroupCenter($groupCenter);
|
$user->addGroupCenter($groupCenter);
|
||||||
|
|
||||||
|
$em->persist($groupCenter);
|
||||||
|
}
|
||||||
|
|
||||||
if (0 === $this->validator->validate($user)->count()) {
|
if (0 === $this->validator->validate($user)->count()) {
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
@ -13,36 +13,30 @@ namespace Chill\MainBundle\Form\Type;
|
|||||||
|
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Entity\PermissionsGroup;
|
use Chill\MainBundle\Entity\PermissionsGroup;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Chill\MainBundle\Repository\CenterRepository;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
||||||
|
|
||||||
class ComposedGroupCenterType extends AbstractType
|
class ComposedGroupCenterType extends AbstractType
|
||||||
{
|
{
|
||||||
|
public function __construct(private readonly CenterRepository $centerRepository) {}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
$centers = $this->centerRepository->findActive();
|
||||||
|
|
||||||
$builder->add('permissionsgroup', EntityType::class, [
|
$builder->add('permissionsgroup', EntityType::class, [
|
||||||
'class' => PermissionsGroup::class,
|
'class' => PermissionsGroup::class,
|
||||||
'choice_label' => static fn (PermissionsGroup $group) => $group->getName(),
|
'choice_label' => static fn (PermissionsGroup $group) => $group->getName(),
|
||||||
])->add('center', EntityType::class, [
|
])->add('center', ChoiceType::class, [
|
||||||
'class' => Center::class,
|
'choices' => $centers,
|
||||||
'query_builder' => static function (EntityRepository $er) {
|
'choice_label' => fn (Center $center) => $center->getName(),
|
||||||
$qb = $er->createQueryBuilder('c');
|
'multiple' => true,
|
||||||
$qb->where($qb->expr()->eq('c.isActive', 'TRUE'))
|
|
||||||
->orderBy('c.name', 'ASC');
|
|
||||||
|
|
||||||
return $qb;
|
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
|
||||||
{
|
|
||||||
$resolver->setDefault('data_class', \Chill\MainBundle\Entity\GroupCenter::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBlockPrefix()
|
public function getBlockPrefix()
|
||||||
{
|
{
|
||||||
return 'composed_groupcenter';
|
return 'composed_groupcenter';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user