3 namespace Rapsys\AirBundle\Form
;
5 use Doctrine\Persistence\ManagerRegistry
;
6 use Symfony\Bridge\Doctrine\Form\Type\EntityType
;
7 use Symfony\Component\Form\AbstractType
;
8 use Symfony\Component\Form\Extension\Core\Type\ChoiceType
;
9 use Symfony\Component\Form\Extension\Core\Type\DateType
;
10 use Symfony\Component\Form\Extension\Core\Type\SubmitType
;
11 use Symfony\Component\Form\Extension\Core\Type\TimeType
;
12 use Symfony\Component\Form\FormBuilderInterface
;
13 use Symfony\Component\OptionsResolver\OptionsResolver
;
14 use Symfony\Component\Translation\TranslatorInterface
;
15 use Symfony\Component\Validator\Constraints\Type
;
16 use Symfony\Component\Validator\Constraints\NotBlank
;
18 use Rapsys\AirBundle\Entity\Dance
;
19 use Rapsys\AirBundle\Entity\Location
;
20 use Rapsys\AirBundle\Entity\Slot
;
21 use Rapsys\AirBundle\Entity\User
;
23 class SessionType
extends AbstractType
{
30 public function __construct(ManagerRegistry
$doctrine) {
31 $this->doctrine
= $doctrine;
35 * @todo: clean that shit
36 * @todo: mapped => false for each button not related with session !!!!
37 * @todo: set stuff in the SessionController, no loggic here please !!!
38 * @todo: add the dance link stuff
42 public function buildForm(FormBuilderInterface
$builder, array $options): void {
43 //Is admin or user with rainfall >= 2
44 if (!empty($options['raincancel'])) {
46 $builder->add('raincancel', SubmitType
::class, ['label' => 'Rain cancel', 'attr' => ['class' => 'submit']]);
48 } elseif (!empty($options['admin'])) {
49 //Add forcecancel item
50 $builder->add('forcecancel', SubmitType
::class, ['label' => 'Force cancel', 'attr' => ['class' => 'submit']]);
54 if (!empty($options['modify'])) {
55 if (!empty($options['admin'])) {
58 ->add('dance', EntityType
::class, ['class' => 'Rapsys\AirBundle\Entity\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']])
61 ->add('slot', EntityType
::class, ['class' => 'Rapsys\AirBundle\Entity\Slot', 'attr' => ['placeholder' => 'Your slot'], 'constraints' => [new NotBlank(['message' => 'Please provide your slot'])], 'choice_translation_domain' => true, 'data' => $options['slot_default']])
63 ->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'])]]);
67 //TODO: avertissement + minimum et maximum ???
68 ->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'])]])
69 //TODO: avertissement + minimum et maximum ???
70 ->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'])]])
71 ->add('modify', SubmitType
::class, ['label' => 'Modify', 'attr' => ['class' => 'submit']]);
74 //Is admin or applicant
75 if (!empty($options['cancel'])) {
76 $builder->add('cancel', SubmitType
::class, ['label' => 'Cancel', 'attr' => ['class' => 'submit']]);
79 //Is admin or senior owner
80 if (!empty($options['move'])) {
82 $locations = $this->doctrine
->getRepository(Location
::class)->findComplementBySessionId($options['session']);
84 //TODO: class senior en orange ???
85 ->add('location', ChoiceType
::class, ['attr' => ['placeholder' => 'Your location'], 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'choices' => $locations, 'choice_translation_domain' => true])
86 ->add('move', SubmitType
::class, ['label' => 'Move', 'attr' => ['class' => 'submit']]);
89 //Add extra user field
90 if (!empty($options['admin'])) {
92 $users = $this->doctrine
->getRepository(User
::class)->findBySessionId($options['session']);
95 //TODO: class admin en rouge ???
96 ->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])
97 ->add('lock', SubmitType
::class, ['label' => 'Lock', 'attr' => ['class' => 'submit']]);
99 //Is admin and locked === null
100 if (!empty($options['attribute'])) {
101 //Add attribute fields
103 ->add('attribute', SubmitType
::class, ['label' => 'Attribute', 'attr' => ['class' => 'submit']])
104 ->add('autoattribute', SubmitType
::class, ['label' => 'Auto attribute', 'attr' => ['class' => 'submit']]);
112 public function configureOptions(OptionsResolver
$resolver): void {
113 $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]);
116 $resolver->setAllowedTypes('admin', 'boolean');
119 $resolver->setAllowedTypes('dance_choices', 'array');
122 $resolver->setAllowedTypes('dance_default', [Dance
::class, 'null']);
124 //Add dance favorites
125 $resolver->setAllowedTypes('dance_favorites', 'array');
128 $resolver->setAllowedTypes('date', 'datetime');
131 $resolver->setAllowedTypes('begin', 'datetime');
134 $resolver->setAllowedTypes('length', 'datetime');
137 $resolver->setAllowedTypes('cancel', 'boolean');
140 $resolver->setAllowedTypes('raincancel', 'boolean');
143 $resolver->setAllowedTypes('modify', 'boolean');
146 $resolver->setAllowedTypes('move', 'boolean');
149 $resolver->setAllowedTypes('attribute', 'boolean');
152 $resolver->setAllowedTypes('user', 'integer');
155 $resolver->setAllowedTypes('session', 'integer');
161 public function getName(): string {
162 return 'rapsysair_session_edit';