Projekt

Obecné

Profil

Stáhnout (2.54 KB) Statistiky
| Větev: | Revize:
1
<?php
2

    
3
namespace App\Form;
4

    
5
use App\Utils\Utils;
6
use App\Entity\DataSet;
7
use App\Repository\IOpenDataManager;
8
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
    /**
17
     * @var IOpenDataManager autowired connection to database
18
     */
19
    private $manager;
20

    
21
    /**
22
     * @param IOpenDataManager autowired connection to database
23
     */
24
    public function __construct(IOpenDataManager $manager) {
25
        $this->manager = $manager;
26
    }
27

    
28
    /**
29
     * @see https://symfony.com/doc/current/forms.html
30
     */
31
    public function buildForm(FormBuilderInterface $builder, array $options) {
32
        $builder
33
            ->add('date', TextType::class)
34
            // Populate time select with data
35
            ->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
            // Populet type select with data
64
            ->add('type', ChoiceType::class, [
65
                'choices' => Utils::prepareDatasetsNames($this->manager->getAvailableCollections()),
66
            ])
67
            ->add('submit', SubmitType::class);
68
    }
69

    
70
    /**
71
     * @see https://symfony.com/doc/current/forms.html
72
     */
73
    public function configureOptions(OptionsResolver $resolver) {
74
        $resolver->setDefaults([
75
            'data_class' => DataSet::class,
76
            'method' => 'GET',
77
        ]);
78
    }
79
}
    (1-1/1)