@@ -8,143 +8,143 @@ |
||
| 8 | 8 | |
| 9 | 9 | abstract class QueryManager |
| 10 | 10 | { |
| 11 | - protected static $time_offset; |
|
| 12 | - protected static $config; |
|
| 13 | - |
|
| 14 | - private static $current; |
|
| 15 | - |
|
| 16 | - public static function current() |
|
| 17 | - { |
|
| 18 | - global $time_offset; |
|
| 19 | - |
|
| 20 | - if (null == self::$current) { |
|
| 21 | - $variables = realpath(dirname(__FILE__)).'/../../json/variables.json'; |
|
| 22 | - self::$config = json_decode(file_get_contents($variables)); |
|
| 23 | - |
|
| 24 | - include_once SYS_PATH.'/core/process/timezone.loader.php'; |
|
| 25 | - self::$time_offset = $time_offset; |
|
| 26 | - |
|
| 27 | - switch (strtolower(SYS_DB_TYPE)) { |
|
| 28 | - case 'rdm': |
|
| 29 | - case 'realdevicemap': |
|
| 30 | - self::$current = new QueryManagerMysqlRealDeviceMap(); |
|
| 31 | - break; |
|
| 32 | - case 'monocle-alt': |
|
| 33 | - case 'monocle-alt-mysql': |
|
| 34 | - self::$current = new QueryManagerMysqlMonocleAlternate(); |
|
| 35 | - break; |
|
| 36 | - case 'monocle-alt-pgsql': |
|
| 37 | - self::$current = new QueryManagerPostgresqlMonocleAlternate(); |
|
| 38 | - break; |
|
| 11 | + protected static $time_offset; |
|
| 12 | + protected static $config; |
|
| 13 | + |
|
| 14 | + private static $current; |
|
| 15 | + |
|
| 16 | + public static function current() |
|
| 17 | + { |
|
| 18 | + global $time_offset; |
|
| 19 | + |
|
| 20 | + if (null == self::$current) { |
|
| 21 | + $variables = realpath(dirname(__FILE__)).'/../../json/variables.json'; |
|
| 22 | + self::$config = json_decode(file_get_contents($variables)); |
|
| 23 | + |
|
| 24 | + include_once SYS_PATH.'/core/process/timezone.loader.php'; |
|
| 25 | + self::$time_offset = $time_offset; |
|
| 26 | + |
|
| 27 | + switch (strtolower(SYS_DB_TYPE)) { |
|
| 28 | + case 'rdm': |
|
| 29 | + case 'realdevicemap': |
|
| 30 | + self::$current = new QueryManagerMysqlRealDeviceMap(); |
|
| 31 | + break; |
|
| 32 | + case 'monocle-alt': |
|
| 33 | + case 'monocle-alt-mysql': |
|
| 34 | + self::$current = new QueryManagerMysqlMonocleAlternate(); |
|
| 35 | + break; |
|
| 36 | + case 'monocle-alt-pgsql': |
|
| 37 | + self::$current = new QueryManagerPostgresqlMonocleAlternate(); |
|
| 38 | + break; |
|
| 39 | 39 | case 'mad': |
| 40 | - self::$current = new QueryManagerMysqlMAD(); |
|
| 41 | - break; |
|
| 42 | - default: //rocketmap |
|
| 43 | - self::$current = new QueryManagerMysqlRocketmap(); |
|
| 44 | - break; |
|
| 45 | - } |
|
| 46 | - } |
|
| 40 | + self::$current = new QueryManagerMysqlMAD(); |
|
| 41 | + break; |
|
| 42 | + default: //rocketmap |
|
| 43 | + self::$current = new QueryManagerMysqlRocketmap(); |
|
| 44 | + break; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - return self::$current; |
|
| 49 | - } |
|
| 48 | + return self::$current; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - private function __construct() |
|
| 52 | - { |
|
| 53 | - } |
|
| 51 | + private function __construct() |
|
| 52 | + { |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // Misc |
|
| 56 | - abstract public function getEcapedString($string); |
|
| 55 | + // Misc |
|
| 56 | + abstract public function getEcapedString($string); |
|
| 57 | 57 | |
| 58 | - // Tester |
|
| 59 | - abstract public function testTotalPokemon(); |
|
| 58 | + // Tester |
|
| 59 | + abstract public function testTotalPokemon(); |
|
| 60 | 60 | |
| 61 | - abstract public function testTotalGyms(); |
|
| 61 | + abstract public function testTotalGyms(); |
|
| 62 | 62 | |
| 63 | - abstract public function testTotalPokestops(); |
|
| 63 | + abstract public function testTotalPokestops(); |
|
| 64 | 64 | |
| 65 | - // Homepage |
|
| 66 | - abstract public function getTotalPokemon(); |
|
| 65 | + // Homepage |
|
| 66 | + abstract public function getTotalPokemon(); |
|
| 67 | 67 | |
| 68 | - abstract public function getTotalLures(); |
|
| 68 | + abstract public function getTotalLures(); |
|
| 69 | 69 | |
| 70 | - abstract public function getTotalGyms(); |
|
| 70 | + abstract public function getTotalGyms(); |
|
| 71 | 71 | |
| 72 | - abstract public function getTotalRaids(); |
|
| 72 | + abstract public function getTotalRaids(); |
|
| 73 | 73 | |
| 74 | - abstract public function getTotalGymsForTeam($team_id); |
|
| 74 | + abstract public function getTotalGymsForTeam($team_id); |
|
| 75 | 75 | |
| 76 | - abstract public function getRecentAll(); |
|
| 76 | + abstract public function getRecentAll(); |
|
| 77 | 77 | |
| 78 | - abstract public function getRecentMythic($mythic_pokemon); |
|
| 78 | + abstract public function getRecentMythic($mythic_pokemon); |
|
| 79 | 79 | |
| 80 | - // Single Pokemon |
|
| 81 | - abstract public function getGymsProtectedByPokemon($pokemon_id); |
|
| 80 | + // Single Pokemon |
|
| 81 | + abstract public function getGymsProtectedByPokemon($pokemon_id); |
|
| 82 | 82 | |
| 83 | - abstract public function getPokemonLastSeen($pokemon_id); |
|
| 83 | + abstract public function getPokemonLastSeen($pokemon_id); |
|
| 84 | 84 | |
| 85 | - abstract public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction); |
|
| 85 | + abstract public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction); |
|
| 86 | 86 | |
| 87 | - abstract public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction); |
|
| 87 | + abstract public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction); |
|
| 88 | 88 | |
| 89 | - abstract public function getPokemonHeatmap($pokemon_id, $start, $end); |
|
| 89 | + abstract public function getPokemonHeatmap($pokemon_id, $start, $end); |
|
| 90 | 90 | |
| 91 | - abstract public function getPokemonGraph($pokemon_id); |
|
| 91 | + abstract public function getPokemonGraph($pokemon_id); |
|
| 92 | 92 | |
| 93 | - abstract public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons); |
|
| 93 | + abstract public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons); |
|
| 94 | 94 | |
| 95 | - abstract public function getPokemonSliderMinMax(); |
|
| 95 | + abstract public function getPokemonSliderMinMax(); |
|
| 96 | 96 | |
| 97 | - abstract public function getMapsCoords(); |
|
| 97 | + abstract public function getMapsCoords(); |
|
| 98 | 98 | |
| 99 | - abstract public function getPokemonCount($pokemon_id); |
|
| 99 | + abstract public function getPokemonCount($pokemon_id); |
|
| 100 | 100 | |
| 101 | - abstract public function getPokemonCountAll(); |
|
| 101 | + abstract public function getPokemonCountAll(); |
|
| 102 | 102 | |
| 103 | - abstract public function getRaidCount($pokemon_id); |
|
| 103 | + abstract public function getRaidCount($pokemon_id); |
|
| 104 | 104 | |
| 105 | - abstract public function getRaidCountAll(); |
|
| 105 | + abstract public function getRaidCountAll(); |
|
| 106 | 106 | |
| 107 | - // Pokestops |
|
| 108 | - abstract public function getTotalPokestops(); |
|
| 107 | + // Pokestops |
|
| 108 | + abstract public function getTotalPokestops(); |
|
| 109 | 109 | |
| 110 | - abstract public function getAllPokestops(); |
|
| 110 | + abstract public function getAllPokestops(); |
|
| 111 | 111 | |
| 112 | - // Gyms |
|
| 113 | - abstract public function getTeamGuardians($team_id); |
|
| 112 | + // Gyms |
|
| 113 | + abstract public function getTeamGuardians($team_id); |
|
| 114 | 114 | |
| 115 | - abstract public function getOwnedAndPoints($team_id); |
|
| 115 | + abstract public function getOwnedAndPoints($team_id); |
|
| 116 | 116 | |
| 117 | - abstract public function getAllGyms(); |
|
| 117 | + abstract public function getAllGyms(); |
|
| 118 | 118 | |
| 119 | - abstract public function getGymData($gym_id); |
|
| 119 | + abstract public function getGymData($gym_id); |
|
| 120 | 120 | |
| 121 | - abstract public function getGymDefenders($gym_id); |
|
| 121 | + abstract public function getGymDefenders($gym_id); |
|
| 122 | 122 | |
| 123 | - // Gym History |
|
| 124 | - abstract public function getGymHistories($gym_name, $team, $page, $ranking); |
|
| 123 | + // Gym History |
|
| 124 | + abstract public function getGymHistories($gym_name, $team, $page, $ranking); |
|
| 125 | 125 | |
| 126 | - abstract public function getGymHistoriesPokemon($gym_id); |
|
| 126 | + abstract public function getGymHistoriesPokemon($gym_id); |
|
| 127 | 127 | |
| 128 | - abstract public function getHistoryForGym($page, $gym_id); |
|
| 128 | + abstract public function getHistoryForGym($page, $gym_id); |
|
| 129 | 129 | |
| 130 | - // Raids |
|
| 131 | - abstract public function getAllRaids($page); |
|
| 130 | + // Raids |
|
| 131 | + abstract public function getAllRaids($page); |
|
| 132 | 132 | |
| 133 | - // Trainers |
|
| 134 | - abstract public function getTrainers($trainer_name, $team, $page, $ranking); |
|
| 133 | + // Trainers |
|
| 134 | + abstract public function getTrainers($trainer_name, $team, $page, $ranking); |
|
| 135 | 135 | |
| 136 | - abstract public function getTrainerLevelCount($team_id); |
|
| 136 | + abstract public function getTrainerLevelCount($team_id); |
|
| 137 | 137 | |
| 138 | - // Cron |
|
| 139 | - abstract public function getPokemonCountsActive(); |
|
| 138 | + // Cron |
|
| 139 | + abstract public function getPokemonCountsActive(); |
|
| 140 | 140 | |
| 141 | - abstract public function getTotalPokemonIV(); |
|
| 141 | + abstract public function getTotalPokemonIV(); |
|
| 142 | 142 | |
| 143 | - abstract public function getPokemonCountsLastDay(); |
|
| 143 | + abstract public function getPokemonCountsLastDay(); |
|
| 144 | 144 | |
| 145 | - abstract public function getCaptchaCount(); |
|
| 145 | + abstract public function getCaptchaCount(); |
|
| 146 | 146 | |
| 147 | - abstract public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude); |
|
| 147 | + abstract public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude); |
|
| 148 | 148 | |
| 149 | - abstract public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude); |
|
| 149 | + abstract public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude); |
|
| 150 | 150 | } |
@@ -4,193 +4,193 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | final class QueryManagerMysqlMAD extends QueryManagerMysql |
| 6 | 6 | { |
| 7 | - public function __construct() |
|
| 8 | - { |
|
| 9 | - parent::__construct(); |
|
| 10 | - } |
|
| 11 | - |
|
| 12 | - public function __destruct() |
|
| 13 | - { |
|
| 14 | - parent::__destruct(); |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - /////////// |
|
| 18 | - // Tester |
|
| 19 | - /////////// |
|
| 20 | - |
|
| 21 | - public function testTotalPokemon() |
|
| 22 | - { |
|
| 23 | - $req = 'SELECT COUNT(*) as total FROM pokemon'; |
|
| 24 | - $result = $this->mysqli->query($req); |
|
| 25 | - if (!is_object($result)) { |
|
| 26 | - return 1; |
|
| 27 | - } else { |
|
| 28 | - $data = $result->fetch_object(); |
|
| 29 | - $total = $data->total; |
|
| 30 | - |
|
| 31 | - if (0 == $total) { |
|
| 32 | - return 2; |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - return 0; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function testTotalGyms() |
|
| 40 | - { |
|
| 41 | - $req = 'SELECT COUNT(*) as total FROM gym'; |
|
| 42 | - $result = $this->mysqli->query($req); |
|
| 43 | - if (!is_object($result)) { |
|
| 44 | - return 1; |
|
| 45 | - } else { |
|
| 46 | - $data = $result->fetch_object(); |
|
| 47 | - $total = $data->total; |
|
| 48 | - |
|
| 49 | - if (0 == $total) { |
|
| 50 | - return 2; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return 0; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function testTotalPokestops() |
|
| 58 | - { |
|
| 59 | - $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
| 60 | - $result = $this->mysqli->query($req); |
|
| 61 | - if (!is_object($result)) { |
|
| 62 | - return 1; |
|
| 63 | - } else { |
|
| 64 | - $data = $result->fetch_object(); |
|
| 65 | - $total = $data->total; |
|
| 66 | - |
|
| 67 | - if (0 == $total) { |
|
| 68 | - return 2; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return 0; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - ///////////// |
|
| 76 | - // Homepage |
|
| 77 | - ///////////// |
|
| 78 | - |
|
| 79 | - public function getTotalPokemon() |
|
| 80 | - { |
|
| 81 | - $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()'; |
|
| 82 | - $result = $this->mysqli->query($req); |
|
| 83 | - $data = $result->fetch_object(); |
|
| 84 | - |
|
| 85 | - return $data; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function getTotalLures() |
|
| 89 | - { |
|
| 90 | - $req = 'SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()'; |
|
| 91 | - $result = $this->mysqli->query($req); |
|
| 92 | - $data = $result->fetch_object(); |
|
| 93 | - |
|
| 94 | - return $data; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function getTotalGyms() |
|
| 98 | - { |
|
| 99 | - $req = 'SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym'; |
|
| 100 | - $result = $this->mysqli->query($req); |
|
| 101 | - $data = $result->fetch_object(); |
|
| 102 | - |
|
| 103 | - return $data; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function getTotalRaids() |
|
| 107 | - { |
|
| 108 | - $req = 'SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP() AND end >= UTC_TIMESTAMP()'; |
|
| 109 | - $result = $this->mysqli->query($req); |
|
| 110 | - $data = $result->fetch_object(); |
|
| 111 | - |
|
| 112 | - return $data; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function getTotalGymsForTeam($team_id) |
|
| 116 | - { |
|
| 117 | - $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'"; |
|
| 118 | - $result = $this->mysqli->query($req); |
|
| 119 | - $data = $result->fetch_object(); |
|
| 120 | - |
|
| 121 | - return $data; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function getRecentAll() |
|
| 125 | - { |
|
| 126 | - $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, |
|
| 7 | + public function __construct() |
|
| 8 | + { |
|
| 9 | + parent::__construct(); |
|
| 10 | + } |
|
| 11 | + |
|
| 12 | + public function __destruct() |
|
| 13 | + { |
|
| 14 | + parent::__destruct(); |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + /////////// |
|
| 18 | + // Tester |
|
| 19 | + /////////// |
|
| 20 | + |
|
| 21 | + public function testTotalPokemon() |
|
| 22 | + { |
|
| 23 | + $req = 'SELECT COUNT(*) as total FROM pokemon'; |
|
| 24 | + $result = $this->mysqli->query($req); |
|
| 25 | + if (!is_object($result)) { |
|
| 26 | + return 1; |
|
| 27 | + } else { |
|
| 28 | + $data = $result->fetch_object(); |
|
| 29 | + $total = $data->total; |
|
| 30 | + |
|
| 31 | + if (0 == $total) { |
|
| 32 | + return 2; |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + return 0; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function testTotalGyms() |
|
| 40 | + { |
|
| 41 | + $req = 'SELECT COUNT(*) as total FROM gym'; |
|
| 42 | + $result = $this->mysqli->query($req); |
|
| 43 | + if (!is_object($result)) { |
|
| 44 | + return 1; |
|
| 45 | + } else { |
|
| 46 | + $data = $result->fetch_object(); |
|
| 47 | + $total = $data->total; |
|
| 48 | + |
|
| 49 | + if (0 == $total) { |
|
| 50 | + return 2; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return 0; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function testTotalPokestops() |
|
| 58 | + { |
|
| 59 | + $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
| 60 | + $result = $this->mysqli->query($req); |
|
| 61 | + if (!is_object($result)) { |
|
| 62 | + return 1; |
|
| 63 | + } else { |
|
| 64 | + $data = $result->fetch_object(); |
|
| 65 | + $total = $data->total; |
|
| 66 | + |
|
| 67 | + if (0 == $total) { |
|
| 68 | + return 2; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return 0; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + ///////////// |
|
| 76 | + // Homepage |
|
| 77 | + ///////////// |
|
| 78 | + |
|
| 79 | + public function getTotalPokemon() |
|
| 80 | + { |
|
| 81 | + $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()'; |
|
| 82 | + $result = $this->mysqli->query($req); |
|
| 83 | + $data = $result->fetch_object(); |
|
| 84 | + |
|
| 85 | + return $data; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function getTotalLures() |
|
| 89 | + { |
|
| 90 | + $req = 'SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()'; |
|
| 91 | + $result = $this->mysqli->query($req); |
|
| 92 | + $data = $result->fetch_object(); |
|
| 93 | + |
|
| 94 | + return $data; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function getTotalGyms() |
|
| 98 | + { |
|
| 99 | + $req = 'SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym'; |
|
| 100 | + $result = $this->mysqli->query($req); |
|
| 101 | + $data = $result->fetch_object(); |
|
| 102 | + |
|
| 103 | + return $data; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function getTotalRaids() |
|
| 107 | + { |
|
| 108 | + $req = 'SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP() AND end >= UTC_TIMESTAMP()'; |
|
| 109 | + $result = $this->mysqli->query($req); |
|
| 110 | + $data = $result->fetch_object(); |
|
| 111 | + |
|
| 112 | + return $data; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function getTotalGymsForTeam($team_id) |
|
| 116 | + { |
|
| 117 | + $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'"; |
|
| 118 | + $result = $this->mysqli->query($req); |
|
| 119 | + $data = $result->fetch_object(); |
|
| 120 | + |
|
| 121 | + return $data; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function getRecentAll() |
|
| 125 | + { |
|
| 126 | + $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, |
|
| 127 | 127 | CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real, |
| 128 | 128 | latitude, longitude, cp, individual_attack, individual_defense, individual_stamina |
| 129 | 129 | FROM pokemon |
| 130 | 130 | ORDER BY last_modified DESC |
| 131 | 131 | LIMIT 0,12"; |
| 132 | - $result = $this->mysqli->query($req); |
|
| 133 | - $data = array(); |
|
| 134 | - if ($result->num_rows > 0) { |
|
| 135 | - while ($row = $result->fetch_object()) { |
|
| 136 | - $data[] = $row; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $data; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - public function getRecentMythic($mythic_pokemons) |
|
| 144 | - { |
|
| 145 | - $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, |
|
| 132 | + $result = $this->mysqli->query($req); |
|
| 133 | + $data = array(); |
|
| 134 | + if ($result->num_rows > 0) { |
|
| 135 | + while ($row = $result->fetch_object()) { |
|
| 136 | + $data[] = $row; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $data; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + public function getRecentMythic($mythic_pokemons) |
|
| 144 | + { |
|
| 145 | + $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, |
|
| 146 | 146 | CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real, |
| 147 | 147 | latitude, longitude, cp, individual_attack, individual_defense, individual_stamina |
| 148 | 148 | FROM pokemon |
| 149 | 149 | WHERE pokemon_id IN (".implode(',', $mythic_pokemons).') |
| 150 | 150 | ORDER BY last_modified DESC |
| 151 | 151 | LIMIT 0,12'; |
| 152 | - $result = $this->mysqli->query($req); |
|
| 153 | - $data = array(); |
|
| 154 | - if ($result->num_rows > 0) { |
|
| 155 | - while ($row = $result->fetch_object()) { |
|
| 156 | - $data[] = $row; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $data; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /////////////////// |
|
| 164 | - // Single Pokemon |
|
| 165 | - /////////////////// |
|
| 166 | - |
|
| 167 | - public function getGymsProtectedByPokemon($pokemon_id) |
|
| 168 | - { |
|
| 169 | - $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'"; |
|
| 170 | - $result = $this->mysqli->query($req); |
|
| 171 | - $data = $result->fetch_object(); |
|
| 172 | - |
|
| 173 | - return $data; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - public function getPokemonLastSeen($pokemon_id) |
|
| 177 | - { |
|
| 178 | - $req = "SELECT disappear_time, |
|
| 152 | + $result = $this->mysqli->query($req); |
|
| 153 | + $data = array(); |
|
| 154 | + if ($result->num_rows > 0) { |
|
| 155 | + while ($row = $result->fetch_object()) { |
|
| 156 | + $data[] = $row; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $data; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /////////////////// |
|
| 164 | + // Single Pokemon |
|
| 165 | + /////////////////// |
|
| 166 | + |
|
| 167 | + public function getGymsProtectedByPokemon($pokemon_id) |
|
| 168 | + { |
|
| 169 | + $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'"; |
|
| 170 | + $result = $this->mysqli->query($req); |
|
| 171 | + $data = $result->fetch_object(); |
|
| 172 | + |
|
| 173 | + return $data; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + public function getPokemonLastSeen($pokemon_id) |
|
| 177 | + { |
|
| 178 | + $req = "SELECT disappear_time, |
|
| 179 | 179 | CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real, |
| 180 | 180 | latitude, longitude |
| 181 | 181 | FROM pokemon |
| 182 | 182 | WHERE pokemon_id = '".$pokemon_id."' |
| 183 | 183 | ORDER BY disappear_time DESC |
| 184 | 184 | LIMIT 0,1"; |
| 185 | - $result = $this->mysqli->query($req); |
|
| 186 | - $data = $result->fetch_object(); |
|
| 185 | + $result = $this->mysqli->query($req); |
|
| 186 | + $data = $result->fetch_object(); |
|
| 187 | 187 | |
| 188 | - return $data; |
|
| 189 | - } |
|
| 188 | + return $data; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 192 | - { |
|
| 193 | - $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime, |
|
| 191 | + public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 192 | + { |
|
| 193 | + $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime, |
|
| 194 | 194 | pokemon_id, disappear_time, latitude, longitude, |
| 195 | 195 | cp, individual_attack, individual_defense, individual_stamina, |
| 196 | 196 | ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, |
@@ -199,235 +199,235 @@ discard block |
||
| 199 | 199 | WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
| 200 | 200 | ORDER BY $top_order_by $top_direction, disappear_time DESC |
| 201 | 201 | LIMIT 0,50"; |
| 202 | - $result = $this->mysqli->query($req); |
|
| 203 | - $top = array(); |
|
| 204 | - while ($data = $result->fetch_object()) { |
|
| 205 | - $top[] = $data; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $top; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 212 | - { |
|
| 213 | - return null; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 217 | - { |
|
| 202 | + $result = $this->mysqli->query($req); |
|
| 203 | + $top = array(); |
|
| 204 | + while ($data = $result->fetch_object()) { |
|
| 205 | + $top[] = $data; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $top; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 212 | + { |
|
| 213 | + return null; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 217 | + { |
|
| 218 | 218 | $req = "SELECT latitude, longitude |
| 219 | 219 | FROM pokemon |
| 220 | 220 | WHERE pokemon_id = ".$pokemon_id." AND disappear_time BETWEEN '".$start."' AND '".$end."' |
| 221 | 221 | LIMIT 10000"; |
| 222 | - $result = $this->mysqli->query($req); |
|
| 223 | - $points = array(); |
|
| 224 | - while ($data = $result->fetch_object()) { |
|
| 225 | - $points[] = $data; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $points; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - public function getPokemonGraph($pokemon_id) |
|
| 232 | - { |
|
| 233 | - $req = "SELECT COUNT(*) AS total, |
|
| 222 | + $result = $this->mysqli->query($req); |
|
| 223 | + $points = array(); |
|
| 224 | + while ($data = $result->fetch_object()) { |
|
| 225 | + $points[] = $data; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $points; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + public function getPokemonGraph($pokemon_id) |
|
| 232 | + { |
|
| 233 | + $req = "SELECT COUNT(*) AS total, |
|
| 234 | 234 | HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour |
| 235 | 235 | FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
| 236 | 236 | GROUP BY disappear_hour |
| 237 | 237 | ORDER BY disappear_hour"; |
| 238 | - $result = $this->mysqli->query($req); |
|
| 239 | - $array = array_fill(0, 24, 0); |
|
| 240 | - while ($result && $data = $result->fetch_object()) { |
|
| 241 | - $array[$data->disappear_hour] = $data->total; |
|
| 242 | - } |
|
| 243 | - // shift array because AM/PM starts at 1AM not 0:00 |
|
| 244 | - $array[] = $array[0]; |
|
| 245 | - array_shift($array); |
|
| 246 | - |
|
| 247 | - return $array; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
| 251 | - { |
|
| 252 | - $inmap_pkms_filter = ''; |
|
| 253 | - $where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id; |
|
| 254 | - $reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where; |
|
| 255 | - $resultTestIv = $this->mysqli->query($reqTestIv); |
|
| 256 | - $testIv = $resultTestIv->fetch_object(); |
|
| 257 | - if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) { |
|
| 258 | - foreach ($inmap_pokemons as $inmap) { |
|
| 259 | - $inmap_pkms_filter .= "'".$inmap."',"; |
|
| 260 | - } |
|
| 261 | - $inmap_pkms_filter = rtrim($inmap_pkms_filter, ','); |
|
| 262 | - $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') '; |
|
| 263 | - } |
|
| 264 | - if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) { |
|
| 265 | - $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') '; |
|
| 266 | - } |
|
| 267 | - if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) { |
|
| 268 | - $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') '; |
|
| 269 | - } |
|
| 270 | - $req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time, |
|
| 238 | + $result = $this->mysqli->query($req); |
|
| 239 | + $array = array_fill(0, 24, 0); |
|
| 240 | + while ($result && $data = $result->fetch_object()) { |
|
| 241 | + $array[$data->disappear_hour] = $data->total; |
|
| 242 | + } |
|
| 243 | + // shift array because AM/PM starts at 1AM not 0:00 |
|
| 244 | + $array[] = $array[0]; |
|
| 245 | + array_shift($array); |
|
| 246 | + |
|
| 247 | + return $array; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
| 251 | + { |
|
| 252 | + $inmap_pkms_filter = ''; |
|
| 253 | + $where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id; |
|
| 254 | + $reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where; |
|
| 255 | + $resultTestIv = $this->mysqli->query($reqTestIv); |
|
| 256 | + $testIv = $resultTestIv->fetch_object(); |
|
| 257 | + if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) { |
|
| 258 | + foreach ($inmap_pokemons as $inmap) { |
|
| 259 | + $inmap_pkms_filter .= "'".$inmap."',"; |
|
| 260 | + } |
|
| 261 | + $inmap_pkms_filter = rtrim($inmap_pkms_filter, ','); |
|
| 262 | + $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') '; |
|
| 263 | + } |
|
| 264 | + if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) { |
|
| 265 | + $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') '; |
|
| 266 | + } |
|
| 267 | + if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) { |
|
| 268 | + $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') '; |
|
| 269 | + } |
|
| 270 | + $req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time, |
|
| 271 | 271 | CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real, |
| 272 | 272 | individual_attack, individual_defense, individual_stamina, move_1, move_2 |
| 273 | 273 | FROM pokemon ".$where.' |
| 274 | 274 | LIMIT 5000'; |
| 275 | - $result = $this->mysqli->query($req); |
|
| 276 | - $spawns = array(); |
|
| 277 | - while ($data = $result->fetch_object()) { |
|
| 278 | - $spawns[] = $data; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return $spawns; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - public function getPokemonSliderMinMax() |
|
| 285 | - { |
|
| 286 | - $req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon'; |
|
| 287 | - $result = $this->mysqli->query($req); |
|
| 288 | - $data = $result->fetch_object(); |
|
| 289 | - |
|
| 290 | - return $data; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - public function getMapsCoords() |
|
| 294 | - { |
|
| 295 | - $req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, |
|
| 275 | + $result = $this->mysqli->query($req); |
|
| 276 | + $spawns = array(); |
|
| 277 | + while ($data = $result->fetch_object()) { |
|
| 278 | + $spawns[] = $data; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return $spawns; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + public function getPokemonSliderMinMax() |
|
| 285 | + { |
|
| 286 | + $req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon'; |
|
| 287 | + $result = $this->mysqli->query($req); |
|
| 288 | + $data = $result->fetch_object(); |
|
| 289 | + |
|
| 290 | + return $data; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + public function getMapsCoords() |
|
| 294 | + { |
|
| 295 | + $req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, |
|
| 296 | 296 | MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude |
| 297 | 297 | FROM trs_spawn'; |
| 298 | - $result = $this->mysqli->query($req); |
|
| 299 | - $data = $result->fetch_object(); |
|
| 298 | + $result = $this->mysqli->query($req); |
|
| 299 | + $data = $result->fetch_object(); |
|
| 300 | 300 | |
| 301 | - return $data; |
|
| 302 | - } |
|
| 301 | + return $data; |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - public function getPokemonCount($pokemon_id) |
|
| 305 | - { |
|
| 306 | - $req = 'SELECT count, last_seen, latitude, longitude |
|
| 304 | + public function getPokemonCount($pokemon_id) |
|
| 305 | + { |
|
| 306 | + $req = 'SELECT count, last_seen, latitude, longitude |
|
| 307 | 307 | FROM pokemon_stats |
| 308 | 308 | WHERE pid = '.$pokemon_id; |
| 309 | - $result = $this->mysqli->query($req); |
|
| 310 | - $data = $result->fetch_object(); |
|
| 309 | + $result = $this->mysqli->query($req); |
|
| 310 | + $data = $result->fetch_object(); |
|
| 311 | 311 | |
| 312 | - return $data; |
|
| 313 | - } |
|
| 312 | + return $data; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - public function getPokemonCountAll() |
|
| 316 | - { |
|
| 317 | - $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
| 315 | + public function getPokemonCountAll() |
|
| 316 | + { |
|
| 317 | + $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
| 318 | 318 | FROM pokemon_stats |
| 319 | 319 | GROUP BY pid'; |
| 320 | - $result = $this->mysqli->query($req); |
|
| 321 | - $array = array(); |
|
| 322 | - while ($data = $result->fetch_object()) { |
|
| 323 | - $array[] = $data; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return $array; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - public function getRaidCount($pokemon_id) |
|
| 330 | - { |
|
| 331 | - $req = 'SELECT count, last_seen, latitude, longitude |
|
| 320 | + $result = $this->mysqli->query($req); |
|
| 321 | + $array = array(); |
|
| 322 | + while ($data = $result->fetch_object()) { |
|
| 323 | + $array[] = $data; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return $array; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + public function getRaidCount($pokemon_id) |
|
| 330 | + { |
|
| 331 | + $req = 'SELECT count, last_seen, latitude, longitude |
|
| 332 | 332 | FROM raid_stats |
| 333 | 333 | WHERE pid = '.$pokemon_id; |
| 334 | - $result = $this->mysqli->query($req); |
|
| 335 | - $data = $result->fetch_object(); |
|
| 334 | + $result = $this->mysqli->query($req); |
|
| 335 | + $data = $result->fetch_object(); |
|
| 336 | 336 | |
| 337 | - return $data; |
|
| 338 | - } |
|
| 337 | + return $data; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - public function getRaidCountAll() |
|
| 341 | - { |
|
| 342 | - $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
| 340 | + public function getRaidCountAll() |
|
| 341 | + { |
|
| 342 | + $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
| 343 | 343 | FROM raid_stats |
| 344 | 344 | GROUP BY pid'; |
| 345 | - $result = $this->mysqli->query($req); |
|
| 346 | - $array = array(); |
|
| 347 | - while ($data = $result->fetch_object()) { |
|
| 348 | - $array[] = $data; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return $array; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /////////////// |
|
| 355 | - // Pokestops |
|
| 356 | - ////////////// |
|
| 357 | - |
|
| 358 | - public function getTotalPokestops() |
|
| 359 | - { |
|
| 360 | - $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
| 361 | - $result = $this->mysqli->query($req); |
|
| 362 | - $data = $result->fetch_object(); |
|
| 363 | - |
|
| 364 | - return $data; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - public function getAllPokestops() |
|
| 368 | - { |
|
| 369 | - $req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now, |
|
| 345 | + $result = $this->mysqli->query($req); |
|
| 346 | + $array = array(); |
|
| 347 | + while ($data = $result->fetch_object()) { |
|
| 348 | + $array[] = $data; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return $array; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /////////////// |
|
| 355 | + // Pokestops |
|
| 356 | + ////////////// |
|
| 357 | + |
|
| 358 | + public function getTotalPokestops() |
|
| 359 | + { |
|
| 360 | + $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
| 361 | + $result = $this->mysqli->query($req); |
|
| 362 | + $data = $result->fetch_object(); |
|
| 363 | + |
|
| 364 | + return $data; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + public function getAllPokestops() |
|
| 368 | + { |
|
| 369 | + $req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now, |
|
| 370 | 370 | CONVERT_TZ(lure_expiration, '+00:00', '".self::$time_offset."') AS lure_expiration_real |
| 371 | 371 | FROM pokestop"; |
| 372 | - $result = $this->mysqli->query($req); |
|
| 373 | - $pokestops = array(); |
|
| 374 | - while ($data = $result->fetch_object()) { |
|
| 375 | - $pokestops[] = $data; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return $pokestops; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - ///////// |
|
| 382 | - // Gyms |
|
| 383 | - ///////// |
|
| 384 | - |
|
| 385 | - public function getTeamGuardians($team_id) |
|
| 386 | - { |
|
| 387 | - $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
|
| 372 | + $result = $this->mysqli->query($req); |
|
| 373 | + $pokestops = array(); |
|
| 374 | + while ($data = $result->fetch_object()) { |
|
| 375 | + $pokestops[] = $data; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return $pokestops; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + ///////// |
|
| 382 | + // Gyms |
|
| 383 | + ///////// |
|
| 384 | + |
|
| 385 | + public function getTeamGuardians($team_id) |
|
| 386 | + { |
|
| 387 | + $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
|
| 388 | 388 | FROM gym WHERE team_id = '".$team_id."' |
| 389 | 389 | GROUP BY guard_pokemon_id |
| 390 | 390 | ORDER BY total DESC |
| 391 | 391 | LIMIT 0,3"; |
| 392 | - $result = $this->mysqli->query($req); |
|
| 393 | - $datas = array(); |
|
| 394 | - while ($data = $result->fetch_object()) { |
|
| 395 | - $datas[] = $data; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - return $datas; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - public function getOwnedAndPoints($team_id) |
|
| 402 | - { |
|
| 403 | - $req = "SELECT COUNT(DISTINCT(gym_id)) AS total, |
|
| 392 | + $result = $this->mysqli->query($req); |
|
| 393 | + $datas = array(); |
|
| 394 | + while ($data = $result->fetch_object()) { |
|
| 395 | + $datas[] = $data; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + return $datas; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + public function getOwnedAndPoints($team_id) |
|
| 402 | + { |
|
| 403 | + $req = "SELECT COUNT(DISTINCT(gym_id)) AS total, |
|
| 404 | 404 | ROUND(AVG(total_cp),0) AS average_points |
| 405 | 405 | FROM gym |
| 406 | 406 | WHERE team_id = '".$team_id."'"; |
| 407 | - $result = $this->mysqli->query($req); |
|
| 408 | - $data = $result->fetch_object(); |
|
| 407 | + $result = $this->mysqli->query($req); |
|
| 408 | + $data = $result->fetch_object(); |
|
| 409 | 409 | |
| 410 | - return $data; |
|
| 411 | - } |
|
| 410 | + return $data; |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | - public function getAllGyms() |
|
| 414 | - { |
|
| 415 | - $req = "SELECT gym_id, team_id, latitude, longitude, |
|
| 413 | + public function getAllGyms() |
|
| 414 | + { |
|
| 415 | + $req = "SELECT gym_id, team_id, latitude, longitude, |
|
| 416 | 416 | CONVERT_TZ(last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned, |
| 417 | 417 | (6 - slots_available) AS level |
| 418 | 418 | FROM gym"; |
| 419 | - $result = $this->mysqli->query($req); |
|
| 420 | - $gyms = array(); |
|
| 421 | - while ($data = $result->fetch_object()) { |
|
| 422 | - $gyms[] = $data; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return $gyms; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - public function getGymData($gym_id) |
|
| 429 | - { |
|
| 430 | - $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team, |
|
| 419 | + $result = $this->mysqli->query($req); |
|
| 420 | + $gyms = array(); |
|
| 421 | + while ($data = $result->fetch_object()) { |
|
| 422 | + $gyms[] = $data; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return $gyms; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + public function getGymData($gym_id) |
|
| 429 | + { |
|
| 430 | + $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team, |
|
| 431 | 431 | CONVERT_TZ(gym.last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned, |
| 432 | 432 | gym.guard_pokemon_id AS guard_pokemon_id, |
| 433 | 433 | gym.total_cp AS total_cp, |
@@ -435,53 +435,53 @@ discard block |
||
| 435 | 435 | FROM gymdetails |
| 436 | 436 | LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id |
| 437 | 437 | WHERE gym.gym_id='".$gym_id."'"; |
| 438 | - $result = $this->mysqli->query($req); |
|
| 439 | - $data = $result->fetch_object(); |
|
| 438 | + $result = $this->mysqli->query($req); |
|
| 439 | + $data = $result->fetch_object(); |
|
| 440 | 440 | |
| 441 | - return $data; |
|
| 442 | - } |
|
| 441 | + return $data; |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | - public function getGymDefenders($gym_id) |
|
| 445 | - { |
|
| 446 | - $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id |
|
| 444 | + public function getGymDefenders($gym_id) |
|
| 445 | + { |
|
| 446 | + $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id |
|
| 447 | 447 | FROM gympokemon |
| 448 | 448 | INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid |
| 449 | 449 | GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id |
| 450 | 450 | HAVING gymmember.gym_id='".$gym_id."' |
| 451 | 451 | ORDER BY cp DESC"; |
| 452 | - $result = $this->mysqli->query($req); |
|
| 453 | - $defenders = array(); |
|
| 454 | - while ($data = $result->fetch_object()) { |
|
| 455 | - $defenders[] = $data; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - return $defenders; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - //////////////// |
|
| 462 | - // Gym History |
|
| 463 | - //////////////// |
|
| 464 | - |
|
| 465 | - public function getGymHistories($gym_name, $team, $page, $ranking) |
|
| 466 | - { |
|
| 467 | - $where = ''; |
|
| 468 | - if (isset($gym_name) && '' != $gym_name) { |
|
| 469 | - $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
| 470 | - } |
|
| 471 | - if (isset($team) && '' != $team) { |
|
| 472 | - $where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team; |
|
| 473 | - } |
|
| 474 | - switch ($ranking) { |
|
| 475 | - case 1: |
|
| 476 | - $order = ' ORDER BY name, last_modified DESC'; |
|
| 477 | - break; |
|
| 478 | - case 2: |
|
| 479 | - $order = ' ORDER BY total_cp DESC, last_modified DESC'; |
|
| 480 | - break; |
|
| 481 | - default: |
|
| 482 | - $order = ' ORDER BY last_modified DESC, name'; |
|
| 483 | - } |
|
| 484 | - $req = "SELECT gymdetails.gym_id, name, team_id, total_cp, |
|
| 452 | + $result = $this->mysqli->query($req); |
|
| 453 | + $defenders = array(); |
|
| 454 | + while ($data = $result->fetch_object()) { |
|
| 455 | + $defenders[] = $data; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return $defenders; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + //////////////// |
|
| 462 | + // Gym History |
|
| 463 | + //////////////// |
|
| 464 | + |
|
| 465 | + public function getGymHistories($gym_name, $team, $page, $ranking) |
|
| 466 | + { |
|
| 467 | + $where = ''; |
|
| 468 | + if (isset($gym_name) && '' != $gym_name) { |
|
| 469 | + $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
| 470 | + } |
|
| 471 | + if (isset($team) && '' != $team) { |
|
| 472 | + $where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team; |
|
| 473 | + } |
|
| 474 | + switch ($ranking) { |
|
| 475 | + case 1: |
|
| 476 | + $order = ' ORDER BY name, last_modified DESC'; |
|
| 477 | + break; |
|
| 478 | + case 2: |
|
| 479 | + $order = ' ORDER BY total_cp DESC, last_modified DESC'; |
|
| 480 | + break; |
|
| 481 | + default: |
|
| 482 | + $order = ' ORDER BY last_modified DESC, name'; |
|
| 483 | + } |
|
| 484 | + $req = "SELECT gymdetails.gym_id, name, team_id, total_cp, |
|
| 485 | 485 | (6 - slots_available) as pokemon_count, |
| 486 | 486 | CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified |
| 487 | 487 | FROM gymdetails |
@@ -489,93 +489,93 @@ discard block |
||
| 489 | 489 | ON gymdetails.gym_id = gym.gym_id |
| 490 | 490 | ".$where.$order." |
| 491 | 491 | LIMIT ".($page * 10).",10"; |
| 492 | - $result = $this->mysqli->query($req); |
|
| 493 | - $gym_history = array(); |
|
| 494 | - while ($data = $result->fetch_object()) { |
|
| 495 | - $gym_history[] = $data; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - return $gym_history; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - public function getGymHistoriesPokemon($gym_id) |
|
| 502 | - { |
|
| 503 | - $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name |
|
| 492 | + $result = $this->mysqli->query($req); |
|
| 493 | + $gym_history = array(); |
|
| 494 | + while ($data = $result->fetch_object()) { |
|
| 495 | + $gym_history[] = $data; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + return $gym_history; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + public function getGymHistoriesPokemon($gym_id) |
|
| 502 | + { |
|
| 503 | + $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name |
|
| 504 | 504 | FROM gymmember |
| 505 | 505 | LEFT JOIN gympokemon |
| 506 | 506 | ON gymmember.pokemon_uid = gympokemon.pokemon_uid |
| 507 | 507 | WHERE gymmember.gym_id = '".$gym_id."' |
| 508 | 508 | ORDER BY deployment_time"; |
| 509 | - $result = $this->mysqli->query($req); |
|
| 510 | - $pokemons = array(); |
|
| 511 | - while ($data = $result->fetch_object()) { |
|
| 512 | - $pokemons[] = $data; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return $pokemons; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - public function getHistoryForGym($page, $gym_id) |
|
| 519 | - { |
|
| 520 | - if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) { |
|
| 521 | - $pageSize = 25; |
|
| 522 | - } else { |
|
| 523 | - $pageSize = 10; |
|
| 524 | - } |
|
| 525 | - $req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count, |
|
| 509 | + $result = $this->mysqli->query($req); |
|
| 510 | + $pokemons = array(); |
|
| 511 | + while ($data = $result->fetch_object()) { |
|
| 512 | + $pokemons[] = $data; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return $pokemons; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + public function getHistoryForGym($page, $gym_id) |
|
| 519 | + { |
|
| 520 | + if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) { |
|
| 521 | + $pageSize = 25; |
|
| 522 | + } else { |
|
| 523 | + $pageSize = 10; |
|
| 524 | + } |
|
| 525 | + $req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count, |
|
| 526 | 526 | CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified |
| 527 | 527 | FROM gymhistory |
| 528 | 528 | WHERE gym_id='".$gym_id."' |
| 529 | 529 | ORDER BY last_modified DESC |
| 530 | 530 | LIMIT ".($page * $pageSize).','.($pageSize + 1); |
| 531 | - $result = $this->mysqli->query($req); |
|
| 532 | - $history = array(); |
|
| 533 | - $count = 0; |
|
| 534 | - while ($data = $result->fetch_object()) { |
|
| 535 | - ++$count; |
|
| 536 | - $pkm = array(); |
|
| 537 | - if (0 == $data->total_cp) { |
|
| 538 | - $data->pokemon_uids = ''; |
|
| 539 | - $data->pokemon_count = 0; |
|
| 540 | - } |
|
| 541 | - if ('' != $data->pokemon_uids) { |
|
| 542 | - $pkm_uids = explode(',', $data->pokemon_uids); |
|
| 543 | - $pkm = $this->getHistoryForGymPokemon($pkm_uids); |
|
| 544 | - } |
|
| 545 | - $data->pokemon = $pkm; |
|
| 546 | - $history[] = $data; |
|
| 547 | - } |
|
| 548 | - if ($count !== ($pageSize + 1)) { |
|
| 549 | - $last_page = true; |
|
| 550 | - } else { |
|
| 551 | - $last_page = false; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - return array('last_page' => $last_page, 'data' => $history); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - private function getHistoryForGymPokemon($pkm_uids) |
|
| 558 | - { |
|
| 559 | - $req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name |
|
| 531 | + $result = $this->mysqli->query($req); |
|
| 532 | + $history = array(); |
|
| 533 | + $count = 0; |
|
| 534 | + while ($data = $result->fetch_object()) { |
|
| 535 | + ++$count; |
|
| 536 | + $pkm = array(); |
|
| 537 | + if (0 == $data->total_cp) { |
|
| 538 | + $data->pokemon_uids = ''; |
|
| 539 | + $data->pokemon_count = 0; |
|
| 540 | + } |
|
| 541 | + if ('' != $data->pokemon_uids) { |
|
| 542 | + $pkm_uids = explode(',', $data->pokemon_uids); |
|
| 543 | + $pkm = $this->getHistoryForGymPokemon($pkm_uids); |
|
| 544 | + } |
|
| 545 | + $data->pokemon = $pkm; |
|
| 546 | + $history[] = $data; |
|
| 547 | + } |
|
| 548 | + if ($count !== ($pageSize + 1)) { |
|
| 549 | + $last_page = true; |
|
| 550 | + } else { |
|
| 551 | + $last_page = false; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + return array('last_page' => $last_page, 'data' => $history); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + private function getHistoryForGymPokemon($pkm_uids) |
|
| 558 | + { |
|
| 559 | + $req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name |
|
| 560 | 560 | FROM gympokemon |
| 561 | 561 | WHERE pokemon_uid IN ('".implode("','", $pkm_uids)."') |
| 562 | 562 | ORDER BY FIND_IN_SET(pokemon_uid, '".implode(',', $pkm_uids)."')"; |
| 563 | - $result = $this->mysqli->query($req); |
|
| 564 | - $pokemons = array(); |
|
| 565 | - while ($data = $result->fetch_object()) { |
|
| 566 | - $pokemons[$data->pokemon_uid] = $data; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - return $pokemons; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /////////// |
|
| 573 | - // Raids |
|
| 574 | - /////////// |
|
| 575 | - |
|
| 576 | - public function getAllRaids($page) |
|
| 577 | - { |
|
| 578 | - $req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2, |
|
| 563 | + $result = $this->mysqli->query($req); |
|
| 564 | + $pokemons = array(); |
|
| 565 | + while ($data = $result->fetch_object()) { |
|
| 566 | + $pokemons[$data->pokemon_uid] = $data; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + return $pokemons; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /////////// |
|
| 573 | + // Raids |
|
| 574 | + /////////// |
|
| 575 | + |
|
| 576 | + public function getAllRaids($page) |
|
| 577 | + { |
|
| 578 | + $req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2, |
|
| 579 | 579 | CONVERT_TZ(raid.spawn, '+00:00', '".self::$time_offset."') AS spawn, |
| 580 | 580 | CONVERT_TZ(raid.start, '+00:00', '".self::$time_offset."') AS start, |
| 581 | 581 | CONVERT_TZ(raid.end, '+00:00', '".self::$time_offset."') AS end, |
@@ -587,121 +587,121 @@ discard block |
||
| 587 | 587 | WHERE raid.end > UTC_TIMESTAMP() |
| 588 | 588 | ORDER BY raid.level DESC, raid.start |
| 589 | 589 | LIMIT ".($page * 10).",10"; |
| 590 | - $result = $this->mysqli->query($req); |
|
| 591 | - $raids = array(); |
|
| 592 | - while ($data = $result->fetch_object()) { |
|
| 593 | - $raids[] = $data; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $raids; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - ////////////// |
|
| 600 | - // Trainers |
|
| 601 | - ////////////// |
|
| 602 | - |
|
| 603 | - public function getTrainers($trainer_name, $team, $page, $ranking) |
|
| 604 | - { |
|
| 605 | - $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking); |
|
| 606 | - foreach ($trainers as $trainer) { |
|
| 607 | - $trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank; |
|
| 608 | - $active_gyms = 0; |
|
| 609 | - $pkmCount = 0; |
|
| 610 | - $trainer->pokemons = array(); |
|
| 611 | - $active_pokemon = $this->getTrainerActivePokemon($trainer->name); |
|
| 612 | - foreach ($active_pokemon as $pokemon) { |
|
| 613 | - ++$active_gyms; |
|
| 614 | - $trainer->pokemons[$pkmCount++] = $pokemon; |
|
| 615 | - } |
|
| 616 | - $inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name); |
|
| 617 | - foreach ($inactive_pokemon as $pokemon) { |
|
| 618 | - $trainer->pokemons[$pkmCount++] = $pokemon; |
|
| 619 | - } |
|
| 620 | - $trainer->gyms = ''.$active_gyms; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - return $trainers; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - public function getTrainerLevelCount($team_id) |
|
| 627 | - { |
|
| 628 | - $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'"; |
|
| 629 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
| 630 | - $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 631 | - } |
|
| 632 | - $req .= ' GROUP BY level'; |
|
| 633 | - $result = $this->mysqli->query($req); |
|
| 634 | - $levelData = array(); |
|
| 635 | - while ($data = $result->fetch_object()) { |
|
| 636 | - $levelData[$data->level] = $data->count; |
|
| 637 | - } |
|
| 638 | - for ($i = 5; $i <= 40; ++$i) { |
|
| 639 | - if (!isset($levelData[$i])) { |
|
| 640 | - $levelData[$i] = 0; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - // sort array again |
|
| 644 | - ksort($levelData); |
|
| 645 | - |
|
| 646 | - return $levelData; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - private function getTrainerData($trainer_name, $team, $page, $ranking) |
|
| 650 | - { |
|
| 651 | - $where = ''; |
|
| 652 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
| 653 | - $where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 654 | - } |
|
| 655 | - if ('' != $trainer_name) { |
|
| 656 | - $where = " HAVING name LIKE '%".$trainer_name."%'"; |
|
| 657 | - } |
|
| 658 | - if (0 != $team) { |
|
| 659 | - $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team; |
|
| 660 | - } |
|
| 661 | - switch ($ranking) { |
|
| 662 | - case 1: |
|
| 663 | - $order = ' ORDER BY active DESC, level DESC'; |
|
| 664 | - break; |
|
| 665 | - case 2: |
|
| 666 | - $order = ' ORDER BY maxCp DESC, level DESC'; |
|
| 667 | - break; |
|
| 668 | - default: |
|
| 669 | - $order = ' ORDER BY level DESC, active DESC'; |
|
| 670 | - } |
|
| 671 | - $order .= ', last_seen DESC, name '; |
|
| 672 | - $limit = ' LIMIT '.($page * 10).',10 '; |
|
| 673 | - $req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp |
|
| 590 | + $result = $this->mysqli->query($req); |
|
| 591 | + $raids = array(); |
|
| 592 | + while ($data = $result->fetch_object()) { |
|
| 593 | + $raids[] = $data; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $raids; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + ////////////// |
|
| 600 | + // Trainers |
|
| 601 | + ////////////// |
|
| 602 | + |
|
| 603 | + public function getTrainers($trainer_name, $team, $page, $ranking) |
|
| 604 | + { |
|
| 605 | + $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking); |
|
| 606 | + foreach ($trainers as $trainer) { |
|
| 607 | + $trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank; |
|
| 608 | + $active_gyms = 0; |
|
| 609 | + $pkmCount = 0; |
|
| 610 | + $trainer->pokemons = array(); |
|
| 611 | + $active_pokemon = $this->getTrainerActivePokemon($trainer->name); |
|
| 612 | + foreach ($active_pokemon as $pokemon) { |
|
| 613 | + ++$active_gyms; |
|
| 614 | + $trainer->pokemons[$pkmCount++] = $pokemon; |
|
| 615 | + } |
|
| 616 | + $inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name); |
|
| 617 | + foreach ($inactive_pokemon as $pokemon) { |
|
| 618 | + $trainer->pokemons[$pkmCount++] = $pokemon; |
|
| 619 | + } |
|
| 620 | + $trainer->gyms = ''.$active_gyms; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + return $trainers; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + public function getTrainerLevelCount($team_id) |
|
| 627 | + { |
|
| 628 | + $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'"; |
|
| 629 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
| 630 | + $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 631 | + } |
|
| 632 | + $req .= ' GROUP BY level'; |
|
| 633 | + $result = $this->mysqli->query($req); |
|
| 634 | + $levelData = array(); |
|
| 635 | + while ($data = $result->fetch_object()) { |
|
| 636 | + $levelData[$data->level] = $data->count; |
|
| 637 | + } |
|
| 638 | + for ($i = 5; $i <= 40; ++$i) { |
|
| 639 | + if (!isset($levelData[$i])) { |
|
| 640 | + $levelData[$i] = 0; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + // sort array again |
|
| 644 | + ksort($levelData); |
|
| 645 | + |
|
| 646 | + return $levelData; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + private function getTrainerData($trainer_name, $team, $page, $ranking) |
|
| 650 | + { |
|
| 651 | + $where = ''; |
|
| 652 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
| 653 | + $where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 654 | + } |
|
| 655 | + if ('' != $trainer_name) { |
|
| 656 | + $where = " HAVING name LIKE '%".$trainer_name."%'"; |
|
| 657 | + } |
|
| 658 | + if (0 != $team) { |
|
| 659 | + $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team; |
|
| 660 | + } |
|
| 661 | + switch ($ranking) { |
|
| 662 | + case 1: |
|
| 663 | + $order = ' ORDER BY active DESC, level DESC'; |
|
| 664 | + break; |
|
| 665 | + case 2: |
|
| 666 | + $order = ' ORDER BY maxCp DESC, level DESC'; |
|
| 667 | + break; |
|
| 668 | + default: |
|
| 669 | + $order = ' ORDER BY level DESC, active DESC'; |
|
| 670 | + } |
|
| 671 | + $order .= ', last_seen DESC, name '; |
|
| 672 | + $limit = ' LIMIT '.($page * 10).',10 '; |
|
| 673 | + $req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp |
|
| 674 | 674 | FROM trainer |
| 675 | 675 | LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned |
| 676 | 676 | FROM gympokemon |
| 677 | 677 | 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 |
| 678 | 678 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name |
| 679 | 679 | GROUP BY trainer.name ".$where.$order.$limit; |
| 680 | - $result = $this->mysqli->query($req); |
|
| 681 | - $trainers = array(); |
|
| 682 | - while ($data = $result->fetch_object()) { |
|
| 683 | - $data->last_seen = date('Y-m-d', strtotime($data->last_seen)); |
|
| 684 | - $trainers[$data->name] = $data; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - return $trainers; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - private function getTrainerLevelRating($level) |
|
| 691 | - { |
|
| 692 | - $req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level; |
|
| 693 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
| 694 | - $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 695 | - } |
|
| 696 | - $result = $this->mysqli->query($req); |
|
| 697 | - $data = $result->fetch_object(); |
|
| 698 | - |
|
| 699 | - return $data; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - private function getTrainerActivePokemon($trainer_name) |
|
| 703 | - { |
|
| 704 | - $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 680 | + $result = $this->mysqli->query($req); |
|
| 681 | + $trainers = array(); |
|
| 682 | + while ($data = $result->fetch_object()) { |
|
| 683 | + $data->last_seen = date('Y-m-d', strtotime($data->last_seen)); |
|
| 684 | + $trainers[$data->name] = $data; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + return $trainers; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + private function getTrainerLevelRating($level) |
|
| 691 | + { |
|
| 692 | + $req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level; |
|
| 693 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
| 694 | + $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 695 | + } |
|
| 696 | + $result = $this->mysqli->query($req); |
|
| 697 | + $data = $result->fetch_object(); |
|
| 698 | + |
|
| 699 | + return $data; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + private function getTrainerActivePokemon($trainer_name) |
|
| 703 | + { |
|
| 704 | + $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 705 | 705 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
| 706 | 706 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
| 707 | 707 | filtered_gymmember.gym_id, |
@@ -712,18 +712,18 @@ discard block |
||
| 712 | 712 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
| 713 | 713 | WHERE gympokemon.trainer_name='".$trainer_name."' |
| 714 | 714 | ORDER BY gympokemon.cp DESC"; |
| 715 | - $result = $this->mysqli->query($req); |
|
| 716 | - $pokemons = array(); |
|
| 717 | - while ($data = $result->fetch_object()) { |
|
| 718 | - $pokemons[] = $data; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - return $pokemons; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - private function getTrainerInactivePokemon($trainer_name) |
|
| 725 | - { |
|
| 726 | - $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 715 | + $result = $this->mysqli->query($req); |
|
| 716 | + $pokemons = array(); |
|
| 717 | + while ($data = $result->fetch_object()) { |
|
| 718 | + $pokemons[] = $data; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + return $pokemons; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + private function getTrainerInactivePokemon($trainer_name) |
|
| 725 | + { |
|
| 726 | + $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 727 | 727 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
| 728 | 728 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
| 729 | 729 | null AS gym_id, |
@@ -734,78 +734,78 @@ discard block |
||
| 734 | 734 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
| 735 | 735 | WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."' |
| 736 | 736 | ORDER BY gympokemon.cp DESC"; |
| 737 | - $result = $this->mysqli->query($req); |
|
| 738 | - $pokemons = array(); |
|
| 739 | - while ($data = $result->fetch_object()) { |
|
| 740 | - $pokemons[] = $data; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - return $pokemons; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - ///////// |
|
| 747 | - // Cron |
|
| 748 | - ///////// |
|
| 749 | - |
|
| 750 | - public function getPokemonCountsActive() |
|
| 751 | - { |
|
| 752 | - $req = 'SELECT pokemon_id, COUNT(*) as total |
|
| 737 | + $result = $this->mysqli->query($req); |
|
| 738 | + $pokemons = array(); |
|
| 739 | + while ($data = $result->fetch_object()) { |
|
| 740 | + $pokemons[] = $data; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + return $pokemons; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + ///////// |
|
| 747 | + // Cron |
|
| 748 | + ///////// |
|
| 749 | + |
|
| 750 | + public function getPokemonCountsActive() |
|
| 751 | + { |
|
| 752 | + $req = 'SELECT pokemon_id, COUNT(*) as total |
|
| 753 | 753 | FROM pokemon |
| 754 | 754 | WHERE disappear_time >= UTC_TIMESTAMP() |
| 755 | 755 | GROUP BY pokemon_id'; |
| 756 | - $result = $this->mysqli->query($req); |
|
| 757 | - $counts = array(); |
|
| 758 | - while ($data = $result->fetch_object()) { |
|
| 759 | - $counts[$data->pokemon_id] = $data->total; |
|
| 760 | - } |
|
| 756 | + $result = $this->mysqli->query($req); |
|
| 757 | + $counts = array(); |
|
| 758 | + while ($data = $result->fetch_object()) { |
|
| 759 | + $counts[$data->pokemon_id] = $data->total; |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - return $counts; |
|
| 763 | - } |
|
| 762 | + return $counts; |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | 765 | |
| 766 | - public function getTotalPokemonIV() |
|
| 767 | - { |
|
| 768 | - $req = 'SELECT COUNT(*) as total |
|
| 766 | + public function getTotalPokemonIV() |
|
| 767 | + { |
|
| 768 | + $req = 'SELECT COUNT(*) as total |
|
| 769 | 769 | FROM pokemon |
| 770 | 770 | WHERE disappear_time >= UTC_TIMESTAMP() AND cp IS NOT NULL'; |
| 771 | - $result = $this->mysqli->query($req); |
|
| 772 | - $data = $result->fetch_object(); |
|
| 771 | + $result = $this->mysqli->query($req); |
|
| 772 | + $data = $result->fetch_object(); |
|
| 773 | 773 | |
| 774 | - return $data; |
|
| 775 | - } |
|
| 774 | + return $data; |
|
| 775 | + } |
|
| 776 | 776 | |
| 777 | - public function getPokemonCountsLastDay() |
|
| 778 | - { |
|
| 779 | - $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
| 777 | + public function getPokemonCountsLastDay() |
|
| 778 | + { |
|
| 779 | + $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
| 780 | 780 | FROM pokemon |
| 781 | 781 | WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY |
| 782 | 782 | GROUP BY pokemon_id |
| 783 | 783 | ORDER BY pokemon_id ASC'; |
| 784 | - $result = $this->mysqli->query($req); |
|
| 785 | - $counts = array(); |
|
| 786 | - while ($data = $result->fetch_object()) { |
|
| 787 | - $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - return $counts; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - public function getCaptchaCount() |
|
| 794 | - { |
|
| 795 | - $req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker'; |
|
| 796 | - $result = $this->mysqli->query($req); |
|
| 797 | - $data = $result->fetch_object(); |
|
| 798 | - |
|
| 799 | - return $data; |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 803 | - { |
|
| 804 | - $pokemon_exclude_sql = ''; |
|
| 805 | - if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
| 806 | - $pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
| 807 | - } |
|
| 808 | - $req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon, |
|
| 784 | + $result = $this->mysqli->query($req); |
|
| 785 | + $counts = array(); |
|
| 786 | + while ($data = $result->fetch_object()) { |
|
| 787 | + $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + return $counts; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + public function getCaptchaCount() |
|
| 794 | + { |
|
| 795 | + $req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker'; |
|
| 796 | + $result = $this->mysqli->query($req); |
|
| 797 | + $data = $result->fetch_object(); |
|
| 798 | + |
|
| 799 | + return $data; |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 803 | + { |
|
| 804 | + $pokemon_exclude_sql = ''; |
|
| 805 | + if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
| 806 | + $pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
| 807 | + } |
|
| 808 | + $req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon, |
|
| 809 | 809 | MAX(UNIX_TIMESTAMP(disappear_time)) as latest_seen |
| 810 | 810 | FROM pokemon |
| 811 | 811 | WHERE disappear_time > (UTC_TIMESTAMP() - INTERVAL '.$time.' HOUR) |
@@ -814,23 +814,23 @@ discard block |
||
| 814 | 814 | GROUP BY spawnpoint_id, pokemon_id |
| 815 | 815 | HAVING COUNT(pokemon_id) >= '.($time / 4).' |
| 816 | 816 | ORDER BY pokemon_id'; |
| 817 | - $result = $this->mysqli->query($req); |
|
| 818 | - $nests = array(); |
|
| 819 | - while ($data = $result->fetch_object()) { |
|
| 820 | - $nests[] = $data; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - return $nests; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 827 | - { |
|
| 828 | - $req = 'SELECT COUNT(*) as total |
|
| 817 | + $result = $this->mysqli->query($req); |
|
| 818 | + $nests = array(); |
|
| 819 | + while ($data = $result->fetch_object()) { |
|
| 820 | + $nests[] = $data; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + return $nests; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 827 | + { |
|
| 828 | + $req = 'SELECT COUNT(*) as total |
|
| 829 | 829 | FROM trs_spawn |
| 830 | 830 | WHERE latitude >= '.$minLatitude.' AND latitude < '.$maxLatitude.' AND longitude >= '.$minLongitude.' AND longitude < '.$maxLongitude; |
| 831 | - $result = $this->mysqli->query($req); |
|
| 832 | - $data = $result->fetch_object(); |
|
| 831 | + $result = $this->mysqli->query($req); |
|
| 832 | + $data = $result->fetch_object(); |
|
| 833 | 833 | |
| 834 | - return $data; |
|
| 835 | - } |
|
| 834 | + return $data; |
|
| 835 | + } |
|
| 836 | 836 | } |