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