1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ps2alerts\Api\Controller\Endpoint; |
4
|
|
|
|
5
|
|
|
use League\Fractal\Manager; |
6
|
|
|
use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController; |
7
|
|
|
use Ps2alerts\Api\Repository\AlertRepository; |
8
|
|
|
use Ps2alerts\Api\Transformer\AlertTotalTransformer; |
9
|
|
|
use Ps2alerts\Api\Transformer\AlertTransformer; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
|
13
|
|
|
class AlertEndpointController extends AbstractEndpointController |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Construct |
17
|
|
|
* |
18
|
|
|
* @param Ps2alerts\Api\Repository\AlertRepository $repository |
19
|
|
|
* @param Ps2alerts\Api\Transformer\AlertTransformer $transformer |
20
|
|
|
* @param League\Fractal\Manager $fractal |
21
|
|
|
*/ |
22
|
|
|
public function __construct( |
23
|
|
|
AlertRepository $repository, |
24
|
|
|
AlertTransformer $transformer, |
25
|
|
|
Manager $fractal |
26
|
|
|
) { |
27
|
|
|
$this->repository = $repository; |
28
|
|
|
$this->transformer = $transformer; |
29
|
|
|
$this->fractal = $fractal; |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Returns a single alert's information |
34
|
|
|
* |
35
|
|
|
* @see AbstractEndpointController::respondWithItem |
36
|
|
|
* |
37
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request |
38
|
|
|
* @param Symfony\Component\HttpFoundation\Response $response |
39
|
|
|
* @param array $args |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getSingle(Request $request, Response $response, array $args) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$alert = $this->repository->readSingleById($args['id']); |
46
|
|
|
|
47
|
|
|
if (empty($alert)) { |
48
|
|
|
return $this->errorEmpty($response); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->respond('item', $alert, $this->transformer, $request, $response); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getActives(Request $request, Response $response) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$actives = $this->repository->readAllByFields(['InProgress', 1]); |
57
|
|
|
|
58
|
|
|
if (empty($actives)) { |
59
|
|
|
return $this->errorEmpty($response); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->respond('collection', $actives, $this->transformer, $request, $response); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the victories of each faction and the totals |
67
|
|
|
* |
68
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request |
69
|
|
|
* @param Symfony\Component\HttpFoundation\Response $response |
70
|
|
|
* @param array $args |
|
|
|
|
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function getVictories(Request $request, Response $response) |
75
|
|
|
{ |
76
|
|
|
$counts = [ |
77
|
|
|
'vs' => $this->repository->readCountByFields(['ResultWinner' => 'VS', 'Valid' => 1]), |
78
|
|
|
'nc' => $this->repository->readCountByFields(['ResultWinner' => 'NC', 'Valid' => 1]), |
79
|
|
|
'tr' => $this->repository->readCountByFields(['ResultWinner' => 'TR', 'Valid' => 1]), |
80
|
|
|
'draw' => $this->repository->readCountByFields(['ResultDraw' => 1, 'Valid' => 1]), |
81
|
|
|
'total' => $this->repository->readCountByFields(['Valid' => 1]) |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
if (empty($counts['total'])) { |
85
|
|
|
return $this->errorEmpty($response); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this->respond('item', $counts, new AlertTotalTransformer, $request, $response); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns the dominations of each faction and the totals |
93
|
|
|
* |
94
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request |
95
|
|
|
* @param Symfony\Component\HttpFoundation\Response $response |
96
|
|
|
* |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function getDominations(Request $request, Response $response) |
100
|
|
|
{ |
101
|
|
|
$counts = [ |
102
|
|
|
'vs' => $this->repository->readCountByFields(['ResultWinner' => 'VS', 'Valid' => 1, 'ResultDomination' => 1]), |
103
|
|
|
'nc' => $this->repository->readCountByFields(['ResultWinner' => 'NC', 'Valid' => 1, 'ResultDomination' => 1]), |
104
|
|
|
'tr' => $this->repository->readCountByFields(['ResultWinner' => 'TR', 'Valid' => 1, 'ResultDomination' => 1]), |
105
|
|
|
'total' => $this->repository->readCountByFields(['Valid' => 1, 'ResultDomination' => 1]) |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
if (empty($counts['total'])) { |
109
|
|
|
return $this->errorEmpty($response); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $this->respond('item', $counts, new AlertTotalTransformer, $request, $response); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..