Projekt

Obecné

Profil

Stáhnout (2.54 KB) Statistiky
| Větev: | Revize:
1 03c02899 vastja
<?php
2
3 4b6b5f1b vastja
namespace App\Form;
4 03c02899 vastja
5
use App\Utils\Utils;
6
use App\Entity\DataSet;
7 ea92a5e5 vastja
use App\Repository\IOpenDataManager;
8 03c02899 vastja
use Symfony\Component\Form\AbstractType;
9
use Symfony\Component\Form\FormBuilderInterface;
10
use Symfony\Component\OptionsResolver\OptionsResolver;
11
use Symfony\Component\Form\Extension\Core\Type\TextType;
12
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
13
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
14
15
class DataSetType extends AbstractType {
16 70a3df53 vastja
    /**
17
     * @var IOpenDataManager autowired connection to database
18
     */
19 03c02899 vastja
    private $manager;
20
21 70a3df53 vastja
    /**
22
     * @param IOpenDataManager autowired connection to database
23
     */
24 03c02899 vastja
    public function __construct(IOpenDataManager $manager) {
25
        $this->manager = $manager;
26
    }
27
28 70a3df53 vastja
    /**
29
     * @see https://symfony.com/doc/current/forms.html
30
     */
31 03c02899 vastja
    public function buildForm(FormBuilderInterface $builder, array $options) {
32
        $builder
33
            ->add('date', TextType::class)
34 70a3df53 vastja
            // Populate time select with data
35 03c02899 vastja
            ->add('time', ChoiceType::class, [
36
                'choices' => [
37
                    '0:00-1:00' => 0,
38
                    '1:00-2:00' => 1,
39
                    '2:00-3:00' => 2,
40
                    '3:00-4:00' => 3,
41
                    '4:00-5:00' => 4,
42
                    '5:00-6:00' => 5,
43
                    '6:00-7:00' => 6,
44
                    '7:00-8:00' => 7,
45
                    '8:00-9:00' => 8,
46
                    '9:00-10:00' => 9,
47
                    '10:00-11:00' => 10,
48
                    '11:00-12:00' => 11,
49
                    '12:00-13:00' => 12,
50
                    '13:00-14:00' => 13,
51
                    '14:00-15:00' => 14,
52
                    '15:00-16:00' => 15,
53
                    '16:00-17:00' => 16,
54
                    '17:00-18:00' => 17,
55
                    '18:00-19:00' => 18,
56
                    '19:00-20:00' => 19,
57
                    '20:00-21:00' => 20,
58
                    '21:00-22:00' => 21,
59
                    '22:00-23:00' => 22,
60
                    '23:00-0:00' => 23,
61
                ],
62
            ])
63 70a3df53 vastja
            // Populet type select with data
64 03c02899 vastja
            ->add('type', ChoiceType::class, [
65 5d599617 vastja
                'choices' => Utils::prepareDatasetsNames($this->manager->getAvailableCollections()),
66 03c02899 vastja
            ])
67
            ->add('submit', SubmitType::class);
68
    }
69
70 70a3df53 vastja
    /**
71
     * @see https://symfony.com/doc/current/forms.html
72
     */
73 03c02899 vastja
    public function configureOptions(OptionsResolver $resolver) {
74
        $resolver->setDefaults([
75
            'data_class' => DataSet::class,
76 896f0d9c vastja
            'method' => 'GET',
77 03c02899 vastja
        ]);
78
    }
79
}