| @@ 442-458 (lines=17) @@ | ||
| 439 | // Raids |
|
| 440 | /////////// |
|
| 441 | ||
| 442 | public function getAllRaids($page) |
|
| 443 | { |
|
| 444 | $limit = ' LIMIT '.($page * 10).',10'; |
|
| 445 | $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 |
|
| 446 | FROM forts f |
|
| 447 | 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)) |
|
| 448 | LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP()) |
|
| 449 | WHERE r.time_end > UNIX_TIMESTAMP() |
|
| 450 | ORDER BY r.level DESC, r.time_battle'.$limit; |
|
| 451 | $result = $this->mysqli->query($req); |
|
| 452 | $raids = array(); |
|
| 453 | while ($data = $result->fetch_object()) { |
|
| 454 | $raids[] = $data; |
|
| 455 | } |
|
| 456 | ||
| 457 | return $raids; |
|
| 458 | } |
|
| 459 | ||
| 460 | //////////////// |
|
| 461 | // Gym History |
|
| @@ 554-568 (lines=15) @@ | ||
| 551 | return array('last_page' => $last_page, 'data' => $history); |
|
| 552 | } |
|
| 553 | ||
| 554 | private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
| 555 | { |
|
| 556 | $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name |
|
| 557 | FROM gym_history_defenders ghd |
|
| 558 | JOIN gym_defenders gd ON ghd.defender_id = gd.external_id |
|
| 559 | WHERE ghd.fort_id = '".$gym_id."' AND date = '".$last_modified."' |
|
| 560 | ORDER BY gd.deployment_time"; |
|
| 561 | $result = $this->mysqli->query($req); |
|
| 562 | $pokemons = array(); |
|
| 563 | while ($data = $result->fetch_object()) { |
|
| 564 | $pokemons[$data->defender_id] = $data; |
|
| 565 | } |
|
| 566 | ||
| 567 | return $pokemons; |
|
| 568 | } |
|
| 569 | ||
| 570 | ////////////// |
|
| 571 | // Trainers |
|
| @@ 189-207 (lines=19) @@ | ||
| 186 | return $data; |
|
| 187 | } |
|
| 188 | ||
| 189 | public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 190 | { |
|
| 191 | $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime, |
|
| 192 | pokemon_id, disappear_time, latitude, longitude, |
|
| 193 | cp, individual_attack, individual_defense, individual_stamina, |
|
| 194 | ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, |
|
| 195 | move_1, move_2, form |
|
| 196 | FROM pokemon |
|
| 197 | WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 198 | ORDER BY $top_order_by $top_direction, disappear_time DESC |
|
| 199 | LIMIT 0,50"; |
|
| 200 | $result = $this->mysqli->query($req); |
|
| 201 | $top = array(); |
|
| 202 | while ($data = $result->fetch_object()) { |
|
| 203 | $top[] = $data; |
|
| 204 | } |
|
| 205 | ||
| 206 | return $top; |
|
| 207 | } |
|
| 208 | ||
| 209 | public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 210 | { |
|
| @@ 232-245 (lines=14) @@ | ||
| 229 | return $toptrainer; |
|
| 230 | } |
|
| 231 | ||
| 232 | public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 233 | { |
|
| 234 | $req = "SELECT latitude, longitude |
|
| 235 | FROM pokemon |
|
| 236 | WHERE pokemon_id = ".$pokemon_id." AND disappear_time BETWEEN '".$start."' AND '".$end."' |
|
| 237 | LIMIT 10000"; |
|
| 238 | $result = $this->mysqli->query($req); |
|
| 239 | $points = array(); |
|
| 240 | while ($data = $result->fetch_object()) { |
|
| 241 | $points[] = $data; |
|
| 242 | } |
|
| 243 | ||
| 244 | return $points; |
|
| 245 | } |
|
| 246 | ||
| 247 | public function getPokemonGraph($pokemon_id) |
|
| 248 | { |
|
| @@ 690-710 (lines=21) @@ | ||
| 687 | return $data; |
|
| 688 | } |
|
| 689 | ||
| 690 | private function getTrainerActivePokemon($trainer_name) |
|
| 691 | { |
|
| 692 | $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 693 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
|
| 694 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
|
| 695 | filtered_gymmember.gym_id, |
|
| 696 | CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, |
|
| 697 | '1' AS active |
|
| 698 | FROM gympokemon INNER JOIN |
|
| 699 | (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 |
|
| 700 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
|
| 701 | WHERE gympokemon.trainer_name='".$trainer_name."' |
|
| 702 | ORDER BY gympokemon.cp DESC"; |
|
| 703 | $result = $this->mysqli->query($req); |
|
| 704 | $pokemons = array(); |
|
| 705 | while ($data = $result->fetch_object()) { |
|
| 706 | $pokemons[] = $data; |
|
| 707 | } |
|
| 708 | ||
| 709 | return $pokemons; |
|
| 710 | } |
|
| 711 | ||
| 712 | private function getTrainerInactivePokemon($trainer_name) |
|
| 713 | { |
|
| @@ 712-732 (lines=21) @@ | ||
| 709 | return $pokemons; |
|
| 710 | } |
|
| 711 | ||
| 712 | private function getTrainerInactivePokemon($trainer_name) |
|
| 713 | { |
|
| 714 | $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 715 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
|
| 716 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
|
| 717 | null AS gym_id, |
|
| 718 | CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, |
|
| 719 | '0' AS active |
|
| 720 | FROM gympokemon LEFT JOIN |
|
| 721 | (SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember |
|
| 722 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
|
| 723 | WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."' |
|
| 724 | ORDER BY gympokemon.cp DESC"; |
|
| 725 | $result = $this->mysqli->query($req); |
|
| 726 | $pokemons = array(); |
|
| 727 | while ($data = $result->fetch_object()) { |
|
| 728 | $pokemons[] = $data; |
|
| 729 | } |
|
| 730 | ||
| 731 | return $pokemons; |
|
| 732 | } |
|
| 733 | ||
| 734 | ///////// |
|
| 735 | // Cron |
|