3 namespace Rapsys\AirBundle\Form
;
5 use Symfony\Bridge\Doctrine\RegistryInterface
;
6 use Symfony\Component\Form\AbstractType
;
7 use Symfony\Component\Form\Extension\Core\Type\ChoiceType
;
8 use Symfony\Component\Form\Extension\Core\Type\DateType
;
9 use Symfony\Component\Form\Extension\Core\Type\SubmitType
;
10 use Symfony\Component\Form\Extension\Core\Type\TimeType
;
11 use Symfony\Component\Form\FormBuilderInterface
;
12 use Symfony\Component\OptionsResolver\OptionsResolver
;
13 use Symfony\Component\Translation\TranslatorInterface
;
14 use Symfony\Component\Validator\Constraints\Date
;
15 use Symfony\Component\Validator\Constraints\NotBlank
;
16 use Symfony\Component\Validator\Constraints\Time
;
18 use Rapsys\AirBundle\Entity\Location
;
19 use Rapsys\AirBundle\Entity\User
;
21 class SessionType
extends AbstractType
{
28 public function __construct(RegistryInterface
$doctrine) {
29 $this->doctrine
= $doctrine;
35 public function buildForm(FormBuilderInterface
$builder, array $options) {
36 //Is admin or user with rainfall >= 2
37 if (!empty($options['raincancel'])) {
39 $builder->add('raincancel', SubmitType
::class, ['label' => 'Rain cancel', 'attr' => ['class' => 'submit']]);
41 } elseif (!empty($options['admin'])) {
42 //Add forcecancel item
43 $builder->add('forcecancel', SubmitType
::class, ['label' => 'Force cancel', 'attr' => ['class' => 'submit']]);
47 if (!empty($options['modify'])) {
48 if (!empty($options['admin'])) {
49 $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 Date(['message' => 'Your date doesn\'t seems to be valid'])]]);
53 //TODO: avertissement + minimum et maximum ???
54 ->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'])]])
55 //TODO: avertissement + minimum et maximum ???
56 ->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'])]])
57 ->add('modify', SubmitType
::class, ['label' => 'Modify', 'attr' => ['class' => 'submit']]);
60 //Is admin or applicant
61 if (!empty($options['cancel'])) {
62 $builder->add('cancel', SubmitType
::class, ['label' => 'Cancel', 'attr' => ['class' => 'submit']]);
65 //Is admin or senior owner
66 if (!empty($options['move'])) {
68 $locations = $this->doctrine
->getRepository(Location
::class)->findComplementBySessionId($options['session']);
70 //TODO: class senior en orange ???
71 ->add('location', ChoiceType
::class, ['attr' => ['placeholder' => 'Your location'], 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'choices' => $locations, 'choice_translation_domain' => true])
72 ->add('move', SubmitType
::class, ['label' => 'Move', 'attr' => ['class' => 'submit']]);
75 //Add extra user field
76 if (!empty($options['admin'])) {
78 $users = $this->doctrine
->getRepository(User
::class)->findAllApplicantBySession($options['session']);
81 //TODO: class admin en rouge ???
82 ->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])
83 ->add('lock', SubmitType
::class, ['label' => 'Lock', 'attr' => ['class' => 'submit']]);
85 //Is admin and locked === null
86 if (!empty($options['attribute'])) {
87 //Add attribute fields
89 ->add('attribute', SubmitType
::class, ['label' => 'Attribute', 'attr' => ['class' => 'submit']])
90 ->add('autoattribute', SubmitType
::class, ['label' => 'Auto attribute', 'attr' => ['class' => 'submit']]);
101 public function configureOptions(OptionsResolver
$resolver) {
102 $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]);
103 $resolver->setAllowedTypes('admin', 'boolean');
104 #TODO: voir si c'est le bon type
105 $resolver->setAllowedTypes('date', 'datetime');
106 $resolver->setAllowedTypes('begin', 'datetime');
107 $resolver->setAllowedTypes('length', 'datetime');
108 $resolver->setAllowedTypes('cancel', 'boolean');
109 $resolver->setAllowedTypes('raincancel', 'boolean');
110 $resolver->setAllowedTypes('modify', 'boolean');
111 $resolver->setAllowedTypes('move', 'boolean');
112 $resolver->setAllowedTypes('attribute', 'boolean');
113 $resolver->setAllowedTypes('user', 'integer');
114 $resolver->setAllowedTypes('session', 'integer');
120 public function getName() {
121 return 'rapsys_air_session_edit';