|
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_dna implements apiEndpoint
|
|
20
|
|
|
{
|
|
21
|
|
|
public function getDescription()
|
|
22
|
|
|
{
|
|
23
|
|
|
return array("type" => "description", "message" =>
|
|
24
|
|
|
"Outputs fitting DNA for all ships killed."
|
|
25
|
|
|
);
|
|
26
|
|
|
}
|
|
27
|
|
|
|
|
28
|
|
|
public function getAcceptedParameters()
|
|
29
|
|
|
{
|
|
30
|
|
|
return array("type" => "parameters", "parameters" =>
|
|
31
|
|
|
array(
|
|
32
|
|
|
"page" => "Pagination.",
|
|
33
|
|
|
"killID" => "Get only data for a single kill."
|
|
34
|
|
|
)
|
|
35
|
|
|
);
|
|
36
|
|
|
}
|
|
37
|
|
|
|
|
38
|
|
|
public function execute($parameters)
|
|
39
|
|
|
{
|
|
40
|
|
|
$page = isset($parameters["page"]) ? $parameters["page"] : 1;
|
|
41
|
|
|
if(isset($parameters["killID"]))
|
|
42
|
|
|
$killIDs[] = (int) $parameters["killID"];
|
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
if(!isset($killIDs))
|
|
45
|
|
|
{
|
|
46
|
|
|
$kills = Feed::getKills(array("limit" => 1000, "cacheTime" => 3600, "page" => $page));
|
|
47
|
|
|
foreach($kills as $kill)
|
|
48
|
|
|
{
|
|
49
|
|
|
$kill = json_decode($kill, true);
|
|
50
|
|
|
$killIDs[] = (int) $kill["killID"];
|
|
|
|
|
|
|
51
|
|
|
}
|
|
52
|
|
|
}
|
|
53
|
|
|
return self::json_data($killIDs);
|
|
54
|
|
|
}
|
|
55
|
|
|
|
|
56
|
|
|
private function json_data($killIDs)
|
|
57
|
|
|
{
|
|
58
|
|
|
$dna = array();
|
|
59
|
|
|
foreach($killIDs as $killID)
|
|
60
|
|
|
{
|
|
61
|
|
|
$killdata = Kills::getKillDetails($killID);
|
|
62
|
|
|
$dna[] = array(
|
|
63
|
|
|
"killtime" => $killdata["info"]["dttm"],
|
|
64
|
|
|
"SolarSystemName" => $killdata["info"]["solarSystemName"],
|
|
65
|
|
|
"solarSystemID" => $killdata["info"]["solarSystemID"],
|
|
66
|
|
|
"regionID" => $killdata["info"]["regionID"],
|
|
67
|
|
|
"regionName" => $killdata["info"]["regionName"],
|
|
68
|
|
|
"victimCharacterID" => isset($killdata["victim"]["characterID"]) ? $killdata["victim"]["characterID"] : null,
|
|
69
|
|
|
"victimCharacterName" => isset($killdata["victim"]["characterName"]) ? $killdata["victim"]["characterName"] : null,
|
|
70
|
|
|
"victimCorporationID" => isset($killdata["victim"]["corporationID"]) ? $killdata["victim"]["corporationID"] : null,
|
|
71
|
|
|
"victimCorporationName" => isset($killdata["victim"]["corporationName"]) ? $killdata["victim"]["corporationName"] : null,
|
|
72
|
|
|
"victimAllianceID" => isset($killdata["victim"]["allianceID"]) ? $killdata["victim"]["allianceID"] : null,
|
|
73
|
|
|
"victimAllianceName" => isset($killdata["victim"]["allianceName"]) ? $killdata["victim"]["allianceName"] : null,
|
|
74
|
|
|
"victimFactionID" => isset($killdata["victim"]["factionID"]) ? $killdata["victim"]["factionID"] : null,
|
|
75
|
|
|
"victimFactionName" => isset($killdata["victim"]["factionName"]) ? $killdata["victim"]["factionName"] : null,
|
|
76
|
|
|
"dna" => Fitting::DNA($killdata["items"], $killdata["victim"]["shipTypeID"])
|
|
77
|
|
|
);
|
|
78
|
|
|
}
|
|
79
|
|
|
return $dna;
|
|
80
|
|
|
}
|
|
81
|
|
|
}
|
|
82
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.