@@ -1,12 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -class QueryManagerMysqlMonocleAlternate extends QueryManagerMysql { |
|
| 3 | +class QueryManagerMysqlMonocleAlternate extends QueryManagerMysql |
|
| 4 | +{ |
|
| 4 | 5 | |
| 5 | - public function __construct() { |
|
| 6 | + public function __construct() |
|
| 7 | + { |
|
| 6 | 8 | parent::__construct(); |
| 7 | 9 | } |
| 8 | 10 | |
| 9 | - public function __destruct() { |
|
| 11 | + public function __destruct() |
|
| 12 | + { |
|
| 10 | 13 | parent::__destruct(); |
| 11 | 14 | } |
| 12 | 15 | |
@@ -14,7 +17,8 @@ discard block |
||
| 14 | 17 | // Tester |
| 15 | 18 | /////////// |
| 16 | 19 | |
| 17 | - function testTotalPokemon() { |
|
| 20 | + function testTotalPokemon() |
|
| 21 | + { |
|
| 18 | 22 | $req = "SELECT COUNT(*) as total FROM sightings"; |
| 19 | 23 | $result = $this->mysqli->query($req); |
| 20 | 24 | if (!is_object($result)) { |
@@ -30,7 +34,8 @@ discard block |
||
| 30 | 34 | return 0; |
| 31 | 35 | } |
| 32 | 36 | |
| 33 | - function testTotalGyms() { |
|
| 37 | + function testTotalGyms() |
|
| 38 | + { |
|
| 34 | 39 | $req = "SELECT COUNT(*) as total FROM forts"; |
| 35 | 40 | $result = $this->mysqli->query($req); |
| 36 | 41 | if (!is_object($result)) { |
@@ -46,7 +51,8 @@ discard block |
||
| 46 | 51 | return 0; |
| 47 | 52 | } |
| 48 | 53 | |
| 49 | - function testTotalPokestops() { |
|
| 54 | + function testTotalPokestops() |
|
| 55 | + { |
|
| 50 | 56 | $req = "SELECT COUNT(*) as total FROM pokestops"; |
| 51 | 57 | $result = $this->mysqli->query($req); |
| 52 | 58 | if (!is_object($result)) { |
@@ -67,26 +73,30 @@ discard block |
||
| 67 | 73 | // Homepage |
| 68 | 74 | ///////////// |
| 69 | 75 | |
| 70 | - function getTotalPokemon() { |
|
| 76 | + function getTotalPokemon() |
|
| 77 | + { |
|
| 71 | 78 | $req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()"; |
| 72 | 79 | $result = $this->mysqli->query($req); |
| 73 | 80 | $data = $result->fetch_object(); |
| 74 | 81 | return $data; |
| 75 | 82 | } |
| 76 | 83 | |
| 77 | - function getTotalLures() { |
|
| 84 | + function getTotalLures() |
|
| 85 | + { |
|
| 78 | 86 | $data = (object) array("total" => 0); |
| 79 | 87 | return $data; |
| 80 | 88 | } |
| 81 | 89 | |
| 82 | - function getTotalGyms() { |
|
| 90 | + function getTotalGyms() |
|
| 91 | + { |
|
| 83 | 92 | $req = "SELECT COUNT(*) AS total FROM forts"; |
| 84 | 93 | $result = $this->mysqli->query($req); |
| 85 | 94 | $data = $result->fetch_object(); |
| 86 | 95 | return $data; |
| 87 | 96 | } |
| 88 | 97 | |
| 89 | - function getTotalRaids() { |
|
| 98 | + function getTotalRaids() |
|
| 99 | + { |
|
| 90 | 100 | $req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_TIMESTAMP()"; |
| 91 | 101 | $result = $this->mysqli->query($req); |
| 92 | 102 | $data = $result->fetch_object(); |
@@ -94,14 +104,16 @@ discard block |
||
| 94 | 104 | } |
| 95 | 105 | |
| 96 | 106 | |
| 97 | - function getTotalGymsForTeam($team_id) { |
|
| 107 | + function getTotalGymsForTeam($team_id) |
|
| 108 | + { |
|
| 98 | 109 | $req = "SELECT COUNT(*) AS total FROM fort_sightings WHERE team = '$team_id'"; |
| 99 | 110 | $result = $this->mysqli->query($req); |
| 100 | 111 | $data = $result->fetch_object(); |
| 101 | 112 | return $data; |
| 102 | 113 | } |
| 103 | 114 | |
| 104 | - function getRecentAll() { |
|
| 115 | + function getRecentAll() |
|
| 116 | + { |
|
| 105 | 117 | $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, |
| 106 | 118 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
| 107 | 119 | FROM sightings |
@@ -117,7 +129,8 @@ discard block |
||
| 117 | 129 | return $data; |
| 118 | 130 | } |
| 119 | 131 | |
| 120 | - function getRecentMythic($mythic_pokemon) { |
|
| 132 | + function getRecentMythic($mythic_pokemon) |
|
| 133 | + { |
|
| 121 | 134 | $req = "SELECT DISTINCT pokemon_id as pokemon_id, CONCAT('A', encounter_id) as encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
| 122 | 135 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
| 123 | 136 | FROM sightings |
@@ -138,14 +151,16 @@ discard block |
||
| 138 | 151 | // Single Pokemon |
| 139 | 152 | /////////////////// |
| 140 | 153 | |
| 141 | - function getGymsProtectedByPokemon($pokemon_id) { |
|
| 154 | + function getGymsProtectedByPokemon($pokemon_id) |
|
| 155 | + { |
|
| 142 | 156 | $req = "SELECT COUNT(DISTINCT(fort_id)) AS total FROM fort_sightings WHERE guard_pokemon_id = '".$pokemon_id."'"; |
| 143 | 157 | $result = $this->mysqli->query($req); |
| 144 | 158 | $data = $result->fetch_object(); |
| 145 | 159 | return $data; |
| 146 | 160 | } |
| 147 | 161 | |
| 148 | - function getPokemonLastSeen($pokemon_id) { |
|
| 162 | + function getPokemonLastSeen($pokemon_id) |
|
| 163 | + { |
|
| 149 | 164 | $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
| 150 | 165 | FROM sightings |
| 151 | 166 | WHERE pokemon_id = '".$pokemon_id."' |
@@ -156,7 +171,8 @@ discard block |
||
| 156 | 171 | return $data; |
| 157 | 172 | } |
| 158 | 173 | |
| 159 | - function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) { |
|
| 174 | + function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 175 | + { |
|
| 160 | 176 | $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, |
| 161 | 177 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
| 162 | 178 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1 as move_1, move_2, form |
@@ -174,7 +190,8 @@ discard block |
||
| 174 | 190 | return $top; |
| 175 | 191 | } |
| 176 | 192 | |
| 177 | - function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
|
| 193 | + function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 194 | + { |
|
| 178 | 195 | $trainer_blacklist = ""; |
| 179 | 196 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 180 | 197 | $trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')"; |
@@ -196,7 +213,8 @@ discard block |
||
| 196 | 213 | return $toptrainer; |
| 197 | 214 | } |
| 198 | 215 | |
| 199 | - public function getPokemonHeatmap($pokemon_id, $start, $end) { |
|
| 216 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 217 | + { |
|
| 200 | 218 | $where = " WHERE pokemon_id = ".$pokemon_id." " |
| 201 | 219 | . "AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
| 202 | 220 | $req = "SELECT lat AS latitude, lon AS longitude FROM sightings".$where." ORDER BY expire_timestamp DESC LIMIT 100000"; |
@@ -208,7 +226,8 @@ discard block |
||
| 208 | 226 | return $points; |
| 209 | 227 | } |
| 210 | 228 | |
| 211 | - public function getPokemonGraph($pokemon_id) { |
|
| 229 | + public function getPokemonGraph($pokemon_id) |
|
| 230 | + { |
|
| 212 | 231 | $req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour |
| 213 | 232 | FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered |
| 214 | 233 | GROUP BY disappear_hour |
@@ -224,7 +243,8 @@ discard block |
||
| 224 | 243 | return $array; |
| 225 | 244 | } |
| 226 | 245 | |
| 227 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
|
| 246 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
| 247 | + { |
|
| 228 | 248 | $inmap_pkms_filter = ""; |
| 229 | 249 | $where = " WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = " . $pokemon_id; |
| 230 | 250 | |
@@ -260,14 +280,16 @@ discard block |
||
| 260 | 280 | return $spawns; |
| 261 | 281 | } |
| 262 | 282 | |
| 263 | - public function getPokemonSliederMinMax() { |
|
| 283 | + public function getPokemonSliederMinMax() |
|
| 284 | + { |
|
| 264 | 285 | $req = "SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings"; |
| 265 | 286 | $result = $this->mysqli->query($req); |
| 266 | 287 | $data = $result->fetch_object(); |
| 267 | 288 | return $data; |
| 268 | 289 | } |
| 269 | 290 | |
| 270 | - public function getMapsCoords() { |
|
| 291 | + public function getMapsCoords() |
|
| 292 | + { |
|
| 271 | 293 | $req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints"; |
| 272 | 294 | $result = $this->mysqli->query($req); |
| 273 | 295 | $data = $result->fetch_object(); |
@@ -280,14 +302,16 @@ discard block |
||
| 280 | 302 | ////////////// |
| 281 | 303 | |
| 282 | 304 | |
| 283 | - function getTotalPokestops() { |
|
| 305 | + function getTotalPokestops() |
|
| 306 | + { |
|
| 284 | 307 | $req = "SELECT COUNT(*) as total FROM pokestops"; |
| 285 | 308 | $result = $this->mysqli->query($req); |
| 286 | 309 | $data = $result->fetch_object(); |
| 287 | 310 | return $data; |
| 288 | 311 | } |
| 289 | 312 | |
| 290 | - public function getAllPokestops() { |
|
| 313 | + public function getAllPokestops() |
|
| 314 | + { |
|
| 291 | 315 | $req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops"; |
| 292 | 316 | $result = $this->mysqli->query($req); |
| 293 | 317 | $pokestops = array(); |
@@ -302,7 +326,8 @@ discard block |
||
| 302 | 326 | // Gyms |
| 303 | 327 | ///////// |
| 304 | 328 | |
| 305 | - function getTeamGuardians($team_id) { |
|
| 329 | + function getTeamGuardians($team_id) |
|
| 330 | + { |
|
| 306 | 331 | $req = "SELECT COUNT(*) AS total, guard_pokemon_id FROM fort_sightings WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3"; |
| 307 | 332 | $result = $this->mysqli->query($req); |
| 308 | 333 | |
@@ -314,7 +339,8 @@ discard block |
||
| 314 | 339 | return $datas; |
| 315 | 340 | } |
| 316 | 341 | |
| 317 | - function getOwnedAndPoints($team_id) { |
|
| 342 | + function getOwnedAndPoints($team_id) |
|
| 343 | + { |
|
| 318 | 344 | $req = "SELECT COUNT(DISTINCT(fs.fort_id)) AS total, ROUND((SUM(gd.cp)) / COUNT(DISTINCT(fs.fort_id)),0) AS average_points |
| 319 | 345 | FROM fort_sightings fs |
| 320 | 346 | JOIN gym_defenders gd ON fs.fort_id = gd.fort_id |
@@ -324,7 +350,8 @@ discard block |
||
| 324 | 350 | return $data; |
| 325 | 351 | } |
| 326 | 352 | |
| 327 | - function getAllGyms() { |
|
| 353 | + function getAllGyms() |
|
| 354 | + { |
|
| 328 | 355 | $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 FROM forts f LEFT JOIN fort_sightings fs ON f.id = fs.fort_id;"; |
| 329 | 356 | $result = $this->mysqli->query($req); |
| 330 | 357 | $gyms = array(); |
@@ -334,7 +361,8 @@ discard block |
||
| 334 | 361 | return $gyms; |
| 335 | 362 | } |
| 336 | 363 | |
| 337 | - public function getGymData($gym_id) { |
|
| 364 | + public function getGymData($gym_id) |
|
| 365 | + { |
|
| 338 | 366 | $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, SUM(gd.cp) as total_cp |
| 339 | 367 | FROM fort_sightings fs |
| 340 | 368 | LEFT JOIN forts f ON f.id = fs.fort_id |
@@ -345,7 +373,8 @@ discard block |
||
| 345 | 373 | return $data; |
| 346 | 374 | } |
| 347 | 375 | |
| 348 | - public function getGymDefenders($gym_id) { |
|
| 376 | + public function getGymDefenders($gym_id) |
|
| 377 | + { |
|
| 349 | 378 | $req = "SELECT DISTINCT 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 |
| 350 | 379 | FROM gym_defenders |
| 351 | 380 | WHERE fort_id='".$gym_id."' |
@@ -363,7 +392,8 @@ discard block |
||
| 363 | 392 | // Raids |
| 364 | 393 | /////////// |
| 365 | 394 | |
| 366 | - public function getAllRaids($page) { |
|
| 395 | + public function getAllRaids($page) |
|
| 396 | + { |
|
| 367 | 397 | $limit = " LIMIT ".($page * 10).",10"; |
| 368 | 398 | $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 |
| 369 | 399 | FROM raids r |
@@ -384,11 +414,13 @@ discard block |
||
| 384 | 414 | // Trainers |
| 385 | 415 | ////////////// |
| 386 | 416 | |
| 387 | - public function getTrainers($trainer_name, $team, $page, $ranking) { |
|
| 417 | + public function getTrainers($trainer_name, $team, $page, $ranking) |
|
| 418 | + { |
|
| 388 | 419 | return array(); // Waiting for Monocle to store level |
| 389 | 420 | } |
| 390 | 421 | |
| 391 | - public function getTrainerLevelCount($team_id) { |
|
| 422 | + public function getTrainerLevelCount($team_id) |
|
| 423 | + { |
|
| 392 | 424 | $levelData = array(); |
| 393 | 425 | for ($i = 5; $i <= 40; $i++) { |
| 394 | 426 | if (!isset($levelData[$i])) { |
@@ -403,7 +435,8 @@ discard block |
||
| 403 | 435 | // Cron |
| 404 | 436 | ///////// |
| 405 | 437 | |
| 406 | - public function getPokemonCountsActive() { |
|
| 438 | + public function getPokemonCountsActive() |
|
| 439 | + { |
|
| 407 | 440 | $req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id"; |
| 408 | 441 | $result = $this->mysqli->query($req); |
| 409 | 442 | $counts = array(); |
@@ -413,7 +446,8 @@ discard block |
||
| 413 | 446 | return $counts; |
| 414 | 447 | } |
| 415 | 448 | |
| 416 | - public function getPoekmonCountsLastDay() { |
|
| 449 | + public function getPoekmonCountsLastDay() |
|
| 450 | + { |
|
| 417 | 451 | $req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day |
| 418 | 452 | FROM sightings |
| 419 | 453 | WHERE FROM_UNIXTIME(expire_timestamp) >= (SELECT FROM_UNIXTIME(MAX(expire_timestamp)) FROM sightings) - INTERVAL 1 DAY |
@@ -427,7 +461,8 @@ discard block |
||
| 427 | 461 | return $counts; |
| 428 | 462 | } |
| 429 | 463 | |
| 430 | - public function getPokemonSinceLastUpdate($pokemon_id, $last_update) { |
|
| 464 | + public function getPokemonSinceLastUpdate($pokemon_id, $last_update) |
|
| 465 | + { |
|
| 431 | 466 | $where = "WHERE pokemon_id = '".$pokemon_id."' AND id > '".$last_update."'"; |
| 432 | 467 | $req = "SELECT count, id AS last_timestamp, (FROM_UNIXTIME(expire_timestamp)) AS disappear_time_real, lat as latitude, lon as longitude |
| 433 | 468 | FROM sightings |
@@ -443,7 +478,8 @@ discard block |
||
| 443 | 478 | return $data; |
| 444 | 479 | } |
| 445 | 480 | |
| 446 | - public function getRaidsSinceLastUpdate($pokemon_id, $last_update) { |
|
| 481 | + public function getRaidsSinceLastUpdate($pokemon_id, $last_update) |
|
| 482 | + { |
|
| 447 | 483 | $where = "WHERE pokemon_id = '".$pokemon_id."AND".$last_update."'"; |
| 448 | 484 | $req = "SELECT time_battle AS start_timestamp, time_end as end, (FROM_UNIXTIME(time_end)) AS end_time_real, lat as latitude, lon as longitude, count |
| 449 | 485 | FROM raids r |
@@ -461,14 +497,16 @@ discard block |
||
| 461 | 497 | return $data; |
| 462 | 498 | } |
| 463 | 499 | |
| 464 | - public function getCaptchaCount() { |
|
| 500 | + public function getCaptchaCount() |
|
| 501 | + { |
|
| 465 | 502 | $req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL"; |
| 466 | 503 | $result = $this->mysqli->query($req); |
| 467 | 504 | $data = $result->fetch_object(); |
| 468 | 505 | return $data; |
| 469 | 506 | } |
| 470 | 507 | |
| 471 | - public function getNestData() { |
|
| 508 | + public function getNestData() |
|
| 509 | + { |
|
| 472 | 510 | $pokemon_exclude_sql = ""; |
| 473 | 511 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 474 | 512 | $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")"; |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
| 162 | 162 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1 as move_1, move_2, form |
| 163 | 163 | FROM sightings |
| 164 | - WHERE pokemon_id = '" . $pokemon_id . "' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 164 | + WHERE pokemon_id = '" . $pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 165 | 165 | ORDER BY $top_order_by $top_direction, expire_timestamp DESC |
| 166 | 166 | LIMIT 0,50"; |
| 167 | 167 | |
@@ -176,13 +176,13 @@ discard block |
||
| 176 | 176 | function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
| 177 | 177 | $trainer_blacklist = ""; |
| 178 | 178 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 179 | - $trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')"; |
|
| 179 | + $trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $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, |
| 183 | 183 | FROM_UNIXTIME(last_modified) AS lasttime, last_modified as last_seen |
| 184 | 184 | FROM gym_defenders |
| 185 | - WHERE pokemon_id = '" . $pokemon_id . "'" . $trainer_blacklist . " |
|
| 185 | + WHERE pokemon_id = '" . $pokemon_id."'".$trainer_blacklist." |
|
| 186 | 186 | ORDER BY $best_order_by $best_direction, owner_name ASC |
| 187 | 187 | LIMIT 0,50"; |
| 188 | 188 | |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
| 226 | 226 | $inmap_pkms_filter = ""; |
| 227 | - $where = " WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = " . $pokemon_id; |
|
| 227 | + $where = " WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = ".$pokemon_id; |
|
| 228 | 228 | |
| 229 | - $reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings " . $where; |
|
| 229 | + $reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings ".$where; |
|
| 230 | 230 | $resultTestIv = $this->mysqli->query($reqTestIv); |
| 231 | 231 | $testIv = $resultTestIv->fetch_object(); |
| 232 | 232 | if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) { |
@@ -234,20 +234,20 @@ discard block |
||
| 234 | 234 | $inmap_pkms_filter .= "'".$inmap."',"; |
| 235 | 235 | } |
| 236 | 236 | $inmap_pkms_filter = rtrim($inmap_pkms_filter, ","); |
| 237 | - $where .= " AND encounter_id NOT IN (" . $inmap_pkms_filter . ") "; |
|
| 237 | + $where .= " AND encounter_id NOT IN (".$inmap_pkms_filter.") "; |
|
| 238 | 238 | } |
| 239 | 239 | if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) { |
| 240 | - $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (" . $ivMin . ") "; |
|
| 240 | + $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (".$ivMin.") "; |
|
| 241 | 241 | } |
| 242 | 242 | if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) { |
| 243 | - $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (" . $ivMax . ") "; |
|
| 243 | + $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (".$ivMax.") "; |
|
| 244 | 244 | } |
| 245 | 245 | $req = "SELECT pokemon_id, lat AS latitude, lon AS longitude, |
| 246 | 246 | FROM_UNIXTIME(expire_timestamp) AS disappear_time, |
| 247 | 247 | FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
| 248 | 248 | atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina, |
| 249 | 249 | move_1, move_2 |
| 250 | - FROM sightings " . $where . " |
|
| 250 | + FROM sightings " . $where." |
|
| 251 | 251 | ORDER BY disappear_time DESC |
| 252 | 252 | LIMIT 5000"; |
| 253 | 253 | $result = $this->mysqli->query($req); |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | $req = "SELECT COUNT(DISTINCT(fs.fort_id)) AS total, ROUND((SUM(gd.cp)) / COUNT(DISTINCT(fs.fort_id)),0) AS average_points |
| 317 | 317 | FROM fort_sightings fs |
| 318 | 318 | JOIN gym_defenders gd ON fs.fort_id = gd.fort_id |
| 319 | - WHERE fs.team = '" . $team_id . "'"; |
|
| 319 | + WHERE fs.team = '" . $team_id."'"; |
|
| 320 | 320 | $result = $this->mysqli->query($req); |
| 321 | 321 | $data = $result->fetch_object(); |
| 322 | 322 | return $data; |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | FROM sightings |
| 434 | 434 | " . $where." |
| 435 | 435 | ) x |
| 436 | - " . $where . " |
|
| 436 | + " . $where." |
|
| 437 | 437 | ORDER BY expire_timestamp DESC |
| 438 | 438 | LIMIT 0 , 1"; |
| 439 | 439 | $result = $this->mysqli->query($req); |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | " . $where." |
| 452 | 452 | ) x |
| 453 | 453 | ON r.fort_id = g.id |
| 454 | - " . $where . " |
|
| 454 | + " . $where." |
|
| 455 | 455 | ORDER BY time_battle DESC |
| 456 | 456 | LIMIT 0 , 1"; |
| 457 | 457 | $result = $this->mysqli->query($req); |
@@ -469,13 +469,13 @@ discard block |
||
| 469 | 469 | public function getNestData() { |
| 470 | 470 | $pokemon_exclude_sql = ""; |
| 471 | 471 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 472 | - $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")"; |
|
| 472 | + $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", self::$config->system->nest_exclude_pokemon).")"; |
|
| 473 | 473 | } |
| 474 | 474 | $req = "SELECT p.pokemon_id, p.lat AS latitude, p.lon AS longitude, count(p.pokemon_id) AS total_pokemon, FROM_UNIXTIME(s.updated) as latest_seen, coalesce(duration,30)*60 as duration |
| 475 | 475 | FROM sightings p |
| 476 | 476 | INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id) |
| 477 | 477 | WHERE p.expire_timestamp > UNIX_TIMESTAMP() - 86400 |
| 478 | - " . $pokemon_exclude_sql . " |
|
| 478 | + " . $pokemon_exclude_sql." |
|
| 479 | 479 | GROUP BY p.spawn_id, p.pokemon_id |
| 480 | 480 | HAVING COUNT(p.pokemon_id) >= 6 |
| 481 | 481 | ORDER BY p.pokemon_id"; |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
| 168 | 168 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS \"IV\", move_1 as move_1, move_2, form |
| 169 | 169 | FROM sightings |
| 170 | - WHERE pokemon_id = '" . $pokemon_id . "' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 170 | + WHERE pokemon_id = '" . $pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 171 | 171 | ORDER BY $top_order_by $top_direction, expire_timestamp DESC |
| 172 | 172 | LIMIT 50 OFFSET 0"; |
| 173 | 173 | $result = pg_query($this->db, $req); |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
| 182 | 182 | $trainer_blacklist = ""; |
| 183 | 183 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 184 | - $trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')"; |
|
| 184 | + $trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | $req = "SELECT external_id, owner_name as trainer_name, ROUND((100.0*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS \"IV\", move_1, move_2, cp as cp, |
| 188 | 188 | TO_TIMESTAMP(last_modified) AS lasttime, last_modified as last_seen |
| 189 | 189 | FROM gym_defenders |
| 190 | - WHERE pokemon_id = '" . $pokemon_id . "'" . $trainer_blacklist . " |
|
| 190 | + WHERE pokemon_id = '" . $pokemon_id."'".$trainer_blacklist." |
|
| 191 | 191 | ORDER BY $best_order_by $best_direction, owner_name ASC |
| 192 | 192 | LIMIT 50 OFFSET 0"; |
| 193 | 193 | |
@@ -229,9 +229,9 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
| 231 | 231 | $inmap_pkms_filter = ""; |
| 232 | - $where = " WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = " . $pokemon_id; |
|
| 232 | + $where = " WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = ".$pokemon_id; |
|
| 233 | 233 | |
| 234 | - $reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings " . $where; |
|
| 234 | + $reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings ".$where; |
|
| 235 | 235 | $resultTestIv = pg_query($this->db, $reqTestIv); |
| 236 | 236 | $testIv = pg_fetch_object($resultTestIv); |
| 237 | 237 | if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) { |
@@ -239,20 +239,20 @@ discard block |
||
| 239 | 239 | $inmap_pkms_filter .= "'".$inmap."',"; |
| 240 | 240 | } |
| 241 | 241 | $inmap_pkms_filter = rtrim($inmap_pkms_filter, ","); |
| 242 | - $where .= " AND encounter_id NOT IN (" . $inmap_pkms_filter . ") "; |
|
| 242 | + $where .= " AND encounter_id NOT IN (".$inmap_pkms_filter.") "; |
|
| 243 | 243 | } |
| 244 | 244 | if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) { |
| 245 | - $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (" . $ivMin . ") "; |
|
| 245 | + $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (".$ivMin.") "; |
|
| 246 | 246 | } |
| 247 | 247 | if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) { |
| 248 | - $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (" . $ivMax . ") "; |
|
| 248 | + $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (".$ivMax.") "; |
|
| 249 | 249 | } |
| 250 | 250 | $req = "SELECT pokemon_id, lat AS latitude, lon AS longitude, |
| 251 | 251 | TO_TIMESTAMP(expire_timestamp) AS disappear_time, |
| 252 | 252 | TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, |
| 253 | 253 | atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina, |
| 254 | 254 | move_1, move_2 |
| 255 | - FROM sightings " . $where . " |
|
| 255 | + FROM sightings " . $where." |
|
| 256 | 256 | ORDER BY disappear_time DESC |
| 257 | 257 | LIMIT 5000"; |
| 258 | 258 | $result = pg_query($this->db, $req); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $req = "SELECT COUNT(DISTINCT(fs.fort_id)) AS total, ROUND((SUM(gd.cp)) / COUNT(DISTINCT(fs.fort_id)),0) AS average_points |
| 322 | 322 | FROM fort_sightings fs |
| 323 | 323 | JOIN gym_defenders gd ON fs.fort_id = gd.fort_id |
| 324 | - WHERE fs.team = '" . $team_id . "'"; |
|
| 324 | + WHERE fs.team = '" . $team_id."'"; |
|
| 325 | 325 | $result = pg_query($this->db, $req); |
| 326 | 326 | $data = pg_fetch_object($result); |
| 327 | 327 | return $data; |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | /////////// |
| 369 | 369 | |
| 370 | 370 | public function getAllRaids($page) { |
| 371 | - $limit = " LIMIT 10 OFFSET ". ($page * 10); |
|
| 371 | + $limit = " LIMIT 10 OFFSET ".($page * 10); |
|
| 372 | 372 | $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, TO_TIMESTAMP(r.time_spawn) AS spawn, TO_TIMESTAMP(r.time_battle) AS start, TO_TIMESTAMP(r.time_end) AS end, TO_TIMESTAMP(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude |
| 373 | 373 | FROM raids r |
| 374 | 374 | JOIN forts f ON f.id = r.fort_id |
@@ -437,9 +437,9 @@ discard block |
||
| 437 | 437 | FROM sightings |
| 438 | 438 | JOIN (SELECT COUNT(*) AS count |
| 439 | 439 | FROM sightings |
| 440 | - " . $where. " |
|
| 440 | + " . $where." |
|
| 441 | 441 | ) count ON 1 = 1 |
| 442 | - " . $where . " |
|
| 442 | + " . $where." |
|
| 443 | 443 | ORDER BY expire_timestamp DESC |
| 444 | 444 | LIMIT 1 OFFSET 0"; |
| 445 | 445 | $result = pg_query($this->db, $req); |
@@ -474,13 +474,13 @@ discard block |
||
| 474 | 474 | public function getNestData() { |
| 475 | 475 | $pokemon_exclude_sql = ""; |
| 476 | 476 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 477 | - $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")"; |
|
| 477 | + $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", self::$config->system->nest_exclude_pokemon).")"; |
|
| 478 | 478 | } |
| 479 | 479 | $req = "SELECT p.spawn_id, p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, TO_TIMESTAMP(MAX(s.updated)) as latest_seen, coalesce(MAX(duration),30)*60 as duration |
| 480 | 480 | FROM sightings p |
| 481 | 481 | INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id) |
| 482 | 482 | WHERE p.expire_timestamp > EXTRACT(EPOCH FROM NOW()) - 86400 |
| 483 | - " . $pokemon_exclude_sql . " |
|
| 483 | + " . $pokemon_exclude_sql." |
|
| 484 | 484 | GROUP BY p.spawn_id, p.pokemon_id |
| 485 | 485 | HAVING COUNT(p.pokemon_id) >= 6 |
| 486 | 486 | ORDER BY p.pokemon_id"; |
@@ -6,13 +6,16 @@ discard block |
||
| 6 | 6 | * Time: 02:26 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -class QueryManagerPostgresqlMonocleAlternate extends QueryManagerPostgresql { |
|
| 9 | +class QueryManagerPostgresqlMonocleAlternate extends QueryManagerPostgresql |
|
| 10 | +{ |
|
| 10 | 11 | |
| 11 | - public function __construct() { |
|
| 12 | + public function __construct() |
|
| 13 | + { |
|
| 12 | 14 | parent::__construct(); |
| 13 | 15 | } |
| 14 | 16 | |
| 15 | - public function __destruct() { |
|
| 17 | + public function __destruct() |
|
| 18 | + { |
|
| 16 | 19 | parent::__destruct(); |
| 17 | 20 | } |
| 18 | 21 | |
@@ -20,7 +23,8 @@ discard block |
||
| 20 | 23 | // Tester |
| 21 | 24 | /////////// |
| 22 | 25 | |
| 23 | - function testTotalPokemon() { |
|
| 26 | + function testTotalPokemon() |
|
| 27 | + { |
|
| 24 | 28 | $req = "SELECT COUNT(*) as total FROM sightings"; |
| 25 | 29 | $result = pg_query($this->db, $req); |
| 26 | 30 | if ($result === false) { |
@@ -36,7 +40,8 @@ discard block |
||
| 36 | 40 | return 0; |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | - function testTotalGyms() { |
|
| 43 | + function testTotalGyms() |
|
| 44 | + { |
|
| 40 | 45 | $req = "SELECT COUNT(*) as total FROM forts"; |
| 41 | 46 | $result = pg_query($this->db, $req); |
| 42 | 47 | if ($result === false) { |
@@ -52,7 +57,8 @@ discard block |
||
| 52 | 57 | return 0; |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | - function testTotalPokestops() { |
|
| 60 | + function testTotalPokestops() |
|
| 61 | + { |
|
| 56 | 62 | $req = "SELECT COUNT(*) as total FROM pokestops"; |
| 57 | 63 | $result = pg_query($this->db, $req); |
| 58 | 64 | if ($result === false) { |
@@ -73,26 +79,30 @@ discard block |
||
| 73 | 79 | // Homepage |
| 74 | 80 | ///////////// |
| 75 | 81 | |
| 76 | - function getTotalPokemon() { |
|
| 82 | + function getTotalPokemon() |
|
| 83 | + { |
|
| 77 | 84 | $req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())"; |
| 78 | 85 | $result = pg_query($this->db, $req); |
| 79 | 86 | $data = pg_fetch_object($result); |
| 80 | 87 | return $data; |
| 81 | 88 | } |
| 82 | 89 | |
| 83 | - function getTotalLures() { |
|
| 90 | + function getTotalLures() |
|
| 91 | + { |
|
| 84 | 92 | $data = (object) array("total" => 0); |
| 85 | 93 | return $data; |
| 86 | 94 | } |
| 87 | 95 | |
| 88 | - function getTotalGyms() { |
|
| 96 | + function getTotalGyms() |
|
| 97 | + { |
|
| 89 | 98 | $req = "SELECT COUNT(*) AS total FROM forts"; |
| 90 | 99 | $result = pg_query($this->db, $req); |
| 91 | 100 | $data = pg_fetch_object($result); |
| 92 | 101 | return $data; |
| 93 | 102 | } |
| 94 | 103 | |
| 95 | - function getTotalRaids() { |
|
| 104 | + function getTotalRaids() |
|
| 105 | + { |
|
| 96 | 106 | $req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())"; |
| 97 | 107 | $result = pg_query($this->db, $req); |
| 98 | 108 | $data = pg_fetch_object($result); |
@@ -100,14 +110,16 @@ discard block |
||
| 100 | 110 | } |
| 101 | 111 | |
| 102 | 112 | |
| 103 | - function getTotalGymsForTeam($team_id) { |
|
| 113 | + function getTotalGymsForTeam($team_id) |
|
| 114 | + { |
|
| 104 | 115 | $req = "SELECT COUNT(*) AS total FROM fort_sightings WHERE team = '$team_id'"; |
| 105 | 116 | $result = pg_query($this->db, $req); |
| 106 | 117 | $data = pg_fetch_object($result); |
| 107 | 118 | return $data; |
| 108 | 119 | } |
| 109 | 120 | |
| 110 | - function getRecentAll() { |
|
| 121 | + function getRecentAll() |
|
| 122 | + { |
|
| 111 | 123 | $req = "SELECT DISTINCT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, |
| 112 | 124 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
| 113 | 125 | FROM sightings |
@@ -123,7 +135,8 @@ discard block |
||
| 123 | 135 | return $data; |
| 124 | 136 | } |
| 125 | 137 | |
| 126 | - function getRecentMythic($mythic_pokemon) { |
|
| 138 | + function getRecentMythic($mythic_pokemon) |
|
| 139 | + { |
|
| 127 | 140 | $req = "SELECT DISTINCT pokemon_id as pokemon_id, CONCAT('A', encounter_id) as encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, |
| 128 | 141 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
| 129 | 142 | FROM sightings |
@@ -144,14 +157,16 @@ discard block |
||
| 144 | 157 | // Single Pokemon |
| 145 | 158 | /////////////////// |
| 146 | 159 | |
| 147 | - function getGymsProtectedByPokemon($pokemon_id) { |
|
| 160 | + function getGymsProtectedByPokemon($pokemon_id) |
|
| 161 | + { |
|
| 148 | 162 | $req = "SELECT COUNT(DISTINCT(fort_id)) AS total FROM fort_sightings WHERE guard_pokemon_id = '".$pokemon_id."'"; |
| 149 | 163 | $result = pg_query($this->db, $req); |
| 150 | 164 | $data = pg_fetch_object($result); |
| 151 | 165 | return $data; |
| 152 | 166 | } |
| 153 | 167 | |
| 154 | - function getPokemonLastSeen($pokemon_id) { |
|
| 168 | + function getPokemonLastSeen($pokemon_id) |
|
| 169 | + { |
|
| 155 | 170 | $req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
| 156 | 171 | FROM sightings |
| 157 | 172 | WHERE pokemon_id = '".$pokemon_id."' |
@@ -162,7 +177,8 @@ discard block |
||
| 162 | 177 | return $data; |
| 163 | 178 | } |
| 164 | 179 | |
| 165 | - function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) { |
|
| 180 | + function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 181 | + { |
|
| 166 | 182 | $req = "SELECT encounter_id, expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS distime, pokemon_id as pokemon_id, TO_TIMESTAMP(expire_timestamp) as disappear_time, lat as latitude, lon as longitude, |
| 167 | 183 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
| 168 | 184 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS \"IV\", move_1 as move_1, move_2, form |
@@ -178,7 +194,8 @@ discard block |
||
| 178 | 194 | return $top; |
| 179 | 195 | } |
| 180 | 196 | |
| 181 | - function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
|
| 197 | + function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 198 | + { |
|
| 182 | 199 | $trainer_blacklist = ""; |
| 183 | 200 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 184 | 201 | $trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')"; |
@@ -199,7 +216,8 @@ discard block |
||
| 199 | 216 | return $toptrainer; |
| 200 | 217 | } |
| 201 | 218 | |
| 202 | - public function getPokemonHeatmap($pokemon_id, $start, $end) { |
|
| 219 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 220 | + { |
|
| 203 | 221 | $where = " WHERE pokemon_id = ".$pokemon_id." " |
| 204 | 222 | . "AND TO_TIMESTAMP(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
| 205 | 223 | $req = "SELECT lat AS latitude, lon AS longitude FROM sightings".$where." ORDER BY expire_timestamp DESC LIMIT 100000"; |
@@ -211,7 +229,8 @@ discard block |
||
| 211 | 229 | return $points; |
| 212 | 230 | } |
| 213 | 231 | |
| 214 | - public function getPokemonGraph($pokemon_id) { |
|
| 232 | + public function getPokemonGraph($pokemon_id) |
|
| 233 | + { |
|
| 215 | 234 | $req = "SELECT COUNT(*) AS total, EXTRACT(HOUR FROM disappear_time) AS disappear_hour |
| 216 | 235 | FROM (SELECT TO_TIMESTAMP(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered |
| 217 | 236 | GROUP BY disappear_hour |
@@ -227,7 +246,8 @@ discard block |
||
| 227 | 246 | return $array; |
| 228 | 247 | } |
| 229 | 248 | |
| 230 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
|
| 249 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
| 250 | + { |
|
| 231 | 251 | $inmap_pkms_filter = ""; |
| 232 | 252 | $where = " WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = " . $pokemon_id; |
| 233 | 253 | |
@@ -263,14 +283,16 @@ discard block |
||
| 263 | 283 | return $spawns; |
| 264 | 284 | } |
| 265 | 285 | |
| 266 | - public function getPokemonSliederMinMax() { |
|
| 286 | + public function getPokemonSliederMinMax() |
|
| 287 | + { |
|
| 267 | 288 | $req = "SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings"; |
| 268 | 289 | $result = pg_query($this->db, $req); |
| 269 | 290 | $data = pg_fetch_object($result); |
| 270 | 291 | return $data; |
| 271 | 292 | } |
| 272 | 293 | |
| 273 | - public function getMapsCoords() { |
|
| 294 | + public function getMapsCoords() |
|
| 295 | + { |
|
| 274 | 296 | $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 | 297 | $result = pg_query($this->db, $req); |
| 276 | 298 | $data = pg_fetch_object($result); |
@@ -283,14 +305,16 @@ discard block |
||
| 283 | 305 | ////////////// |
| 284 | 306 | |
| 285 | 307 | |
| 286 | - function getTotalPokestops() { |
|
| 308 | + function getTotalPokestops() |
|
| 309 | + { |
|
| 287 | 310 | $req = "SELECT COUNT(*) as total FROM pokestops"; |
| 288 | 311 | $result = pg_query($this->db, $req); |
| 289 | 312 | $data = pg_fetch_object($result); |
| 290 | 313 | return $data; |
| 291 | 314 | } |
| 292 | 315 | |
| 293 | - public function getAllPokestops() { |
|
| 316 | + public function getAllPokestops() |
|
| 317 | + { |
|
| 294 | 318 | $req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, EXTRACT(EPOCH FROM NOW()) AS now, null AS lure_expiration_real FROM pokestops"; |
| 295 | 319 | $result = pg_query($this->db, $req); |
| 296 | 320 | $pokestops = array(); |
@@ -305,7 +329,8 @@ discard block |
||
| 305 | 329 | // Gyms |
| 306 | 330 | ///////// |
| 307 | 331 | |
| 308 | - function getTeamGuardians($team_id) { |
|
| 332 | + function getTeamGuardians($team_id) |
|
| 333 | + { |
|
| 309 | 334 | $req = "SELECT COUNT(*) AS total, guard_pokemon_id FROM fort_sightings WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 3 OFFSET 0"; |
| 310 | 335 | $result = pg_query($this->db, $req); |
| 311 | 336 | |
@@ -317,7 +342,8 @@ discard block |
||
| 317 | 342 | return $datas; |
| 318 | 343 | } |
| 319 | 344 | |
| 320 | - function getOwnedAndPoints($team_id) { |
|
| 345 | + function getOwnedAndPoints($team_id) |
|
| 346 | + { |
|
| 321 | 347 | $req = "SELECT COUNT(DISTINCT(fs.fort_id)) AS total, ROUND((SUM(gd.cp)) / COUNT(DISTINCT(fs.fort_id)),0) AS average_points |
| 322 | 348 | FROM fort_sightings fs |
| 323 | 349 | JOIN gym_defenders gd ON fs.fort_id = gd.fort_id |
@@ -327,7 +353,8 @@ discard block |
||
| 327 | 353 | return $data; |
| 328 | 354 | } |
| 329 | 355 | |
| 330 | - function getAllGyms() { |
|
| 356 | + function getAllGyms() |
|
| 357 | + { |
|
| 331 | 358 | $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 FROM forts f LEFT JOIN fort_sightings fs ON f.id = fs.fort_id;"; |
| 332 | 359 | $result = pg_query($this->db, $req); |
| 333 | 360 | $gyms = array(); |
@@ -337,7 +364,8 @@ discard block |
||
| 337 | 364 | return $gyms; |
| 338 | 365 | } |
| 339 | 366 | |
| 340 | - public function getGymData($gym_id) { |
|
| 367 | + public function getGymData($gym_id) |
|
| 368 | + { |
|
| 341 | 369 | $req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, TO_TIMESTAMP(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, SUM(gd.cp) as total_cp |
| 342 | 370 | FROM fort_sightings fs |
| 343 | 371 | LEFT JOIN forts f ON f.id = fs.fort_id |
@@ -349,7 +377,8 @@ discard block |
||
| 349 | 377 | return $data; |
| 350 | 378 | } |
| 351 | 379 | |
| 352 | - public function getGymDefenders($gym_id) { |
|
| 380 | + public function getGymDefenders($gym_id) |
|
| 381 | + { |
|
| 353 | 382 | $req = "SELECT DISTINCT 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 |
| 354 | 383 | FROM gym_defenders |
| 355 | 384 | WHERE fort_id='".$gym_id."' |
@@ -367,7 +396,8 @@ discard block |
||
| 367 | 396 | // Raids |
| 368 | 397 | /////////// |
| 369 | 398 | |
| 370 | - public function getAllRaids($page) { |
|
| 399 | + public function getAllRaids($page) |
|
| 400 | + { |
|
| 371 | 401 | $limit = " LIMIT 10 OFFSET ". ($page * 10); |
| 372 | 402 | $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, TO_TIMESTAMP(r.time_spawn) AS spawn, TO_TIMESTAMP(r.time_battle) AS start, TO_TIMESTAMP(r.time_end) AS end, TO_TIMESTAMP(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude |
| 373 | 403 | FROM raids r |
@@ -388,11 +418,13 @@ discard block |
||
| 388 | 418 | // Trainers |
| 389 | 419 | ////////////// |
| 390 | 420 | |
| 391 | - public function getTrainers($trainer_name, $team, $page, $ranking) { |
|
| 421 | + public function getTrainers($trainer_name, $team, $page, $ranking) |
|
| 422 | + { |
|
| 392 | 423 | return array(); // Waiting for Monocle to store level |
| 393 | 424 | } |
| 394 | 425 | |
| 395 | - public function getTrainerLevelCount($team_id) { |
|
| 426 | + public function getTrainerLevelCount($team_id) |
|
| 427 | + { |
|
| 396 | 428 | $levelData = array(); |
| 397 | 429 | for ($i = 5; $i <= 40; $i++) { |
| 398 | 430 | if (!isset($levelData[$i])) { |
@@ -407,7 +439,8 @@ discard block |
||
| 407 | 439 | // Cron |
| 408 | 440 | ///////// |
| 409 | 441 | |
| 410 | - public function getPokemonCountsActive() { |
|
| 442 | + public function getPokemonCountsActive() |
|
| 443 | + { |
|
| 411 | 444 | $req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) GROUP BY pokemon_id"; |
| 412 | 445 | $result = pg_query($this->db, $req); |
| 413 | 446 | $counts = array(); |
@@ -417,7 +450,8 @@ discard block |
||
| 417 | 450 | return $counts; |
| 418 | 451 | } |
| 419 | 452 | |
| 420 | - public function getPoekmonCountsLastDay() { |
|
| 453 | + public function getPoekmonCountsLastDay() |
|
| 454 | + { |
|
| 421 | 455 | $req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day |
| 422 | 456 | FROM sightings |
| 423 | 457 | WHERE TO_TIMESTAMP(expire_timestamp) >= (SELECT TO_TIMESTAMP(MAX(expire_timestamp)) FROM sightings) - INTERVAL 1 DAY |
@@ -431,7 +465,8 @@ discard block |
||
| 431 | 465 | return $counts; |
| 432 | 466 | } |
| 433 | 467 | |
| 434 | - public function getPokemonSinceLastUpdate($pokemon_id, $last_update) { |
|
| 468 | + public function getPokemonSinceLastUpdate($pokemon_id, $last_update) |
|
| 469 | + { |
|
| 435 | 470 | $where = "WHERE pokemon_id = '".$pokemon_id."' AND id > '".$last_update."'"; |
| 436 | 471 | $req = "SELECT count, id AS last_timestamp, (TO_TIMESTAMP(expire_timestamp)) AS disappear_time_real, lat as latitude, lon as longitude |
| 437 | 472 | FROM sightings |
@@ -447,7 +482,8 @@ discard block |
||
| 447 | 482 | return $data; |
| 448 | 483 | } |
| 449 | 484 | |
| 450 | - public function getRaidsSinceLastUpdate($pokemon_id, $last_update) { |
|
| 485 | + public function getRaidsSinceLastUpdate($pokemon_id, $last_update) |
|
| 486 | + { |
|
| 451 | 487 | $where = "WHERE pokemon_id = '".$pokemon_id."' AND time_battle > '".$last_update."'"; |
| 452 | 488 | $req = "SELECT time_battle AS start_timestamp, time_end as end, (TO_TIMESTAMP(time_end)) AS end_time_real, lat as latitude, lon as longitude, count |
| 453 | 489 | FROM raids r |
@@ -464,14 +500,16 @@ discard block |
||
| 464 | 500 | return $data; |
| 465 | 501 | } |
| 466 | 502 | |
| 467 | - public function getCaptchaCount() { |
|
| 503 | + public function getCaptchaCount() |
|
| 504 | + { |
|
| 468 | 505 | $req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL"; |
| 469 | 506 | $result = pg_query($this->db, $req); |
| 470 | 507 | $data = pg_fetch_object($result); |
| 471 | 508 | return $data; |
| 472 | 509 | } |
| 473 | 510 | |
| 474 | - public function getNestData() { |
|
| 511 | + public function getNestData() |
|
| 512 | + { |
|
| 475 | 513 | $pokemon_exclude_sql = ""; |
| 476 | 514 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 477 | 515 | $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")"; |