This repository was archived by the owner on Feb 13, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathDataController.php
More file actions
81 lines (70 loc) · 2.46 KB
/
Copy pathDataController.php
File metadata and controls
81 lines (70 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace DB\StatisticBundle\Controller;
use DB\StatisticBundle\Exception\ApiException;
use DB\StatisticBundle\Manager\GraphManager;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class DataController extends Controller
{
public function indexAction(Request $request, $graphID)
{
$response = new JsonResponse();
/** @var GraphManager $graphManager */
$graphManager = $this->get('db.statistic.manager');
$graph = null;
try {
$graph = $graphManager->getGraphWithID($graphID, $request->query->all())->encode();
$statusResponse = array(
'code' => 200,
'graph_id' => $graphID
);
} catch (ApiException $e) {
$e->setGraphID($graphID);
$statusResponse = $e->encode();
}
$response->setData(array(
"status" => $statusResponse,
"graph" => $graph
));
$response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
return $response;
}
public function multipleAction(Request $request)
{
$response = new JsonResponse();
/** @var GraphManager $graphManager */
$graphManager = $this->get('db.statistic.manager');
$statusCode = 200;
$graphs = array();
foreach ($request->query->all() as $key => $value) {
if (substr( $key, 0, 2 ) !== "id")
continue;
try {
$graphs[$key] = array(
"status" => array(
'code' => 200,
'graph_id' => $value
),
"graph" => $graphManager->getGraphWithID($value, $request->query->all())->encode()
);
} catch (ApiException $e) {
$statusCode = 201;
$e->setGraphID($value);
$graphs[$key] = array(
"status" => $e->encode(),
"graph" => null
);
}
}
$dataResponse = array(
'status' => array(
'code' => $statusCode
),
'graphs' => $graphs
);
$response->setData($dataResponse);
$response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
return $response;
}
}