1
|
<?php
|
2
|
|
3
|
namespace App\Controller;
|
4
|
|
5
|
use App\Entity\DataSet;
|
6
|
use App\Form\Type\DataSetType;
|
7
|
use App\OpenData\IOpenDataManager;
|
8
|
use Symfony\Component\HttpFoundation\Request;
|
9
|
use Symfony\Component\Routing\Annotation\Route;
|
10
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
11
|
|
12
|
class HeatmapController extends AbstractController {
|
13
|
/**
|
14
|
* @Route("/heatmap", name="heatmap")
|
15
|
*/
|
16
|
public function index(Request $request, IOpenDataManager $manager) {
|
17
|
$dataSet = new DataSet();
|
18
|
|
19
|
$form = $this->createForm(DataSetType::class, $dataSet);
|
20
|
$form->handleRequest($request);
|
21
|
|
22
|
$isSubmitted = $form->isSubmitted();
|
23
|
if ($isSubmitted) {
|
24
|
$dataSet = $form->getData();
|
25
|
if (false == $manager->isCollectionAvailable($dataSet->getType(), $dataSet->getDate())) {
|
26
|
$dataSet = new DataSet();
|
27
|
}
|
28
|
$form = $this->createForm(DataSetType::class, $dataSet);
|
29
|
}
|
30
|
|
31
|
return $this->render(
|
32
|
'heatmap.html.twig',
|
33
|
[
|
34
|
'form' => $form->createView(),
|
35
|
'submitted' => $isSubmitted,
|
36
|
'data_to_display' => $dataSet,
|
37
|
]
|
38
|
);
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* @Route("heatmap/opendata/{name}/{date}/{time}", name="opendata")
|
43
|
*/
|
44
|
public function opendata(IOpenDataManager $manager, $name = 'NONE', $date = '2020-01-01', $time = '1') {
|
45
|
return $this->json([
|
46
|
'items' => $manager->getCollectionDataByName($name, $date, $time),
|
47
|
'max' => $manager->getMaxCollectionNumberAtDay($name, $date),
|
48
|
]);
|
49
|
}
|
50
|
|
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
|
|
58
|
/**
|
59
|
* @Route("heatmap/dates", name="dates")
|
60
|
*/
|
61
|
public function datesWithAvailableDatasets(IOpenDataManager $manager) {
|
62
|
return $this->json($manager->getDatesWithAvailableCollection());
|
63
|
}
|
64
|
}
|