]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Form/SessionType.php
Import anonymous token, a token required to validate an user's roles
[airbundle] / Form / SessionType.php
index f9901c3f15290592ef66c309fbf276096851051c..b42b26afe00ef919885ba241e8bedec31bbeba0a 100644 (file)
@@ -2,18 +2,23 @@
 
 namespace Rapsys\AirBundle\Form;
 
 
 namespace Rapsys\AirBundle\Form;
 
-use Symfony\Bridge\Doctrine\RegistryInterface;
+use Doctrine\Persistence\ManagerRegistry;
+use Symfony\Bridge\Doctrine\Form\Type\EntityType;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
+use Symfony\Component\Form\Extension\Core\Type\DateType;
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
 use Symfony\Component\Form\Extension\Core\Type\TimeType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 use Symfony\Component\Translation\TranslatorInterface;
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
 use Symfony\Component\Form\Extension\Core\Type\TimeType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 use Symfony\Component\Translation\TranslatorInterface;
+use Symfony\Component\Validator\Constraints\Type;
 use Symfony\Component\Validator\Constraints\NotBlank;
 use Symfony\Component\Validator\Constraints\NotBlank;
-use Symfony\Component\Validator\Constraints\Time;
-use Rapsys\AirBundle\Entity\User;
+
+use Rapsys\AirBundle\Entity\Dance;
 use Rapsys\AirBundle\Entity\Location;
 use Rapsys\AirBundle\Entity\Location;
