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