1
|
|
|
<?php
|
2
|
|
|
/* zKillboard
|
3
|
|
|
* Copyright (C) 2012-2015 EVE-KILL Team and EVSCO.
|
4
|
|
|
*
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify
|
6
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
8
|
|
|
* (at your option) any later version.
|
9
|
|
|
*
|
10
|
|
|
* This program is distributed in the hope that it will be useful,
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
|
|
* GNU Affero General Public License for more details.
|
14
|
|
|
*
|
15
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
|
|
*/
|
18
|
|
|
|
19
|
|
|
class api_battles implements apiEndpoint
|
20
|
|
|
{
|
21
|
|
|
public function getDescription()
|
22
|
|
|
{
|
23
|
|
|
return array("type" => "description", "message" =>
|
24
|
|
|
"Battles lists the battles that has been sorted by users. You can list all the battles that are available, and you can call up data for a single battle."
|
25
|
|
|
);
|
26
|
|
|
}
|
27
|
|
|
|
28
|
|
|
public function getAcceptedParameters()
|
29
|
|
|
{
|
30
|
|
|
return array("type" => "parameters", "parameters" =>
|
31
|
|
|
array(
|
32
|
|
|
"list" => "Lists all the battles available to peruse.",
|
33
|
|
|
"battle/#/" => "Lists data for a single battle. Replace # with a battleID."
|
34
|
|
|
)
|
35
|
|
|
);
|
36
|
|
|
}
|
37
|
|
|
public function execute($parameters)
|
38
|
|
|
{
|
39
|
|
|
$command = isset($parameters["battles"]) ? $parameters["battles"] : NULL;
|
40
|
|
|
$battleID = isset($parameters["battle"]) ? $parameters["battle"] : 0;
|
41
|
|
|
|
42
|
|
|
if($command == "list")
|
43
|
|
|
{
|
44
|
|
|
$data = array();
|
|
|
|
|
45
|
|
|
$battles = Db::query("SELECT * FROM zz_battles", array(), 360);
|
46
|
|
|
foreach($battles as $key => $value)
|
47
|
|
|
{
|
48
|
|
|
unset($battles[$key]["teamAJson"]);
|
49
|
|
|
unset($battles[$key]["teamBJson"]);
|
50
|
|
|
}
|
51
|
|
|
return $battles;
|
52
|
|
|
}
|
53
|
|
|
elseif($command == "battle")
|
54
|
|
|
{
|
55
|
|
|
$getData = Db::queryRow("SELECT * FROM zz_battles WHERE battleID = :battleID", array(":battleID" => $battleID), 360);
|
56
|
|
|
|
57
|
|
|
foreach($getData as $key => $value)
|
58
|
|
|
{
|
59
|
|
|
switch($key)
|
60
|
|
|
{
|
61
|
|
|
case "teamAinvolved":
|
62
|
|
|
case "teamBinvolved":
|
63
|
|
|
$data[$key] = json_decode($value, true);
|
|
|
|
|
64
|
|
|
break;
|
65
|
|
|
|
66
|
|
|
case "teamAJson":
|
67
|
|
|
case "teamBJson":
|
68
|
|
|
$subJson = json_decode($value, true);
|
69
|
|
|
foreach($subJson as $d)
|
70
|
|
|
$data[$key][] = json_decode($d, true);
|
|
|
|
|
71
|
|
|
break;
|
72
|
|
|
|
73
|
|
|
default:
|
74
|
|
|
$data[$key] = $value;
|
75
|
|
|
break;
|
76
|
|
|
}
|
77
|
|
|
}
|
78
|
|
|
return $data;
|
79
|
|
|
}
|
80
|
|
|
else
|
81
|
|
|
return array(
|
82
|
|
|
"type" => "error",
|
83
|
|
|
"message" => "No valid parameter passed."
|
84
|
|
|
);
|
85
|
|
|
}
|
86
|
|
|
}
|
87
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.