diff --git a/src/Bundle/ChillMainBundle/Entity/Regroupment.php b/src/Bundle/ChillMainBundle/Entity/Regroupment.php index 5de02ade6..96953abf5 100644 --- a/src/Bundle/ChillMainBundle/Entity/Regroupment.php +++ b/src/Bundle/ChillMainBundle/Entity/Regroupment.php @@ -43,7 +43,7 @@ class Regroupment private bool $isActive = true; /** - * @ORM\Column(type="string", length=15, options={"default": ""}, nullable=false) + * @ORM\Column(type="text", options={"default": ""}, nullable=false) */ private string $name = ''; diff --git a/src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php b/src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php index 17768544b..55157b1ab 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Export/PickCenterType.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Regroupment; use Chill\MainBundle\Export\ExportManager; use Chill\MainBundle\Form\DataMapper\ExportPickCenterDataMapper; +use Chill\MainBundle\Repository\RegroupmentRepository; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; @@ -29,29 +30,28 @@ use function count; /** * Pick centers amongst available centers for the user. */ -class PickCenterType extends AbstractType +final class PickCenterType extends AbstractType { public const CENTERS_IDENTIFIERS = 'c'; - protected AuthorizationHelperInterface $authorizationHelper; + private AuthorizationHelperInterface $authorizationHelper; - protected ExportManager $exportManager; + private ExportManager $exportManager; - protected UserInterface $user; + private RegroupmentRepository $regroupmentRepository; + + private UserInterface $user; public function __construct( TokenStorageInterface $tokenStorage, ExportManager $exportManager, + RegroupmentRepository $regroupmentRepository, AuthorizationHelperInterface $authorizationHelper ) { $this->exportManager = $exportManager; $this->user = $tokenStorage->getToken()->getUser(); $this->authorizationHelper = $authorizationHelper; - } - - public function addGroupingCenter(GroupingCenterInterface $grouping) - { - $this->groupingCenters[md5($grouping->getName())] = $grouping; + $this->regroupmentRepository = $regroupmentRepository; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -71,13 +71,14 @@ class PickCenterType extends AbstractType 'choice_label' => static function (Center $c) { return $c->getName(); }, - 'data' => count($this->groupingCenters) > 0 ? null : $centers, + 'data' => $centers, ]) ->add('regroupment', EntityType::class, [ 'class' => Regroupment::class, 'label' => 'regroupment', 'multiple' => true, 'expanded' => true, + 'choices' => $this->regroupmentRepository->findAllActive(), 'choice_label' => static function (Regroupment $r) { return $r->getName(); }, diff --git a/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php b/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php deleted file mode 100644 index 7b04d2ebd..000000000 --- a/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php +++ /dev/null @@ -1,18 +0,0 @@ -repository->findAll(); } + public function findAllActive(): array + { + return $this->repository->findBy(['isActive' => true], ['name' => 'ASC']); + } + /** * @param mixed|null $limit * @param mixed|null $offset diff --git a/src/Bundle/ChillMainBundle/Resources/views/Export/new_centers_step.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Export/new_centers_step.html.twig index a73913154..e08ec84d9 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Export/new_centers_step.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Export/new_centers_step.html.twig @@ -44,16 +44,6 @@
{{ form_widget(form.submit, { 'attr' : { 'class' : 'btn btn-action btn-create' }, 'label' : 'Go to export options' } ) }}
diff --git a/src/Bundle/ChillMainBundle/migrations/Version20230301155213.php b/src/Bundle/ChillMainBundle/migrations/Version20230301155213.php new file mode 100644 index 000000000..6d93b71d9 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20230301155213.php @@ -0,0 +1,26 @@ +addSql('ALTER TABLE regroupment ALTER name TYPE TEXT'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE regroupment ALTER name TYPE VARCHAR(15)'); + } +}