Projekt

Obecné

Profil

Stáhnout (2.53 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
        
26
        $selectTypeData = $options['data']->getDate() == null ?
27
            Utils::prepareDatasetsNames($this->manager->getAvailableCollections()) :
28
            $this->manager->getAvailableCollectionsByDay($options['data']->getDate());
29
        
30
        $builder
31
            ->add('date', TextType::class)
32
            ->add('time', ChoiceType::class, [
33
                'choices' => [
34
                    '0:00-1:00' => 0,
35
                    '1:00-2:00' => 1,
36
                    '2:00-3:00' => 2,
37
                    '3:00-4:00' => 3,
38
                    '4:00-5:00' => 4,
39
                    '5:00-6:00' => 5,
40
                    '6:00-7:00' => 6,
41
                    '7:00-8:00' => 7,
42
                    '8:00-9:00' => 8,
43
                    '9:00-10:00' => 9,
44
                    '10:00-11:00' => 10,
45
                    '11:00-12:00' => 11,
46
                    '12:00-13:00' => 12,
47
                    '13:00-14:00' => 13,
48
                    '14:00-15:00' => 14,
49
                    '15:00-16:00' => 15,
50
                    '16:00-17:00' => 16,
51
                    '17:00-18:00' => 17,
52
                    '18:00-19:00' => 18,
53
                    '19:00-20:00' => 19,
54
                    '20:00-21:00' => 20,
55
                    '21:00-22:00' => 21,
56
                    '22:00-23:00' => 22,
57
                    '23:00-0:00' => 23,
58
                ],
59
            ])
60
            ->add('type', ChoiceType::class, [
61
                'choices' => $selectTypeData,
62
            ])
63
            ->add('submit', SubmitType::class);
64
    }
65

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

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

    
75
    // }
76
}
    (1-1/1)