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\SubmitType
;
9 use Symfony\Component\Form\Extension\Core\Type\TimeType
;
10 use Symfony\Component\Form\FormBuilderInterface
;
11 use Symfony\Component\OptionsResolver\OptionsResolver
;
12 use Symfony\Component\Translation\TranslatorInterface
;
13 use Symfony\Component\Validator\Constraints\NotBlank
;
14 use Symfony\Component\Validator\Constraints\Time
;
15 use Rapsys\AirBundle\Entity\User
;
16 use Rapsys\AirBundle\Entity\Location
;
18 class SessionEditType
extends AbstractType
{
25 public function __construct(RegistryInterface
$doctrine) {
26 $this->doctrine
= $doctrine;
32 public function buildForm(FormBuilderInterface
$builder, array $options) {
33 //Is admin or user with rainfall >= 2
34 if (!empty($options['raincancel'])) {
36 $builder->add('raincancel', SubmitType
::class, ['label' => 'Rain cancel', 'attr' => ['class' => 'submit']]);
38 } elseif (!empty($options['admin'])) {
39 //Add forcecancel item
40 $builder->add('forcecancel', SubmitType
::class, ['label' => 'Force cancel', 'attr' => ['class' => 'submit']]);
44 if (!empty($options['modify'])) {
46 //TODO: avertissement + minimum et maximum ???
47 ->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'])]])
48 //TODO: avertissement + minimum et maximum ???
49 ->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'])]])
50 ->add('modify', SubmitType
::class, ['label' => 'Modify', 'attr' => ['class' => 'submit']]);
53 //Is admin or applicant
54 if (!empty($options['cancel'])) {
55 $builder->add('cancel', SubmitType
::class, ['label' => 'Cancel', 'attr' => ['class' => 'submit']]);
58 //Is admin or senior owner
59 if (!empty($options['move'])) {
61 $locations = $this->doctrine
->getRepository(Location
::class)->findComplementBySessionId($options['session']);
63 //TODO: class senior en orange ???
64 ->add('location', ChoiceType
::class, ['attr' => ['placeholder' => 'Your location'], 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'choices' => $locations, 'choice_translation_domain' => true])
65 ->add('move', SubmitType
::class, ['label' => 'Move', 'attr' => ['class' => 'submit']]);
68 //Add extra user field
69 if (!empty($options['admin'])) {
71 $users = $this->doctrine
->getRepository(User
::class)->findAllApplicantBySession($options['session']);
74 //TODO: class admin en rouge ???
75 ->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])
76 ->add('lock', SubmitType
::class, ['label' => 'Lock', 'attr' => ['class' => 'submit']]);
78 //Is admin and locked === null
79 if (!empty($options['attribute'])) {
80 //Add attribute fields
82 ->add('attribute', SubmitType
::class, ['label' => 'Attribute', 'attr' => ['class' => 'submit']])
83 ->add('autoattribute', SubmitType
::class, ['label' => 'Auto attribute', 'attr' => ['class' => 'submit']]);
94 public function configureOptions(OptionsResolver
$resolver) {
95 $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]);
96 $resolver->setAllowedTypes('admin', 'boolean');
97 #TODO: voir si c'est le bon type
98 $resolver->setAllowedTypes('begin', 'datetime');
99 $resolver->setAllowedTypes('length', 'datetime');
100 $resolver->setAllowedTypes('cancel', 'boolean');
101 $resolver->setAllowedTypes('raincancel', 'boolean');
102 $resolver->setAllowedTypes('modify', 'boolean');
103 $resolver->setAllowedTypes('move', 'boolean');
104 $resolver->setAllowedTypes('attribute', 'boolean');
105 $resolver->setAllowedTypes('user', 'integer');
106 $resolver->setAllowedTypes('session', 'integer');
112 public function getName() {
113 return 'rapsys_air_session_edit';