|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Overwatch\ResultBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
|
6
|
|
|
use Overwatch\TestBundle\Entity\Test; |
|
7
|
|
|
use Overwatch\TestBundle\Entity\TestGroup; |
|
8
|
|
|
use Overwatch\TestBundle\Security\TestGroupVoter; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* ApiController |
|
19
|
|
|
* Handles API request made for Result |
|
20
|
|
|
* @Route("/api/results") |
|
21
|
|
|
*/ |
|
22
|
|
|
class ApiController extends Controller |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Returns the latest results from across all tests |
|
26
|
|
|
* |
|
27
|
|
|
* @Route("") |
|
28
|
|
|
* @Method({"GET"}) |
|
29
|
|
|
* @Security("has_role('ROLE_SUPER_ADMIN')") |
|
30
|
|
|
* @ApiDoc( |
|
31
|
|
|
* resource=true, |
|
32
|
|
|
* filters={ |
|
33
|
|
|
* {"name"="pageSize", "description"="How many results to return per page","type"="Integer","default"=10,"maximum"=100}, |
|
34
|
|
|
* {"name"="page", "description"="The page number to return results from","type"="Integer","default"=1} |
|
35
|
|
|
* }, |
|
36
|
|
|
* tags={ |
|
37
|
|
|
* "Super Admin" = "#ff1919" |
|
38
|
|
|
* } |
|
39
|
|
|
* ) |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function getResultsAction(Request $request) |
|
42
|
|
|
{ |
|
43
|
1 |
|
$size = $request->query->get('pageSize', 10); |
|
44
|
|
|
|
|
45
|
1 |
|
$results = $this->getEntityRepository('OverwatchResultBundle:TestResult')->getResults( |
|
46
|
1 |
|
[], |
|
47
|
1 |
|
($size >= 100) ? 10 : $size, |
|
48
|
1 |
|
$request->query->get('page', 1) |
|
49
|
1 |
|
); |
|
50
|
|
|
|
|
51
|
1 |
|
return new JsonResponse($results); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns the latest results for each test in the requested group |
|
56
|
|
|
* |
|
57
|
|
|
* @Route("/group/{id}") |
|
58
|
|
|
* @Method({"GET"}) |
|
59
|
|
|
* @Security("is_granted('view', group)") |
|
60
|
|
|
* @ApiDoc( |
|
61
|
|
|
* requirements={ |
|
62
|
|
|
* {"name"="id", "description"="The ID of the group for which to return results for", "dataType"="integer", "requirement"="\d+"} |
|
63
|
|
|
* }, |
|
64
|
|
|
* filters={ |
|
65
|
|
|
* {"name"="pageSize", "description"="How many results to return per test per page","type"="Integer","default"=10,"maximum"=100}, |
|
66
|
|
|
* {"name"="page", "description"="The page number to return results from","type"="Integer","default"=1} |
|
67
|
|
|
* }, |
|
68
|
|
|
* tags={ |
|
69
|
|
|
* "Super Admin" = "#ff1919", |
|
70
|
|
|
* "Admin" = "#ffff33", |
|
71
|
|
|
* "User" = "#75ff47" |
|
72
|
|
|
* } |
|
73
|
|
|
* ) |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function getRecentGroupResultsAction(TestGroup $group, Request $request) |
|
76
|
|
|
{ |
|
77
|
1 |
|
$results = []; |
|
78
|
1 |
|
$size = $request->query->get('pageSize', 10); |
|
79
|
|
|
|
|
80
|
1 |
|
foreach ($group->getTests()->toArray() as $test) { |
|
81
|
1 |
|
$results[] = $this->getEntityRepository('OverwatchResultBundle:TestResult')->getResults( |
|
82
|
|
|
[ |
|
83
|
|
|
'test' => $test |
|
84
|
1 |
|
], |
|
85
|
1 |
|
($size >= 100) ? 10 : $size, |
|
86
|
1 |
|
$request->query->get('page', 1) |
|
87
|
1 |
|
); |
|
88
|
1 |
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
return new JsonResponse($results); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns the latest results for the given test |
|
95
|
|
|
* |
|
96
|
|
|
* @Route("/test/{id}") |
|
97
|
|
|
* @Method({"GET"}) |
|
98
|
|
|
* @ApiDoc( |
|
99
|
|
|
* filters={ |
|
100
|
|
|
* {"name"="pageSize", "description"="How many results to return per page","type"="Integer","default"=10,"maximum"=100}, |
|
101
|
|
|
* {"name"="page", "description"="The page number to return results from","type"="Integer","default"=1} |
|
102
|
|
|
* }, |
|
103
|
|
|
* requirements={ |
|
104
|
|
|
* {"name"="id", "description"="The ID of the test for which to return results for", "dataType"="integer", "requirement"="\d+"} |
|
105
|
|
|
* }, |
|
106
|
|
|
* tags={ |
|
107
|
|
|
* "Super Admin" = "#ff1919", |
|
108
|
|
|
* "Admin" = "#ffff33", |
|
109
|
|
|
* "User" = "#75ff47" |
|
110
|
|
|
* } |
|
111
|
|
|
* ) |
|
112
|
|
|
*/ |
|
113
|
2 |
|
public function getResultsForTestAction(Request $request, Test $test) |
|
114
|
|
|
{ |
|
115
|
2 |
|
if (!$this->isGranted(TestGroupVoter::VIEW, $test->getGroup())) { |
|
116
|
1 |
|
throw new AccessDeniedHttpException('You must be a member of this test\'s group to see it\'s results'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
$size = $request->query->get('pageSize', 10); |
|
120
|
|
|
|
|
121
|
1 |
|
$results = $this->getEntityRepository('OverwatchResultBundle:TestResult')->getResults( |
|
122
|
|
|
[ |
|
123
|
|
|
'test' => $test |
|
124
|
1 |
|
], |
|
125
|
1 |
|
($size >= 100) ? 10 : $size, |
|
126
|
1 |
|
$request->query->get('page', 1) |
|
127
|
1 |
|
); |
|
128
|
|
|
|
|
129
|
1 |
|
return new JsonResponse($results); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
3 |
|
private function getEntityRepository($entity) |
|
133
|
|
|
{ |
|
134
|
3 |
|
return $this->get('doctrine.orm.entity_manager')->getRepository($entity); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|