1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class QueryManagerMysqlMonocleAlternate extends QueryManagerMysql { |
|
|
|
|
4
|
|
|
|
5
|
|
|
public function __construct() { |
6
|
|
|
parent::__construct(); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
public function __destruct() { |
10
|
|
|
parent::__destruct(); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/////////// |
14
|
|
|
// Tester |
15
|
|
|
/////////// |
16
|
|
|
|
17
|
|
View Code Duplication |
function testTotalPokemon() { |
|
|
|
|
18
|
|
|
$req = "SELECT COUNT(*) as total FROM sightings"; |
19
|
|
|
$result = $this->mysqli->query($req); |
20
|
|
|
if (!is_object($result)) { |
21
|
|
|
return 1; |
22
|
|
|
} else { |
23
|
|
|
$data = $result->fetch_object(); |
24
|
|
|
$total = $data->total; |
25
|
|
|
|
26
|
|
|
if ($total == 0) { |
27
|
|
|
return 2; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
return 0; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
function testTotalGyms() { |
|
|
|
|
34
|
|
|
$req = "SELECT COUNT(*) as total FROM forts"; |
35
|
|
|
$result = $this->mysqli->query($req); |
36
|
|
|
if (!is_object($result)) { |
37
|
|
|
return 1; |
38
|
|
|
} else { |
39
|
|
|
$data = $result->fetch_object(); |
40
|
|
|
$total = $data->total; |
41
|
|
|
|
42
|
|
|
if ($total == 0) { |
43
|
|
|
return 2; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
return 0; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
function testTotalPokestops() { |
|
|
|
|
50
|
|
|
$req = "SELECT COUNT(*) as total FROM pokestops"; |
51
|
|
|
$result = $this->mysqli->query($req); |
52
|
|
|
if (!is_object($result)) { |
53
|
|
|
return 1; |
54
|
|
|
} else { |
55
|
|
|
$data = $result->fetch_object(); |
56
|
|
|
$total = $data->total; |
57
|
|
|
|
58
|
|
|
if ($total == 0) { |
59
|
|
|
return 2; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
return 0; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
///////////// |
67
|
|
|
// Homepage |
68
|
|
|
///////////// |
69
|
|
|
|
70
|
|
|
function getTotalPokemon() { |
|
|
|
|
71
|
|
|
$req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()"; |
72
|
|
|
$result = $this->mysqli->query($req); |
73
|
|
|
$data = $result->fetch_object(); |
74
|
|
|
return $data; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function getTotalLures() { |
|
|
|
|
78
|
|
|
$data = (object) array("total" => 0); |
79
|
|
|
return $data; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function getTotalGyms() { |
|
|
|
|
83
|
|
|
$req = "SELECT COUNT(*) AS total FROM forts"; |
84
|
|
|
$result = $this->mysqli->query($req); |
85
|
|
|
$data = $result->fetch_object(); |
86
|
|
|
return $data; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function getTotalRaids() { |
|
|
|
|
90
|
|
|
$req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_TIMESTAMP()"; |
91
|
|
|
$result = $this->mysqli->query($req); |
92
|
|
|
$data = $result->fetch_object(); |
93
|
|
|
return $data; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
function getTotalGymsForTeam($team_id) { |
|
|
|
|
98
|
|
|
$req = "SELECT COUNT(*) AS total |
99
|
|
|
FROM forts f |
100
|
|
|
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
101
|
|
|
WHERE team = '$team_id'"; |
102
|
|
|
$result = $this->mysqli->query($req); |
103
|
|
|
$data = $result->fetch_object(); |
104
|
|
|
return $data; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
function getRecentAll() { |
|
|
|
|
108
|
|
|
$req = "SELECT DISTINCT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
109
|
|
|
lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
110
|
|
|
FROM sightings |
111
|
|
|
ORDER BY updated DESC |
112
|
|
|
LIMIT 0,12"; |
113
|
|
|
$result = $this->mysqli->query($req); |
114
|
|
|
$data = array(); |
115
|
|
|
if ($result->num_rows > 0) { |
116
|
|
|
while ($row = $result->fetch_object()) { |
117
|
|
|
$data[] = $row; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
return $data; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
function getRecentMythic($mythic_pokemon) { |
|
|
|
|
124
|
|
|
$req = "SELECT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
125
|
|
|
lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
126
|
|
|
FROM sightings |
127
|
|
|
WHERE pokemon_id IN (".implode(",", $mythic_pokemon).") |
128
|
|
|
ORDER BY updated DESC |
129
|
|
|
LIMIT 0,12"; |
130
|
|
|
$result = $this->mysqli->query($req); |
131
|
|
|
$data = array(); |
132
|
|
|
if ($result->num_rows > 0) { |
133
|
|
|
while ($row = $result->fetch_object()) { |
134
|
|
|
$data[] = $row; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
return $data; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/////////////////// |
141
|
|
|
// Single Pokemon |
142
|
|
|
/////////////////// |
143
|
|
|
|
144
|
|
View Code Duplication |
function getGymsProtectedByPokemon($pokemon_id) { |
|
|
|
|
145
|
|
|
$req = "SELECT COUNT(f.id) AS total |
146
|
|
|
FROM forts f |
147
|
|
|
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
148
|
|
|
WHERE guard_pokemon_id = '".$pokemon_id."'"; |
149
|
|
|
$result = $this->mysqli->query($req); |
150
|
|
|
$data = $result->fetch_object(); |
151
|
|
|
return $data; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
View Code Duplication |
function getPokemonLastSeen($pokemon_id) { |
|
|
|
|
155
|
|
|
$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
156
|
|
|
FROM sightings |
157
|
|
|
WHERE pokemon_id = '".$pokemon_id."' |
158
|
|
|
ORDER BY expire_timestamp DESC |
159
|
|
|
LIMIT 0,1"; |
160
|
|
|
$result = $this->mysqli->query($req); |
161
|
|
|
$data = $result->fetch_object(); |
162
|
|
|
return $data; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) { |
|
|
|
|
166
|
|
|
$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS distime, pokemon_id as pokemon_id, FROM_UNIXTIME(expire_timestamp) as disappear_time, lat as latitude, lon as longitude, |
167
|
|
|
cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
168
|
|
|
ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1 as move_1, move_2, form |
169
|
|
|
FROM sightings |
170
|
|
|
WHERE pokemon_id = '" . $pokemon_id . "' AND move_1 IS NOT NULL AND move_1 <> '0' |
171
|
|
|
ORDER BY $top_order_by $top_direction, expire_timestamp DESC |
172
|
|
|
LIMIT 0,50"; |
173
|
|
|
|
174
|
|
|
$result = $this->mysqli->query($req); |
175
|
|
|
$top = array(); |
176
|
|
|
while ($data = $result->fetch_object()) { |
177
|
|
|
$top[] = $data; |
178
|
|
|
} |
179
|
|
|
return $top; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
View Code Duplication |
function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
|
|
|
|
183
|
|
|
$trainer_blacklist = ""; |
184
|
|
|
if (!empty(self::$config->system->trainer_blacklist)) { |
185
|
|
|
$trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')"; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
$req = "SELECT owner_name as trainer_name, ROUND((100*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS IV, move_1, move_2, cp as cp, |
189
|
|
|
FROM_UNIXTIME(last_modified) AS lasttime, last_modified as last_seen |
190
|
|
|
FROM gym_defenders |
191
|
|
|
WHERE pokemon_id = '" . $pokemon_id . "'" . $trainer_blacklist . " |
192
|
|
|
ORDER BY $best_order_by $best_direction, owner_name ASC |
193
|
|
|
LIMIT 0,50"; |
194
|
|
|
|
195
|
|
|
$result = $this->mysqli->query($req); |
196
|
|
|
$toptrainer = array(); |
197
|
|
|
while ($data = $result->fetch_object()) { |
198
|
|
|
$toptrainer[] = $data; |
199
|
|
|
} |
200
|
|
|
return $toptrainer; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
View Code Duplication |
public function getPokemonHeatmap($pokemon_id, $start, $end) { |
|
|
|
|
204
|
|
|
$where = " WHERE pokemon_id = ".$pokemon_id." " |
205
|
|
|
. "AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
206
|
|
|
$req = "SELECT lat AS latitude, lon AS longitude FROM sightings".$where." LIMIT 100000"; |
207
|
|
|
$result = $this->mysqli->query($req); |
208
|
|
|
$points = array(); |
209
|
|
|
while ($data = $result->fetch_object()) { |
210
|
|
|
$points[] = $data; |
211
|
|
|
} |
212
|
|
|
return $points; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
View Code Duplication |
public function getPokemonGraph($pokemon_id) { |
|
|
|
|
216
|
|
|
$req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour |
217
|
|
|
FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
218
|
|
|
GROUP BY disappear_hour |
219
|
|
|
ORDER BY disappear_hour"; |
220
|
|
|
$result = $this->mysqli->query($req); |
221
|
|
|
$array = array_fill(0, 24, 0); |
222
|
|
|
while ($result && $data = $result->fetch_object()) { |
223
|
|
|
$array[$data->disappear_hour] = $data->total; |
224
|
|
|
} |
225
|
|
|
// shift array because AM/PM starts at 1AM not 0:00 |
226
|
|
|
$array[] = $array[0]; |
227
|
|
|
array_shift($array); |
228
|
|
|
return $array; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
View Code Duplication |
public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
|
|
|
|
232
|
|
|
$inmap_pkms_filter = ""; |
233
|
|
|
$where = " WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = " . $pokemon_id; |
234
|
|
|
|
235
|
|
|
$reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings " . $where; |
236
|
|
|
$resultTestIv = $this->mysqli->query($reqTestIv); |
237
|
|
|
$testIv = $resultTestIv->fetch_object(); |
238
|
|
|
if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) { |
239
|
|
|
foreach ($inmap_pokemons as $inmap) { |
240
|
|
|
$inmap_pkms_filter .= "'".$inmap."',"; |
241
|
|
|
} |
242
|
|
|
$inmap_pkms_filter = rtrim($inmap_pkms_filter, ","); |
243
|
|
|
$where .= " AND encounter_id NOT IN (" . $inmap_pkms_filter . ") "; |
244
|
|
|
} |
245
|
|
|
if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) { |
246
|
|
|
$where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (" . $ivMin . ") "; |
247
|
|
|
} |
248
|
|
|
if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) { |
249
|
|
|
$where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (" . $ivMax . ") "; |
250
|
|
|
} |
251
|
|
|
$req = "SELECT pokemon_id, lat AS latitude, lon AS longitude, |
252
|
|
|
FROM_UNIXTIME(expire_timestamp) AS disappear_time, |
253
|
|
|
FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
254
|
|
|
atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina, |
255
|
|
|
move_1, move_2 |
256
|
|
|
FROM sightings " . $where . " |
257
|
|
|
LIMIT 5000"; |
258
|
|
|
$result = $this->mysqli->query($req); |
259
|
|
|
$spawns = array(); |
260
|
|
|
while ($data = $result->fetch_object()) { |
261
|
|
|
$spawns[] = $data; |
262
|
|
|
} |
263
|
|
|
return $spawns; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
public function getPokemonSliderMinMax() { |
267
|
|
|
$req = "SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings"; |
268
|
|
|
$result = $this->mysqli->query($req); |
269
|
|
|
$data = $result->fetch_object(); |
270
|
|
|
return $data; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function getMapsCoords() { |
274
|
|
|
$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints"; |
275
|
|
|
$result = $this->mysqli->query($req); |
276
|
|
|
$data = $result->fetch_object(); |
277
|
|
|
return $data; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public function getPokemonCount($pokemon_id) { |
281
|
|
|
$req = "SELECT count, last_seen, latitude, longitude |
282
|
|
|
FROM pokemon_stats |
283
|
|
|
WHERE pid = ".$pokemon_id; |
284
|
|
|
$result = $this->mysqli->query($req); |
285
|
|
|
$data = $result->fetch_object(); |
286
|
|
|
return $data; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
public function getRaidCount($pokemon_id) { |
290
|
|
|
$req = "SELECT count, last_seen, latitude, longitude |
291
|
|
|
FROM raid_stats |
292
|
|
|
WHERE pid = ".$pokemon_id; |
293
|
|
|
$result = $this->mysqli->query($req); |
294
|
|
|
$data = $result->fetch_object(); |
295
|
|
|
return $data; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
|
299
|
|
|
|
300
|
|
|
/////////////// |
301
|
|
|
// Pokestops |
302
|
|
|
////////////// |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
function getTotalPokestops() { |
|
|
|
|
306
|
|
|
$req = "SELECT COUNT(*) as total FROM pokestops"; |
307
|
|
|
$result = $this->mysqli->query($req); |
308
|
|
|
$data = $result->fetch_object(); |
309
|
|
|
return $data; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
public function getAllPokestops() { |
313
|
|
|
$req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops"; |
314
|
|
|
$result = $this->mysqli->query($req); |
315
|
|
|
$pokestops = array(); |
316
|
|
|
while ($data = $result->fetch_object()) { |
317
|
|
|
$pokestops[] = $data; |
318
|
|
|
} |
319
|
|
|
return $pokestops; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
|
323
|
|
|
///////// |
324
|
|
|
// Gyms |
325
|
|
|
///////// |
326
|
|
|
|
327
|
|
|
function getTeamGuardians($team_id) { |
|
|
|
|
328
|
|
|
$req = "SELECT COUNT(*) AS total, guard_pokemon_id |
329
|
|
|
FROM forts f |
330
|
|
|
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
331
|
|
|
WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3"; |
332
|
|
|
$result = $this->mysqli->query($req); |
333
|
|
|
|
334
|
|
|
$datas = array(); |
335
|
|
|
while ($data = $result->fetch_object()) { |
336
|
|
|
$datas[] = $data; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
return $datas; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
function getOwnedAndPoints($team_id) { |
|
|
|
|
343
|
|
|
$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp)) AS average_points |
344
|
|
|
FROM forts f |
345
|
|
|
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
346
|
|
|
WHERE fs.team = '" . $team_id . "'"; |
347
|
|
|
$result = $this->mysqli->query($req); |
348
|
|
|
$data = $result->fetch_object(); |
349
|
|
|
return $data; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
function getAllGyms() { |
|
|
|
|
353
|
|
|
$req = "SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level |
354
|
|
|
FROM forts f |
355
|
|
|
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id));"; |
356
|
|
|
$result = $this->mysqli->query($req); |
357
|
|
|
$gyms = array(); |
358
|
|
|
while ($data = $result->fetch_object()) { |
359
|
|
|
$gyms[] = $data; |
360
|
|
|
} |
361
|
|
|
return $gyms; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
public function getGymData($gym_id) { |
365
|
|
|
$req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, FROM_UNIXTIME(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, fs.total_cp |
366
|
|
|
FROM forts f |
367
|
|
|
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
368
|
|
|
WHERE f.id ='".$gym_id."'"; |
369
|
|
|
$result = $this->mysqli->query($req); |
370
|
|
|
$data = $result->fetch_object(); |
371
|
|
|
return $data; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
public function getGymDefenders($gym_id) { |
375
|
|
|
$req = "SELECT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id |
376
|
|
|
FROM gym_defenders |
377
|
|
|
WHERE fort_id='".$gym_id."' |
378
|
|
|
ORDER BY deployment_time"; |
379
|
|
|
$result = $this->mysqli->query($req); |
380
|
|
|
$defenders = array(); |
381
|
|
|
while ($data = $result->fetch_object()) { |
382
|
|
|
$defenders[] = $data; |
383
|
|
|
} |
384
|
|
|
return $defenders; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
|
388
|
|
|
/////////// |
389
|
|
|
// Raids |
390
|
|
|
/////////// |
391
|
|
|
|
392
|
|
View Code Duplication |
public function getAllRaids($page) { |
|
|
|
|
393
|
|
|
$limit = " LIMIT ".($page * 10).",10"; |
394
|
|
|
$req = "SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, FROM_UNIXTIME(r.time_spawn) AS spawn, FROM_UNIXTIME(r.time_battle) AS start, FROM_UNIXTIME(r.time_end) AS end, FROM_UNIXTIME(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude |
395
|
|
|
FROM forts f |
396
|
|
|
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
397
|
|
|
LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP()) |
398
|
|
|
WHERE r.time_end > UNIX_TIMESTAMP() |
399
|
|
|
ORDER BY r.level DESC, r.time_battle" . $limit; |
400
|
|
|
$result = $this->mysqli->query($req); |
401
|
|
|
$raids = array(); |
402
|
|
|
while ($data = $result->fetch_object()) { |
403
|
|
|
$raids[] = $data; |
404
|
|
|
} |
405
|
|
|
return $raids; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
|
409
|
|
|
|
410
|
|
|
//////////////// |
411
|
|
|
// Gym History |
412
|
|
|
//////////////// |
413
|
|
|
|
414
|
|
View Code Duplication |
public function getGymHistories($gym_name, $team, $page, $ranking) |
|
|
|
|
415
|
|
|
{ |
416
|
|
|
$where = ""; |
417
|
|
|
if (isset($gym_name) && $gym_name != '') { |
418
|
|
|
$where = " WHERE name LIKE '%".$gym_name."%'"; |
419
|
|
|
} |
420
|
|
|
if (isset($team) && $team != '') { |
421
|
|
|
$where .= ($where === "" ? " WHERE" : " AND")." fs.team = ".$team; |
422
|
|
|
} |
423
|
|
|
switch ($ranking) { |
424
|
|
|
case 1: |
425
|
|
|
$order = " ORDER BY name, last_modified DESC"; |
426
|
|
|
break; |
427
|
|
|
case 2: |
428
|
|
|
$order = " ORDER BY total_cp DESC, last_modified DESC"; |
429
|
|
|
break; |
430
|
|
|
default: |
431
|
|
|
$order = " ORDER BY last_modified DESC, name"; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
$limit = " LIMIT ".($page * 10).",10"; |
435
|
|
|
|
436
|
|
|
$req = "SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, FROM_UNIXTIME(last_modified) AS last_modified |
437
|
|
|
FROM forts f |
438
|
|
|
LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
439
|
|
|
".$where.$order.$limit; |
440
|
|
|
$result = $this->mysqli->query($req); |
441
|
|
|
$gym_history = array(); |
442
|
|
|
while ($data = $result->fetch_object()) { |
443
|
|
|
$gym_history[] = $data; |
444
|
|
|
} |
445
|
|
|
return $gym_history; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
public function getGymHistoriesPokemon($gym_id) |
449
|
|
|
{ |
450
|
|
|
$req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name |
451
|
|
|
FROM gym_defenders |
452
|
|
|
WHERE fort_id = '". $gym_id ."' |
453
|
|
|
ORDER BY deployment_time"; |
454
|
|
|
$result = $this->mysqli->query($req); |
455
|
|
|
$pokemons = array(); |
456
|
|
|
while ($data = $result->fetch_object()) { |
457
|
|
|
$pokemons[] = $data; |
458
|
|
|
} |
459
|
|
|
return $pokemons; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
public function getHistoryForGym($page, $gym_id) |
463
|
|
|
{ |
464
|
|
View Code Duplication |
if (isset(self::$config->system->gymhistory_hide_cp_changes) && self::$config->system->gymhistory_hide_cp_changes === true) { |
|
|
|
|
465
|
|
|
$pageSize = 25; |
466
|
|
|
} else { |
467
|
|
|
$pageSize = 10; |
468
|
|
|
} |
469
|
|
|
$req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, FROM_UNIXTIME(fs.last_modified) as last_modified, last_modified as last_modified_real |
470
|
|
|
FROM fort_sightings fs |
471
|
|
|
LEFT JOIN forts f ON f.id = fs.fort_id |
472
|
|
|
WHERE f.id = '". $gym_id ."' |
473
|
|
|
ORDER BY fs.last_modified DESC |
474
|
|
|
LIMIT ".($page * $pageSize).",".($pageSize+1); |
475
|
|
|
$result = $this->mysqli->query($req); |
476
|
|
|
$history = array(); |
477
|
|
|
$count = 0; |
478
|
|
View Code Duplication |
while ($data = $result->fetch_object()) { |
|
|
|
|
479
|
|
|
$count++; |
480
|
|
|
if ($data->total_cp == 0) { |
481
|
|
|
$data->pokemon = array(); |
482
|
|
|
$data->pokemon_count = 0; |
483
|
|
|
$data->pokemon_uids = ""; |
484
|
|
|
} else { |
485
|
|
|
$data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real); |
486
|
|
|
$data->pokemon_count = count($data->pokemon); |
487
|
|
|
$data->pokemon_uids = implode(",", array_keys($data->pokemon)); |
488
|
|
|
} |
489
|
|
|
if ($data->total_cp === 0 || $data->pokemon_count !== 0) { |
490
|
|
|
$history[] = $data; |
491
|
|
|
} |
492
|
|
|
} |
493
|
|
|
if ($count !== ($pageSize + 1)) { |
494
|
|
|
$last_page = true; |
495
|
|
|
} else { |
496
|
|
|
$last_page = false; |
497
|
|
|
} |
498
|
|
|
return array("last_page" => $last_page, "data" => $history); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
View Code Duplication |
private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
|
|
|
502
|
|
|
{ |
503
|
|
|
$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name |
504
|
|
|
FROM gym_history_defenders ghd |
505
|
|
|
JOIN gym_defenders gd ON ghd.defender_id = gd.external_id |
506
|
|
|
WHERE ghd.fort_id = '". $gym_id ."' AND date = '".$last_modified."' |
507
|
|
|
ORDER BY gd.deployment_time"; |
508
|
|
|
$result = $this->mysqli->query($req); |
509
|
|
|
$pokemons = array(); |
510
|
|
|
while ($data = $result->fetch_object()) { |
511
|
|
|
$pokemons[$data->defender_id] = $data; |
512
|
|
|
} |
513
|
|
|
return $pokemons; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
|
517
|
|
|
|
518
|
|
|
////////////// |
519
|
|
|
// Trainers |
520
|
|
|
////////////// |
521
|
|
|
|
522
|
|
|
public function getTrainers($trainer_name, $team, $page, $rankingNumber) { |
523
|
|
|
$ranking = $this->getTrainerLevelRanking(); |
524
|
|
|
$where = ""; |
525
|
|
|
if (!empty(self::$config->system->trainer_blacklist)) { |
526
|
|
|
$where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
527
|
|
|
} |
528
|
|
|
if ($trainer_name != "") { |
529
|
|
|
$where = " AND gd.owner_name LIKE '%".$trainer_name."%'"; |
530
|
|
|
} |
531
|
|
View Code Duplication |
if ($team != 0) { |
|
|
|
|
532
|
|
|
$where .= ($where == "" ? " HAVING" : " AND")." team = ".$team; |
533
|
|
|
} |
534
|
|
View Code Duplication |
switch ($rankingNumber) { |
|
|
|
|
535
|
|
|
case 1: |
536
|
|
|
$order = " ORDER BY active DESC, level DESC"; |
537
|
|
|
break; |
538
|
|
|
case 2: |
539
|
|
|
$order = " ORDER BY maxCp DESC, level DESC"; |
540
|
|
|
break; |
541
|
|
|
default: |
542
|
|
|
$order = " ORDER BY level DESC, active DESC"; |
543
|
|
|
} |
544
|
|
|
$order .= ", last_seen DESC, name "; |
545
|
|
|
$limit = " LIMIT ".($page * 10).",10 "; |
546
|
|
|
$req = "SELECT gd.owner_name AS name, MAX(owner_level) AS level, MAX(cp) AS maxCp, MAX(active) AS active, MAX(team) AS team, FROM_UNIXTIME(MAX(last_modified)) as last_seen |
547
|
|
|
FROM gym_defenders gd |
548
|
|
|
LEFT JOIN ( |
549
|
|
|
SELECT owner_name, COUNT(*) as active |
550
|
|
|
FROM gym_defenders gd2 |
551
|
|
|
WHERE fort_id IS NOT NULL |
552
|
|
|
GROUP BY owner_name |
553
|
|
|
) active ON active.owner_name = gd.owner_name |
554
|
|
|
WHERE gd.owner_level IS NOT NULL " . $where . " |
555
|
|
|
GROUP BY gd.owner_name" . $order . $limit; |
556
|
|
|
$result = $this->mysqli->query($req); |
557
|
|
|
$trainers = array(); |
558
|
|
View Code Duplication |
while ($data = $result->fetch_object()) { |
|
|
|
|
559
|
|
|
$data->last_seen = date("Y-m-d", strtotime($data->last_seen)); |
560
|
|
|
if (is_null($data->active)) { |
561
|
|
|
$data->active = 0; |
562
|
|
|
} |
563
|
|
|
$trainers[$data->name] = $data; |
564
|
|
|
|
565
|
|
|
$pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name)); |
|
|
|
|
566
|
|
|
|
567
|
|
|
$trainers[$data->name]->gyms = $data->active; |
568
|
|
|
$trainers[$data->name]->pokemons = $pokemon; |
569
|
|
|
$trainers[$data->name]->rank = $ranking[$data->level]; |
570
|
|
|
} |
571
|
|
|
return $trainers; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
View Code Duplication |
public function getTrainerLevelRanking() { |
|
|
|
|
575
|
|
|
$exclue = ""; |
576
|
|
|
if (!empty(self::$config->system->trainer_blacklist)) { |
577
|
|
|
$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
578
|
|
|
} |
579
|
|
|
$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level"; |
580
|
|
|
$result = $this->mysqli->query($req); |
581
|
|
|
$levelData = array(); |
582
|
|
|
while ($data = $result->fetch_object()) { |
583
|
|
|
$levelData[$data->level] = $data->count; |
584
|
|
|
} |
585
|
|
|
for ($i = 5; $i <= 40; $i++) { |
586
|
|
|
if (!isset($levelData[$i])) { |
587
|
|
|
$levelData[$i] = 0; |
588
|
|
|
} |
589
|
|
|
} |
590
|
|
|
# sort array again |
591
|
|
|
ksort($levelData); |
592
|
|
|
return $levelData; |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
public function getActivePokemon($trainer_name) { |
596
|
|
|
$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, FROM_UNIXTIME(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned |
597
|
|
|
FROM gym_defenders |
598
|
|
|
WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL |
599
|
|
|
ORDER BY deployment_time"; |
600
|
|
|
$result = $this->mysqli->query($req); |
601
|
|
|
$pokemon = array(); |
602
|
|
|
while ($data = $result->fetch_object()) { |
603
|
|
|
$pokemon[] = $data; |
604
|
|
|
} |
605
|
|
|
return $pokemon; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
public function getInactivePokemon($trainer_name) { |
609
|
|
|
$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, NULL AS deployment_time, '0' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned |
610
|
|
|
FROM gym_defenders |
611
|
|
|
WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL |
612
|
|
|
ORDER BY last_scanned"; |
613
|
|
|
$result = $this->mysqli->query($req); |
614
|
|
|
$pokemon = array(); |
615
|
|
|
while ($data = $result->fetch_object()) { |
616
|
|
|
$pokemon[] = $data; |
617
|
|
|
} |
618
|
|
|
return $pokemon; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
View Code Duplication |
public function getTrainerLevelCount($team_id) { |
|
|
|
|
622
|
|
|
$exclue = ""; |
623
|
|
|
if (!empty(self::$config->system->trainer_blacklist)) { |
624
|
|
|
$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
625
|
|
|
} |
626
|
|
|
$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level"; |
627
|
|
|
$result = $this->mysqli->query($req); |
628
|
|
|
$levelData = array(); |
629
|
|
|
while ($data = $result->fetch_object()) { |
630
|
|
|
$levelData[$data->level] = $data->count; |
631
|
|
|
} |
632
|
|
|
for ($i = 5; $i <= 40; $i++) { |
633
|
|
|
if (!isset($levelData[$i])) { |
634
|
|
|
$levelData[$i] = 0; |
635
|
|
|
} |
636
|
|
|
} |
637
|
|
|
# sort array again |
638
|
|
|
ksort($levelData); |
639
|
|
|
return $levelData; |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
|
643
|
|
|
///////// |
644
|
|
|
// Cron |
645
|
|
|
///////// |
646
|
|
|
|
647
|
|
|
public function getPokemonCountsActive() { |
648
|
|
|
$req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id"; |
649
|
|
|
$result = $this->mysqli->query($req); |
650
|
|
|
$counts = array(); |
651
|
|
|
while ($data = $result->fetch_object()) { |
652
|
|
|
$counts[$data->pokemon_id] = $data->total; |
653
|
|
|
} |
654
|
|
|
return $counts; |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
public function getPokemonCountsLastDay() { |
658
|
|
|
$req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day |
659
|
|
|
FROM sightings |
660
|
|
|
WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings) |
661
|
|
|
GROUP BY pokemon_id |
662
|
|
|
ORDER BY pokemon_id ASC"; |
663
|
|
|
$result = $this->mysqli->query($req); |
664
|
|
|
$counts = array(); |
665
|
|
|
while ($data = $result->fetch_object()) { |
666
|
|
|
$counts[$data->pokemon_id] = $data->spawns_last_day; |
667
|
|
|
} |
668
|
|
|
return $counts; |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
public function getCaptchaCount() { |
672
|
|
|
$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL"; |
673
|
|
|
$result = $this->mysqli->query($req); |
674
|
|
|
$data = $result->fetch_object(); |
675
|
|
|
return $data; |
676
|
|
|
} |
677
|
|
|
|
678
|
|
View Code Duplication |
public function getNestData() { |
|
|
|
|
679
|
|
|
$pokemon_exclude_sql = ""; |
680
|
|
|
if (!empty(self::$config->system->nest_exclude_pokemon)) { |
681
|
|
|
$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")"; |
682
|
|
|
} |
683
|
|
|
$req = "SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(s.updated) as latest_seen, coalesce(CASE WHEN MAX(duration) = 0 THEN NULL ELSE MAX(duration) END ,30)*60 as duration |
684
|
|
|
FROM sightings p |
685
|
|
|
INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id) |
686
|
|
|
WHERE p.expire_timestamp > UNIX_TIMESTAMP() - 86400 |
687
|
|
|
" . $pokemon_exclude_sql . " |
688
|
|
|
GROUP BY p.spawn_id, p.pokemon_id |
689
|
|
|
HAVING COUNT(p.pokemon_id) >= 6 |
690
|
|
|
ORDER BY p.pokemon_id"; |
691
|
|
|
$result = $this->mysqli->query($req); |
692
|
|
|
$nests = array(); |
693
|
|
|
while ($data = $result->fetch_object()) { |
694
|
|
|
$nests[] = $data; |
695
|
|
|
} |
696
|
|
|
return $nests; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
} |
700
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.