X-Git-Url: https://git.rapsys.eu/airbundle/blobdiff_plain/d458958d9f2bff86eef468ce0502bc281aab8c8e..9435311a62e45dc4e38ad063f1c846774c02328f:/Form/ApplicationType.php diff --git a/Form/ApplicationType.php b/Form/ApplicationType.php index 3e6f097..ef6819a 100644 --- a/Form/ApplicationType.php +++ b/Form/ApplicationType.php @@ -8,7 +8,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\DateType; -use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Validator\Constraints\Date; use Symfony\Component\Validator\Constraints\NotBlank; @@ -16,6 +15,7 @@ use Symfony\Bridge\Doctrine\RegistryInterface; use Symfony\Component\Translation\TranslatorInterface; use Rapsys\AirBundle\Entity\User; use Rapsys\AirBundle\Entity\Slot; +use Rapsys\AirBundle\Entity\Location; class ApplicationType extends AbstractType { //Doctrine instance @@ -38,17 +38,21 @@ class ApplicationType extends AbstractType { //Create base form $form = $builder - ->add('location', EntityType::class, ['class' => 'RapsysAirBundle:Location', 'attr' => ['placeholder' => 'Your location'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your location'])]]) ->add('date', DateType::class, ['attr' => ['placeholder' => 'Your date', 'class' => 'date'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'data' => new \DateTime('+7 day'), 'constraints' => [new NotBlank(['message' => 'Please provide your date']), new Date(['message' => 'Your date doesn\'t seems to be valid'])]]) #->add('slot', ChoiceType::class, ['attr' => ['placeholder' => 'Your slot'], 'constraints' => [new NotBlank(['message' => 'Please provide your slot'])], 'choices' => $slots, 'data' => $options['slot']]) ->add('slot', EntityType::class, ['class' => 'RapsysAirBundle:Slot', 'attr' => ['placeholder' => 'Your slot'], 'constraints' => [new NotBlank(['message' => 'Please provide your slot'])], 'choice_translation_domain' => true, 'data' => $options['slot']]) - ->add('return', HiddenType::class, ['data' => $options['return']]) ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]); //Add extra user field if (!empty($options['admin'])) { - $users = $this->doctrine->getRepository(User::class)->findAllWithTranslatedGroupAndTitle($this->translator); - $form->add('user', ChoiceType::class, ['attr' => ['placeholder' => 'Your user'], 'constraints' => [new NotBlank(['message' => 'Please provide your user'])], 'choices' => $users, 'data' => $options['user'], 'choice_translation_domain' => false]); + $users = $this->doctrine->getRepository(User::class)->findAllWithTranslatedGroupAndCivility($this->translator); + $form + ->add('location', EntityType::class, ['class' => 'RapsysAirBundle:Location', 'attr' => ['placeholder' => 'Your location'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'data' => $options['location']]) + ->add('user', ChoiceType::class, ['attr' => ['placeholder' => 'Your user'], 'choice_translation_domain' => false, 'constraints' => [new NotBlank(['message' => 'Please provide your user'])], 'choices' => $users, 'data' => $options['user']]); + //Add user locations + } else { + $locations = $this->doctrine->getRepository(Location::class)->findByUserId($options['user']); + $form->add('location', EntityType::class, ['class' => 'RapsysAirBundle:Location', 'choices' => $locations, 'attr' => ['placeholder' => 'Your location'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'data' => $options['location']]); } //Return form @@ -60,9 +64,9 @@ class ApplicationType extends AbstractType { */ public function configureOptions(OptionsResolver $resolver) { //XXX: 1 should be the first user - $resolver->setDefaults(['error_bubbling' => true, 'admin' => false, 'return' => '', 'slot' => null, 'user' => 1]); + $resolver->setDefaults(['error_bubbling' => true, 'admin' => false, 'slot' => null, 'location' => null, 'user' => 1]); $resolver->setAllowedTypes('admin', 'boolean'); - $resolver->setAllowedTypes('return', 'string'); + $resolver->setAllowedTypes('location', [Location::class, 'null']); $resolver->setAllowedTypes('slot', [Slot::class, 'null']); $resolver->setAllowedTypes('user', 'integer'); }