Projekt

Obecné

Profil

Stáhnout (2.46 KB) Statistiky
| Větev: | Revize:
1 3fc08f2d vastja
<?php
2
3
namespace App\Controller;
4
5 03c02899 vastja
use App\Entity\DataSet;
6
use App\Form\Type\DataSetType;
7 3fc08f2d vastja
use App\OpenData\IOpenDataManager;
8 03c02899 vastja
use Symfony\Component\HttpFoundation\Request;
9 3fc08f2d vastja
use Symfony\Component\Routing\Annotation\Route;
10
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11
12
class HeatmapController extends AbstractController {
13
    /**
14 c6708024 vastja
     * @Route("/heatmap", name="heatmap")
15 3fc08f2d vastja
     */
16 dfe43218 vastja
    public function index(Request $request, IOpenDataManager $manager) {
17 03c02899 vastja
        $dataSet = new DataSet();
18
19
        $form = $this->createForm(DataSetType::class, $dataSet);
20
        $form->handleRequest($request);
21
22 03ccdd65 vastja
        $isSubmitted = $form->isSubmitted();
23
        if ($isSubmitted) {
24 03c02899 vastja
            $dataSet = $form->getData();
25 03ccdd65 vastja
            if (false == $manager->isCollectionAvailable($dataSet->getType(), $dataSet->getDate())) {
26
                $dataSet = new DataSet();
27 dfe43218 vastja
            }
28 03ccdd65 vastja
            $form = $this->createForm(DataSetType::class, $dataSet);
29 03c02899 vastja
        }
30
31
        return $this->render(
32
            'heatmap.html.twig',
33
            [
34
                'form' => $form->createView(),
35 03ccdd65 vastja
                'submitted' => $isSubmitted,
36 64bc2934 vastja
                'data_to_display' => $dataSet,
37 03c02899 vastja
            ]
38
        );
39 3fc08f2d vastja
    }
40
41
    /**
42 64bc2934 vastja
     * @Route("heatmap/opendata/{name}/{date}/{time}", name="opendata")
43 3fc08f2d vastja
     */
44 03ccdd65 vastja
    public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '2020-01-01', $time = '1') {
45 3ae59f75 vastja
        return $this->json([
46
            'items' => $manager->getCollectionDataByName($name, $date, $time),
47
            'max' => $manager->getMaxCollectionNumberAtDay($name, $date),
48
        ]);
49 3fc08f2d vastja
    }
50 03c02899 vastja
51
    /**
52
     * @Route("heatmap/available/{date}", name="available")
53
     */
54
    public function availableDatasets(IOpenDataManager $manager, $date = '01012020') {
55
        return $this->json($manager->getAvailableCollectionsByDay($date));
56
    }
57 d8f6e6f2 vastja
58
    /**
59
     * @Route("heatmap/dates", name="dates")
60
     */
61
    public function datesWithAvailableDatasets(IOpenDataManager $manager) {
62
        return $this->json($manager->getDatesWithAvailableCollection());
63
    }
64 61ff7718 vastja
65
    /**
66
     * @Route("heatmap/positions/{name}", name="positions")
67
     */
68
    public function dataSourcePoistions(IOpenDataManager $manager, $name = 'NONE') {
69
        return $this->json($manager->getDataSourcePositions($name));
70
    }
71 72a438f3 vastja
72
    /**
73
     * @Route("heatmap/last", name="last")
74
     */
75
    public function lastAvailableCollections(IOpenDataManager $manager) {
76
        return $this->json($manager->getLastAvailableCollections());
77
    }
78 3fc08f2d vastja
}