Projekt

Obecné

Profil

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

    
3
namespace App\Form\Type;
4

    
5
use App\Utils\Utils;
6
use App\Entity\DataSet;
7
use App\OpenData\IOpenDataManager;
8
use Symfony\Component\Form\FormView;
9
use Symfony\Component\Form\AbstractType;
10
use Symfony\Component\Form\FormInterface;
11
use Symfony\Component\Form\FormBuilderInterface;
12
use Symfony\Component\OptionsResolver\OptionsResolver;
13
use Symfony\Component\Form\Extension\Core\Type\TextType;
14
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
15
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
16

    
17
class DataSetType extends AbstractType {
18
    private $manager;
19

    
20
    public function __construct(IOpenDataManager $manager) {
21
        $this->manager = $manager;
22
    }
23

    
24
    public function buildForm(FormBuilderInterface $builder, array $options) {
25
        $selectTypeData = null == $options['data']->getDate() ?
26
            Utils::prepareDatasetsNames($this->manager->getAvailableCollections()) :
27
            $this->manager->getAvailableCollectionsByDay($options['data']->getDate());
28

    
29
        $builder
30
            ->add('date', TextType::class)
31
            ->add('time', ChoiceType::class, [
32
                'choices' => [
33
                    '0:00-1:00' => 0,
34
                    '1:00-2:00' => 1,
35
                    '2:00-3:00' => 2,
36
                    '3:00-4:00' => 3,
37
                    '4:00-5:00' => 4,
38
                    '5:00-6:00' => 5,
39
                    '6:00-7:00' => 6,
40
                    '7:00-8:00' => 7,
41
                    '8:00-9:00' => 8,
42
                    '9:00-10:00' => 9,
43
                    '10:00-11:00' => 10,
44
                    '11:00-12:00' => 11,
45
                    '12:00-13:00' => 12,
46
                    '13:00-14:00' => 13,
47
                    '14:00-15:00' => 14,
48
                    '15:00-16:00' => 15,
49
                    '16:00-17:00' => 16,
50
                    '17:00-18:00' => 17,
51
                    '18:00-19:00' => 18,
52
                    '19:00-20:00' => 19,
53
                    '20:00-21:00' => 20,
54
                    '21:00-22:00' => 21,
55
                    '22:00-23:00' => 22,
56
                    '23:00-0:00' => 23,
57
                ],
58
            ])
59
            ->add('type', ChoiceType::class, [
60
                'choices' => $selectTypeData,
61
            ])
62
            ->add('submit', SubmitType::class);
63
    }
64

    
65
    public function configureOptions(OptionsResolver $resolver) {
66
        $resolver->setDefaults([
67
            'data_class' => DataSet::class,
68
            'method' => 'GET',
69
        ]);
70
    }
71

    
72
    // public function buildView(FormView $view, Forminterface $form, array $options) {
73

    
74
    // }
75
}
    (1-1/1)