+use Rapsys\AirBundle\Entity\Slot;
+use Rapsys\AirBundle\Entity\User;
 
 class SessionType extends AbstractType {
        //Doctrine instance
 
 class SessionType extends AbstractType {
        //Doctrine instance
@@ -22,11 +27,16 @@ class SessionType extends AbstractType {
        /**
         * {@inheritdoc}
         */
        /**
         * {@inheritdoc}
         */
-       public function __construct(RegistryInterface $doctrine) {
+       public function __construct(ManagerRegistry $doctrine) {
                $this->doctrine = $doctrine;
        }
 
        /**
                $this->doctrine = $doctrine;
        }
 
        /**
+        * @todo: clean that shit
+        * @todo: mapped => false for each button not related with session !!!!
+        * @todo: set stuff in the SessionController, no loggic here please !!!
+        * @todo: add the dance link stuff
+        *
         * {@inheritdoc}
         */
        public function buildForm(FormBuilderInterface $builder, array $options) {
         * {@inheritdoc}
         */
        public function buildForm(FormBuilderInterface $builder, array $options) {
@@ -42,11 +52,22 @@ class SessionType extends AbstractType {
 
                //Is admin or owner
                if (!empty($options['modify'])) {
 
                //Is admin or owner
                if (!empty($options['modify'])) {
+                       if (!empty($options['admin'])) {
+                               $builder
+                                       //Add dance field
+                                       ->add('dance', EntityType::class, ['class' => 'RapsysAirBundle:Dance', 'choices' => $options['dance_choices'], 'preferred_choices' => $options['dance_favorites'], 'attr' => ['placeholder' => 'Your dance'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your dance'])], 'data' => $options['dance_default']])
+
+                                       //Add slot field
+                                       ->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_default']])
+                                       //Add date field
+                                       ->add('date', DateType::class, ['attr' => ['placeholder' => 'Your date', 'class' => 'date'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'data' => $options['date'], 'constraints' => [new NotBlank(['message' => 'Please provide your date']), new Type(['type' => \DateTime::class, 'message' => 'Your date doesn\'t seems to be valid'])]]);
+                       }
+
                        $builder
                                //TODO: avertissement + minimum et maximum ???
                        $builder
                                //TODO: avertissement + minimum et maximum ???
-                               ->add('begin', TimeType::class, ['attr' => ['placeholder' => 'Your begin', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['begin'], 'constraints' => [new NotBlank(['message' => 'Please provide your begin']), new Time(['message' => 'Your begin doesn\'t seems to be valid'])]])
+                               ->add('begin', TimeType::class, ['attr' => ['placeholder' => 'Your begin', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['begin'], 'constraints' => [new NotBlank(['message' => 'Please provide your begin']), new Type(['type' => \DateTime::class, 'message' => 'Your begin doesn\'t seems to be valid'])]])
                                //TODO: avertissement + minimum et maximum ???
                                //TODO: avertissement + minimum et maximum ???
-                               ->add('length', TimeType::class, ['attr' => ['placeholder' => 'Your length', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['length'], 'constraints' => [new NotBlank(['message' => 'Please provide your length']), new Time(['message' => 'Your length doesn\'t seems to be valid'])]])
+                               ->add('length', TimeType::class, ['attr' => ['placeholder' => 'Your length', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['length'], 'constraints' => [new NotBlank(['message' => 'Please provide your length']), new Type(['type' => \DateTime::class, 'message' => 'Your length doesn\'t seems to be valid'])]])
                                ->add('modify', SubmitType::class, ['label' => 'Modify', 'attr' => ['class' => 'submit']]);
                }
 
                                ->add('modify', SubmitType::class, ['label' => 'Modify', 'attr' => ['class' => 'submit']]);
                }
 
@@ -68,7 +89,7 @@ class SessionType extends AbstractType {
                //Add extra user field
                if (!empty($options['admin'])) {
                        //Load users
                //Add extra user field
                if (!empty($options['admin'])) {
                        //Load users
-                       $users = $this->doctrine->getRepository(User::class)->findAllApplicantBySession($options['session']);
+                       $users = $this->doctrine->getRepository(User::class)->findBySessionId($options['session']);
                        //Add admin fields
                        $builder
                                //TODO: class admin en rouge ???
                        //Add admin fields
                        $builder
                                //TODO: class admin en rouge ???
@@ -92,17 +113,48 @@ class SessionType extends AbstractType {
         * {@inheritdoc}
         */
        public function configureOptions(OptionsResolver $resolver) {
         * {@inheritdoc}
         */
        public function configureOptions(OptionsResolver $resolver) {
-               $resolver->setDefaults(['error_bubbling' => true, 'admin' => false, 'begin' => null, 'length' => null, 'cancel' => false, 'raincancel' => false, 'modify' => false, 'move' => false, 'attribute' => false, 'user' => null, 'session' => null]);
+               $resolver->setDefaults(['error_bubbling' => true, 'admin' => false, 'dance_choices' => [], 'dance_default' => null, 'dance_favorites' => [], 'date' => null, 'begin' => null, 'length' => null, 'cancel' => false, 'raincancel' => false, 'modify' => false, 'move' => false, 'attribute' => false, 'user' => null, 'session' => null, 'slot_default' => null]);
+
+               //Add admin
                $resolver->setAllowedTypes('admin', 'boolean');
                $resolver->setAllowedTypes('admin', 'boolean');
-               #TODO: voir si c'est le bon type
+
+               //Add dance choices
+               $resolver->setAllowedTypes('dance_choices', 'array');
+
+               //Add dance default
+               $resolver->setAllowedTypes('dance_default', [Dance::class, 'null']);
+
+               //Add dance favorites
+               $resolver->setAllowedTypes('dance_favorites', 'array');
+
+               //Add date
+               $resolver->setAllowedTypes('date', 'datetime');
+
+               //Add begin
                $resolver->setAllowedTypes('begin', 'datetime');
                $resolver->setAllowedTypes('begin', 'datetime');
+
+               //Add length
                $resolver->setAllowedTypes('length', 'datetime');
                $resolver->setAllowedTypes('length', 'datetime');
+
+               //Add cancel
                $resolver->setAllowedTypes('cancel', 'boolean');
                $resolver->setAllowedTypes('cancel', 'boolean');
+
+               //Add raincancel
                $resolver->setAllowedTypes('raincancel', 'boolean');
                $resolver->setAllowedTypes('raincancel', 'boolean');
+
+               //Add modify
                $resolver->setAllowedTypes('modify', 'boolean');
                $resolver->setAllowedTypes('modify', 'boolean');
+
+               //Add move
                $resolver->setAllowedTypes('move', 'boolean');
                $resolver->setAllowedTypes('move', 'boolean');
+
+               //Add attribute
                $resolver->setAllowedTypes('attribute', 'boolean');
                $resolver->setAllowedTypes('attribute', 'boolean');
+
+               //Add user
                $resolver->setAllowedTypes('user', 'integer');
                $resolver->setAllowedTypes('user', 'integer');
+
+               //Add session
                $resolver->setAllowedTypes('session', 'integer');
        }
 
                $resolver->setAllowedTypes('session', 'integer');
        }