|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// @todo Go over this ENTIRE file again as there's been major refactors since and it's likely broken! |
|
4
|
|
|
|
|
5
|
|
|
namespace Ps2alerts\Api\Controller\Endpoint\Leaderboards; |
|
6
|
|
|
|
|
7
|
|
|
use Ps2alerts\Api\Repository\Metrics\OutfitTotalRepository; |
|
8
|
|
|
use Ps2alerts\Api\Transformer\Leaderboards\OutfitLeaderboardTransformer; |
|
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
10
|
|
|
|
|
11
|
|
|
class LeaderboardOutfitEndpointController extends AbstractLeaderboardEndpointController |
|
12
|
|
|
{ |
|
13
|
|
|
protected $repository; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Construct |
|
17
|
|
|
* |
|
18
|
|
|
* @param League\Fractal\Manager $fractal |
|
|
|
|
|
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct( |
|
21
|
|
|
OutfitTotalRepository $repository |
|
22
|
|
|
) { |
|
23
|
|
|
$this->repository = $repository; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get Outfit Leaderboard |
|
28
|
|
|
* |
|
29
|
|
|
* @return ResponseInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
public function outfits() |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$valid = $this->validateRequestVars(); |
|
34
|
|
|
|
|
35
|
|
|
// If validation didn't pass, chuck 'em out |
|
36
|
|
|
if ($valid !== true) { |
|
37
|
|
|
return $this->respondWithError($valid->getMessage(), self::CODE_WRONG_ARGS); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$server = $_GET['server']; |
|
41
|
|
|
$limit = $_GET['limit']; |
|
42
|
|
|
$offset = $_GET['offset']; |
|
43
|
|
|
|
|
44
|
|
|
// Translate field into table specific columns |
|
45
|
|
|
|
|
46
|
|
|
if (isset($_GET['field'])) { |
|
47
|
|
|
$field = $this->getField($_GET['field']); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if (! isset($field)) { |
|
51
|
|
|
return $this->respondWithError('Field wasn\'t provided and is required.', self::CODE_WRONG_ARGS); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// Perform Query |
|
55
|
|
|
$query = $this->repository->newQuery(); |
|
56
|
|
|
$query->cols(['*']); |
|
57
|
|
|
$query->orderBy(["{$field} desc"]); |
|
58
|
|
|
$query->where('outfitID > 0'); |
|
59
|
|
|
|
|
60
|
|
|
if (isset($server)) { |
|
61
|
|
|
$query->where('outfitServer = ?', $server); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (isset($limit)) { |
|
65
|
|
|
$query->limit($limit); |
|
66
|
|
|
} else { |
|
67
|
|
|
$query->limit(10); // Set default limit |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (isset($offset)) { |
|
71
|
|
|
$query->offset($offset); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->respond( |
|
75
|
|
|
'collection', |
|
76
|
|
|
$this->repository->fireStatementAndReturn($query), |
|
77
|
|
|
new OutfitLeaderboardTransformer |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Gets the appropiate field for the table and handles some table naming oddities |
|
83
|
|
|
* @param string $input Field to look at |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
View Code Duplication |
public function getField($input) { |
|
|
|
|
|
|
87
|
|
|
$field = null; |
|
88
|
|
|
switch ($input) { |
|
89
|
|
|
case 'kills': |
|
90
|
|
|
$field = 'outfitKills'; |
|
91
|
|
|
break; |
|
92
|
|
|
case 'deaths': |
|
93
|
|
|
$field = 'outfitDeaths'; |
|
94
|
|
|
break; |
|
95
|
|
|
case 'teamkills': |
|
96
|
|
|
$field = 'outfitTKs'; |
|
97
|
|
|
break; |
|
98
|
|
|
case 'suicides': |
|
99
|
|
|
$field = 'outfitSuicides'; |
|
100
|
|
|
break; |
|
101
|
|
|
case 'captures': |
|
102
|
|
|
$field = 'outfitCaptures'; |
|
103
|
|
|
break; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $field; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.