|
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_stats implements apiEndpoint
|
|
20
|
|
|
{
|
|
21
|
|
|
public function getDescription()
|
|
22
|
|
|
{
|
|
23
|
|
|
return array("type" => "description", "message" =>
|
|
24
|
|
|
"Shows stats for an entity"
|
|
25
|
|
|
);
|
|
26
|
|
|
}
|
|
27
|
|
|
|
|
28
|
|
|
public function getAcceptedParameters()
|
|
29
|
|
|
{
|
|
30
|
|
|
return array("type" => "parameters", "parameters" =>
|
|
31
|
|
|
array(
|
|
32
|
|
|
"characterID" => "Get stats for a certain characterID.",
|
|
33
|
|
|
"corporationID" => "Get stats for a certain corporationID.",
|
|
34
|
|
|
"allianceID" => "Get stats for a certain allianceID.",
|
|
35
|
|
|
"factionID" => "Get stats for a certain factionID.",
|
|
36
|
|
|
"shipTypeID" => "Get stats for a certain ship.",
|
|
37
|
|
|
"groupID" => "Get stats for a certain group of ships.",
|
|
38
|
|
|
"solarSystemID" => "Get stats for a certain solarsystem",
|
|
39
|
|
|
"regionID" => "Get stats for a certain region.",
|
|
40
|
|
|
"recent" => "Show recent or all time stats."
|
|
41
|
|
|
)
|
|
42
|
|
|
);
|
|
43
|
|
|
}
|
|
44
|
|
|
|
|
45
|
|
|
public function execute($parameters)
|
|
46
|
|
|
{
|
|
47
|
|
|
// Map calls to the internal names.
|
|
48
|
|
|
$mapping = array(
|
|
49
|
|
|
"factionID" => "faction",
|
|
50
|
|
|
"allianceID" => "alli",
|
|
51
|
|
|
"corporationID" => "corp",
|
|
52
|
|
|
"characterID" => "pilot",
|
|
53
|
|
|
"groupID" => "group",
|
|
54
|
|
|
"shipTypeID" => "ship",
|
|
55
|
|
|
"solarSystemID" => "system",
|
|
56
|
|
|
"regionID" => "region"
|
|
57
|
|
|
);
|
|
58
|
|
|
|
|
59
|
|
|
$allowed_types = array(
|
|
60
|
|
|
"factionID",
|
|
61
|
|
|
"allianceID",
|
|
62
|
|
|
"corporationID",
|
|
63
|
|
|
"characterID",
|
|
64
|
|
|
"groupID",
|
|
65
|
|
|
"shipTypeID",
|
|
66
|
|
|
"solarSystemID",
|
|
67
|
|
|
"regionID"
|
|
68
|
|
|
);
|
|
69
|
|
|
|
|
70
|
|
|
$statsTable = isset($parameters["recent"]) ? "zz_stats_recent" : "zz_stats";
|
|
71
|
|
|
|
|
72
|
|
|
foreach($parameters as $key => $value)
|
|
73
|
|
|
if(!in_array($key, $allowed_types))
|
|
74
|
|
|
unset($parameters[$key]);
|
|
75
|
|
|
|
|
76
|
|
|
foreach($parameters as $key => $value)
|
|
77
|
|
|
{
|
|
78
|
|
|
$flag = $key;
|
|
79
|
|
|
$id = $value[0];
|
|
80
|
|
|
}
|
|
81
|
|
|
|
|
82
|
|
|
$type = isset($flag) ? $mapping[$flag] : null;
|
|
83
|
|
|
|
|
84
|
|
|
if(!$type)
|
|
|
|
|
|
|
85
|
|
|
return array(
|
|
86
|
|
|
"type" => "error",
|
|
87
|
|
|
"message" => "Please use a valid type."
|
|
88
|
|
|
);
|
|
89
|
|
|
|
|
90
|
|
|
$stat_totals = Db::queryRow('SELECT SUM(destroyed) AS countDestroyed, SUM(lost) AS countLost, SUM(pointsDestroyed) AS pointsDestroyed, SUM(pointsLost) AS pointsLost, SUM(iskDestroyed) AS iskDestroyed, SUM(iskLost) AS iskLost FROM ' . $statsTable . ' WHERE type = :type AND typeID = :id', array(':type' => $type, ':id' => $id));
|
|
|
|
|
|
|
91
|
|
|
$stat_details = Db::query('SELECT groupID, destroyed AS countDestroyed, lost AS countLost, pointsDestroyed, pointsLost, iskDestroyed, iskLost FROM ' . $statsTable . ' WHERE type = :type AND typeID = :id', array(':type' => $type, ':id' => $id));
|
|
92
|
|
|
|
|
93
|
|
|
$output = array();
|
|
94
|
|
|
$output["totals"] = $stat_totals;
|
|
95
|
|
|
foreach($stat_details as $detail)
|
|
96
|
|
|
$output["groups"][array_shift($detail)] = $detail;
|
|
97
|
|
|
|
|
98
|
|
|
$characterID = isset($parameters["characterID"][0]) ? $parameters["characterID"][0] : NULL;
|
|
99
|
|
|
$corporationID = isset($parameters["corporationID"][0]) ? $parameters["corporationID"][0] : Info::getCharacterAffiliations($characterID)["corporationID"];
|
|
100
|
|
|
$verified = (bool) Db::queryField("SELECT count(*) AS count FROM zz_api_characters WHERE ((characterID = :characterID AND isDirector = 'F') OR (corporationID = :corporationID AND isDirector = 'T')) AND errorCode = 0", "count", array(":characterID" => $characterID, ":corporationID" => $corporationID), 0);
|
|
101
|
|
|
$output["apiVerified"] = $verified;
|
|
102
|
|
|
|
|
103
|
|
|
return $output;
|
|
104
|
|
|
}
|
|
105
|
|
|
}
|
|
106
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: