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\Location
;
19 use Rapsys\AirBundle\Entity\User
;
21 class SessionType
extends AbstractType
{
28 public function __construct(ManagerRegistry
$doctrine) {
29 $this->doctrine
= $doctrine;
33 * @todo: clean that shit
34 * @todo: mapped => false for each button not related with session !!!!
35 * @todo: set stuff in the SessionController, no loggic here please !!!
36 * @todo: add the dance link stuff
40 public function buildForm(FormBuilderInterface
$builder, array $options) {
41 //Is admin or user with rainfall >= 2
42 if (!empty($options['raincancel'])) {
44 $builder->add('raincancel', SubmitType
::class, ['label' => 'Rain cancel', 'attr' => ['class' => 'submit']]);
46 } elseif (!empty($options['admin'])) {
47 //Add forcecancel item
48 $builder->add('forcecancel', SubmitType
::class, ['label' => 'Force cancel', 'attr' => ['class' => 'submit']]);
52 if (!empty($options['modify'])) {
53 if (!empty($options['admin'])) {
54 $builder->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'])]]);
58 //TODO: avertissement + minimum et maximum ???
59 ->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'])]])
60 //TODO: avertissement + minimum et maximum ???
61 ->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'])]])
62 ->add('modify', SubmitType
::class, ['label' => 'Modify', 'attr' => ['class' => 'submit']]);
65 //Is admin or applicant
66 if (!empty($options['cancel'])) {
67 $builder->add('cancel', SubmitType
::class, ['label' => 'Cancel', 'attr' => ['class' => 'submit']]);
70 //Is admin or senior owner
71 if (!empty($options['move'])) {
73 $locations = $this->doctrine
->getRepository(Location
::class)->findComplementBySessionId($options['session']);
75 //TODO: class senior en orange ???
76 ->add('location', ChoiceType
::class, ['attr' => ['placeholder' => 'Your location'], 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'choices' => $locations, 'choice_translation_domain' => true])
77 ->add('move', SubmitType
::class, ['label' => 'Move', 'attr' => ['class' => 'submit']]);
80 //Add extra user field
81 if (!empty($options['admin'])) {
83 $users = $this->doctrine
->getRepository(User
::class)->findBySessionId($options['session']);
86 //TODO: class admin en rouge ???
87 ->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])
88 ->add('lock', SubmitType
::class, ['label' => 'Lock', 'attr' => ['class' => 'submit']]);
90 //Is admin and locked === null
91 if (!empty($options['attribute'])) {
92 //Add attribute fields
94 ->add('attribute', SubmitType
::class, ['label' => 'Attribute', 'attr' => ['class' => 'submit']])
95 ->add('autoattribute', SubmitType
::class, ['label' => 'Auto attribute', 'attr' => ['class' => 'submit']]);
106 public function configureOptions(OptionsResolver
$resolver) {
107 $resolver->setDefaults(['error_bubbling' => true, 'admin' => false, 'date' => null, 'begin' => null, 'length' => null, 'cancel' => false, 'raincancel' => false, 'modify' => false, 'move' => false, 'attribute' => false, 'user' => null, 'session' => null]);
108 $resolver->setAllowedTypes('admin', 'boolean');
109 #TODO: voir si c'est le bon type
110 $resolver->setAllowedTypes('date', 'datetime');
111 $resolver->setAllowedTypes('begin', 'datetime');
112 $resolver->setAllowedTypes('length', 'datetime');
113 $resolver->setAllowedTypes('cancel', 'boolean');
114 $resolver->setAllowedTypes('raincancel', 'boolean');
115 $resolver->setAllowedTypes('modify', 'boolean');
116 $resolver->setAllowedTypes('move', 'boolean');
117 $resolver->setAllowedTypes('attribute', 'boolean');
118 $resolver->setAllowedTypes('user', 'integer');
119 $resolver->setAllowedTypes('session', 'integer');
125 public function getName() {
126 return 'rapsys_air_session_edit';