@@ -22,7 +22,7 @@ |
||
| 22 | 22 | $rarityarray = array(); |
| 23 | 23 | foreach ($counts as $poke_id => $total) { |
| 24 | 24 | $rarity = $pokemons->pokemon->$poke_id->rarity; |
| 25 | - isset($rarityarray[$rarity]) ? $rarityarray[$rarity]+=$total : $rarityarray[$rarity]=$total; |
|
| 25 | + isset($rarityarray[$rarity]) ? $rarityarray[$rarity] += $total : $rarityarray[$rarity] = $total; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // Set amount of Pokemon for each rarity to 0 if there weren't any at that time |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | // Load Query Manager |
| 30 | 30 | // ################### |
| 31 | 31 | |
| 32 | -include_once __DIR__ . '/../process/queries/QueryManager.php'; |
|
| 32 | +include_once __DIR__.'/../process/queries/QueryManager.php'; |
|
| 33 | 33 | $manager = QueryManager::current(); |
| 34 | 34 | |
| 35 | 35 | |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | $pokedatas = json_decode(file_get_contents($pokemonstats_file), true); |
| 52 | 52 | } |
| 53 | 53 | if (is_file($pokedex_counts_file)) { |
| 54 | - $pokecountdatas = json_decode(file_get_contents($pokedex_counts_file), true); |
|
| 54 | + $pokecountdatas = json_decode(file_get_contents($pokedex_counts_file), true); |
|
| 55 | 55 | } |
| 56 | 56 | if (is_file($pokedex_raids_file)) { |
| 57 | - $raiddatas = json_decode(file_get_contents($pokedex_raids_file), true); |
|
| 57 | + $raiddatas = json_decode(file_get_contents($pokedex_raids_file), true); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | $trainer_lvl = []; |
| 29 | 29 | # For all 3 teams |
| 30 | 30 | for ($teamid = 1; $teamid <= 3; $teamid++) { |
| 31 | - $data = $manager->getTrainerLevelCount($teamid); |
|
| 31 | + $data = $manager->getTrainerLevelCount($teamid); |
|
| 32 | 32 | $trainer_lvl[$teamid] = $data; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | // Load Query Manager |
| 21 | 21 | // ################### |
| 22 | 22 | |
| 23 | -include_once __DIR__ . '/../process/queries/QueryManager.php'; |
|
| 23 | +include_once __DIR__.'/../process/queries/QueryManager.php'; |
|
| 24 | 24 | $manager = QueryManager::current(); |
| 25 | 25 | |
| 26 | 26 | # Chart Graph datas |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | // Load Query Manager |
| 70 | 70 | // ################### |
| 71 | 71 | |
| 72 | -include_once __DIR__ . '/queries/QueryManager.php'; |
|
| 72 | +include_once __DIR__.'/queries/QueryManager.php'; |
|
| 73 | 73 | $manager = QueryManager::current(); |
| 74 | 74 | |
| 75 | 75 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | |
| 270 | 270 | // Gym owned and average points |
| 271 | - $data = $manager->getOwnedAndPoints($team_values->id); |
|
| 271 | + $data = $manager->getOwnedAndPoints($team_values->id); |
|
| 272 | 272 | |
| 273 | 273 | $teams->$team_key->gym_owned = $data->total; |
| 274 | 274 | $teams->$team_key->average = $data->average_points; |
@@ -3,7 +3,7 @@ |
||
| 3 | 3 | // Load Query Manager |
| 4 | 4 | // ################### |
| 5 | 5 | |
| 6 | -include_once __DIR__ . '/../core/process/queries/QueryManager.php'; |
|
| 6 | +include_once __DIR__.'/../core/process/queries/QueryManager.php'; |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | ######################################################################## |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -include_once __DIR__ . '/QueryManagerPostgresqlMonocleAlternate.php'; |
|
| 3 | +include_once __DIR__.'/QueryManagerPostgresqlMonocleAlternate.php'; |
|
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | abstract class QueryManagerPostgresql extends QueryManager { |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | $this->db = pg_connect("host=".SYS_DB_HOST." port=".SYS_DB_PORT." dbname=".SYS_DB_NAME." user=".SYS_DB_USER." password=".SYS_DB_PSWD); |
| 13 | 13 | |
| 14 | 14 | if ($this->db === false) { |
| 15 | - header('Location:' . HOST_URL . 'offline.html'); |
|
| 15 | + header('Location:'.HOST_URL.'offline.html'); |
|
| 16 | 16 | exit(); |
| 17 | 17 | } |
| 18 | 18 | } |
@@ -3,11 +3,13 @@ discard block |
||
| 3 | 3 | include_once __DIR__ . '/QueryManagerPostgresqlMonocleAlternate.php'; |
| 4 | 4 | |
| 5 | 5 | |
| 6 | -abstract class QueryManagerPostgresql extends QueryManager { |
|
| 6 | +abstract class QueryManagerPostgresql extends QueryManager |
|
| 7 | +{ |
|
| 7 | 8 | |
| 8 | 9 | protected $db; |
| 9 | 10 | |
| 10 | - protected function __construct() { |
|
| 11 | + protected function __construct() |
|
| 12 | + { |
|
| 11 | 13 | |
| 12 | 14 | $this->db = pg_connect("host=".SYS_DB_HOST." port=".SYS_DB_PORT." dbname=".SYS_DB_NAME." user=".SYS_DB_USER." password=".SYS_DB_PSWD); |
| 13 | 15 | |
@@ -17,7 +19,8 @@ discard block |
||
| 17 | 19 | } |
| 18 | 20 | } |
| 19 | 21 | |
| 20 | - public function __destruct() { |
|
| 22 | + public function __destruct() |
|
| 23 | + { |
|
| 21 | 24 | pg_close($this->db); |
| 22 | 25 | } |
| 23 | 26 | |
@@ -25,7 +28,8 @@ discard block |
||
| 25 | 28 | // Misc |
| 26 | 29 | ///////// |
| 27 | 30 | |
| 28 | - public function getEcapedString($string) { |
|
| 31 | + public function getEcapedString($string) |
|
| 32 | + { |
|
| 29 | 33 | return pg_escape_string($this->db, $string); |
| 30 | 34 | } |
| 31 | 35 | |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -include_once __DIR__ . '/QueryManagerMysqlRocketmap.php'; |
|
| 4 | -include_once __DIR__ . '/QueryManagerMysqlMonocleAlternate.php'; |
|
| 3 | +include_once __DIR__.'/QueryManagerMysqlRocketmap.php'; |
|
| 4 | +include_once __DIR__.'/QueryManagerMysqlMonocleAlternate.php'; |
|
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | abstract class QueryManagerMysql extends QueryManager { |
@@ -4,11 +4,13 @@ discard block |
||
| 4 | 4 | include_once __DIR__ . '/QueryManagerMysqlMonocleAlternate.php'; |
| 5 | 5 | |
| 6 | 6 | |
| 7 | -abstract class QueryManagerMysql extends QueryManager { |
|
| 7 | +abstract class QueryManagerMysql extends QueryManager |
|
| 8 | +{ |
|
| 8 | 9 | |
| 9 | 10 | protected $mysqli; |
| 10 | 11 | |
| 11 | - protected function __construct() { |
|
| 12 | + protected function __construct() |
|
| 13 | + { |
|
| 12 | 14 | $this->mysqli = new mysqli(SYS_DB_HOST, SYS_DB_USER, SYS_DB_PSWD, SYS_DB_NAME, SYS_DB_PORT); |
| 13 | 15 | if ($this->mysqli->connect_error != '') { |
| 14 | 16 | header('Location:'.HOST_URL.'offline.html'); |
@@ -22,7 +24,8 @@ discard block |
||
| 22 | 24 | } |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | - public function __destruct() { |
|
| 27 | + public function __destruct() |
|
| 28 | + { |
|
| 26 | 29 | $this->mysqli->close(); |
| 27 | 30 | } |
| 28 | 31 | |
@@ -30,7 +33,8 @@ discard block |
||
| 30 | 33 | // Misc |
| 31 | 34 | ///////// |
| 32 | 35 | |
| 33 | - public function getEcapedString($string) { |
|
| 36 | + public function getEcapedString($string) |
|
| 37 | + { |
|
| 34 | 38 | return mysqli_real_escape_string($this->mysqli, $string); |
| 35 | 39 | } |
| 36 | 40 | |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -include_once __DIR__ . '/../../../config.php'; |
|
| 4 | -include_once __DIR__ . '/QueryManagerMysql.php'; |
|
| 5 | -include_once __DIR__ . '/QueryManagerPostgresql.php'; |
|
| 3 | +include_once __DIR__.'/../../../config.php'; |
|
| 4 | +include_once __DIR__.'/QueryManagerMysql.php'; |
|
| 5 | +include_once __DIR__.'/QueryManagerPostgresql.php'; |
|
| 6 | 6 | |
| 7 | 7 | abstract class QueryManager { |
| 8 | 8 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | if (self::$current == null) { |
| 17 | 17 | |
| 18 | - $variables = realpath(dirname(__FILE__)) . '/../../json/variables.json'; |
|
| 18 | + $variables = realpath(dirname(__FILE__)).'/../../json/variables.json'; |
|
| 19 | 19 | self::$config = json_decode(file_get_contents($variables)); |
| 20 | 20 | |
| 21 | 21 | include_once(SYS_PATH.'/core/process/timezone.loader.php'); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | return self::$current; |
| 39 | 39 | } |
| 40 | - private function __construct(){} |
|
| 40 | + private function __construct() {} |
|
| 41 | 41 | |
| 42 | 42 | // Misc |
| 43 | 43 | abstract public function getEcapedString($string); |
@@ -4,13 +4,15 @@ discard block |
||
| 4 | 4 | include_once __DIR__ . '/QueryManagerMysql.php'; |
| 5 | 5 | include_once __DIR__ . '/QueryManagerPostgresql.php'; |
| 6 | 6 | |
| 7 | -abstract class QueryManager { |
|
| 7 | +abstract class QueryManager |
|
| 8 | +{ |
|
| 8 | 9 | |
| 9 | 10 | protected static $time_offset; |
| 10 | 11 | protected static $config; |
| 11 | 12 | |
| 12 | 13 | private static $current; |
| 13 | - public static function current() { |
|
| 14 | + public static function current() |
|
| 15 | + { |
|
| 14 | 16 | global $time_offset; |
| 15 | 17 | |
| 16 | 18 | if (self::$current == null) { |
@@ -37,7 +39,9 @@ discard block |
||
| 37 | 39 | } |
| 38 | 40 | return self::$current; |
| 39 | 41 | } |
| 40 | - private function __construct(){} |
|
| 42 | + private function __construct() |
|
| 43 | + { |
|
| 44 | +} |
|
| 41 | 45 | |
| 42 | 46 | // Misc |
| 43 | 47 | abstract public function getEcapedString($string); |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | ///////// |
| 303 | 303 | |
| 304 | 304 | function getTeamGuardians($team_id) { |
| 305 | - $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"; |
|
| 305 | + $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"; |
|
| 306 | 306 | $result = $this->mysqli->query($req); |
| 307 | 307 | $datas = array(); |
| 308 | 308 | while ($data = $result->fetch_object()) { |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | FROM gympokemon |
| 455 | 455 | 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 |
| 456 | 456 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name |
| 457 | - GROUP BY trainer.name " . $where . $order . $limit; |
|
| 457 | + GROUP BY trainer.name " . $where.$order.$limit; |
|
| 458 | 458 | |
| 459 | 459 | $result = $this->mysqli->query($req); |
| 460 | 460 | $trainers = array(); |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | return $data; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - private function getTrainerActivePokemon($trainer_name){ |
|
| 478 | + private function getTrainerActivePokemon($trainer_name) { |
|
| 479 | 479 | $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 |
| 480 | 480 | FROM gympokemon INNER JOIN |
| 481 | 481 | (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 |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | return $pokemons; |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - private function getTrainerInactivePokemon($trainer_name){ |
|
| 493 | + private function getTrainerInactivePokemon($trainer_name) { |
|
| 494 | 494 | $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 |
| 495 | 495 | FROM gympokemon LEFT JOIN |
| 496 | 496 | (SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | JOIN spawnpoint s ON p.spawnpoint_id = s.id |
| 545 | 545 | " . $where." |
| 546 | 546 | ) x |
| 547 | - " . $where . " |
|
| 547 | + " . $where." |
|
| 548 | 548 | ORDER BY last_timestamp DESC |
| 549 | 549 | LIMIT 0,1"; |
| 550 | 550 | $result = $this->mysqli->query($req); |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | FROM pokemon p |
| 587 | 587 | INNER JOIN spawnpoint s ON (p.spawnpoint_id = s.id) |
| 588 | 588 | WHERE p.disappear_time > UTC_TIMESTAMP() - INTERVAL 24 HOUR |
| 589 | - " . $pokemon_exclude_sql . " |
|
| 589 | + " . $pokemon_exclude_sql." |
|
| 590 | 590 | GROUP BY p.spawnpoint_id, p.pokemon_id |
| 591 | 591 | HAVING COUNT(p.pokemon_id) >= 6 |
| 592 | 592 | 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." ORDER BY disappear_time DESC 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."' ORDER BY disappear_time 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 | |
@@ -258,14 +278,16 @@ discard block |
||
| 258 | 278 | return $spawns; |
| 259 | 279 | } |
| 260 | 280 | |
| 261 | - public function getPokemonSliderMinMax() { |
|
| 281 | + public function getPokemonSliderMinMax() |
|
| 282 | + { |
|
| 262 | 283 | $req = "SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon"; |
| 263 | 284 | $result = $this->mysqli->query($req); |
| 264 | 285 | $data = $result->fetch_object(); |
| 265 | 286 | return $data; |
| 266 | 287 | } |
| 267 | 288 | |
| 268 | - public function getMapsCoords() { |
|
| 289 | + public function getMapsCoords() |
|
| 290 | + { |
|
| 269 | 291 | $req = "SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude FROM spawnpoint"; |
| 270 | 292 | $result = $this->mysqli->query($req); |
| 271 | 293 | $data = $result->fetch_object(); |
@@ -277,14 +299,16 @@ discard block |
||
| 277 | 299 | // Pokestops |
| 278 | 300 | ////////////// |
| 279 | 301 | |
| 280 | - function getTotalPokestops() { |
|
| 302 | + function getTotalPokestops() |
|
| 303 | + { |
|
| 281 | 304 | $req = "SELECT COUNT(*) as total FROM pokestop"; |
| 282 | 305 | $result = $this->mysqli->query($req); |
| 283 | 306 | $data = $result->fetch_object(); |
| 284 | 307 | return $data; |
| 285 | 308 | } |
| 286 | 309 | |
| 287 | - public function getAllPokestops() { |
|
| 310 | + public function getAllPokestops() |
|
| 311 | + { |
|
| 288 | 312 | $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"; |
| 289 | 313 | $result = $this->mysqli->query($req); |
| 290 | 314 | $pokestops = array(); |
@@ -299,7 +323,8 @@ discard block |
||
| 299 | 323 | // Gyms |
| 300 | 324 | ///////// |
| 301 | 325 | |
| 302 | - function getTeamGuardians($team_id) { |
|
| 326 | + function getTeamGuardians($team_id) |
|
| 327 | + { |
|
| 303 | 328 | $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"; |
| 304 | 329 | $result = $this->mysqli->query($req); |
| 305 | 330 | $datas = array(); |
@@ -309,14 +334,16 @@ discard block |
||
| 309 | 334 | return $datas; |
| 310 | 335 | } |
| 311 | 336 | |
| 312 | - function getOwnedAndPoints($team_id) { |
|
| 337 | + function getOwnedAndPoints($team_id) |
|
| 338 | + { |
|
| 313 | 339 | $req = "SELECT COUNT(DISTINCT(gym_id)) AS total, ROUND(AVG(total_cp),0) AS average_points FROM gym WHERE team_id = '".$team_id."'"; |
| 314 | 340 | $result = $this->mysqli->query($req); |
| 315 | 341 | $data = $result->fetch_object(); |
| 316 | 342 | return $data; |
| 317 | 343 | } |
| 318 | 344 | |
| 319 | - function getAllGyms() { |
|
| 345 | + function getAllGyms() |
|
| 346 | + { |
|
| 320 | 347 | $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"; |
| 321 | 348 | $result = $this->mysqli->query($req); |
| 322 | 349 | $gyms = array(); |
@@ -326,7 +353,8 @@ discard block |
||
| 326 | 353 | return $gyms; |
| 327 | 354 | } |
| 328 | 355 | |
| 329 | - public function getGymData($gym_id) { |
|
| 356 | + public function getGymData($gym_id) |
|
| 357 | + { |
|
| 330 | 358 | $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team, |
| 331 | 359 | (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 |
| 332 | 360 | FROM gymdetails |
@@ -337,7 +365,8 @@ discard block |
||
| 337 | 365 | return $data; |
| 338 | 366 | } |
| 339 | 367 | |
| 340 | - public function getGymDefenders($gym_id) { |
|
| 368 | + public function getGymDefenders($gym_id) |
|
| 369 | + { |
|
| 341 | 370 | $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id |
| 342 | 371 | FROM gympokemon INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid |
| 343 | 372 | GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id |
@@ -356,7 +385,8 @@ discard block |
||
| 356 | 385 | // Raids |
| 357 | 386 | /////////// |
| 358 | 387 | |
| 359 | - public function getAllRaids($page) { |
|
| 388 | + public function getAllRaids($page) |
|
| 389 | + { |
|
| 360 | 390 | $limit = " LIMIT ".($page * 10).",10"; |
| 361 | 391 | $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 |
| 362 | 392 | JOIN gymdetails ON gymdetails.gym_id = raid.gym_id |
@@ -376,7 +406,8 @@ discard block |
||
| 376 | 406 | // Trainers |
| 377 | 407 | ////////////// |
| 378 | 408 | |
| 379 | - public function getTrainers($trainer_name, $team, $page, $ranking) { |
|
| 409 | + public function getTrainers($trainer_name, $team, $page, $ranking) |
|
| 410 | + { |
|
| 380 | 411 | $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking); |
| 381 | 412 | foreach ($trainers as $trainer) { |
| 382 | 413 | |
@@ -401,7 +432,8 @@ discard block |
||
| 401 | 432 | return $trainers; |
| 402 | 433 | } |
| 403 | 434 | |
| 404 | - public function getTrainerLevelCount($team_id) { |
|
| 435 | + public function getTrainerLevelCount($team_id) |
|
| 436 | + { |
|
| 405 | 437 | $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'"; |
| 406 | 438 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 407 | 439 | $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -422,7 +454,8 @@ discard block |
||
| 422 | 454 | return $levelData; |
| 423 | 455 | } |
| 424 | 456 | |
| 425 | - private function getTrainerData($trainer_name, $team, $page, $ranking) { |
|
| 457 | + private function getTrainerData($trainer_name, $team, $page, $ranking) |
|
| 458 | + { |
|
| 426 | 459 | $where = ""; |
| 427 | 460 | |
| 428 | 461 | if (!empty(self::$config->system->trainer_blacklist)) { |
@@ -463,7 +496,8 @@ discard block |
||
| 463 | 496 | return $trainers; |
| 464 | 497 | } |
| 465 | 498 | |
| 466 | - private function getTrainerLevelRating($level) { |
|
| 499 | + private function getTrainerLevelRating($level) |
|
| 500 | + { |
|
| 467 | 501 | $req = "SELECT COUNT(1) AS rank FROM trainer WHERE level = ".$level; |
| 468 | 502 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 469 | 503 | $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -473,7 +507,8 @@ discard block |
||
| 473 | 507 | return $data; |
| 474 | 508 | } |
| 475 | 509 | |
| 476 | - private function getTrainerActivePokemon($trainer_name){ |
|
| 510 | + private function getTrainerActivePokemon($trainer_name) |
|
| 511 | + { |
|
| 477 | 512 | $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 |
| 478 | 513 | FROM gympokemon INNER JOIN |
| 479 | 514 | (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 |
@@ -488,7 +523,8 @@ discard block |
||
| 488 | 523 | return $pokemons; |
| 489 | 524 | } |
| 490 | 525 | |
| 491 | - private function getTrainerInactivePokemon($trainer_name){ |
|
| 526 | + private function getTrainerInactivePokemon($trainer_name) |
|
| 527 | + { |
|
| 492 | 528 | $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 |
| 493 | 529 | FROM gympokemon LEFT JOIN |
| 494 | 530 | (SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember |
@@ -508,7 +544,8 @@ discard block |
||
| 508 | 544 | // Cron |
| 509 | 545 | ///////// |
| 510 | 546 | |
| 511 | - public function getPokemonCountsActive() { |
|
| 547 | + public function getPokemonCountsActive() |
|
| 548 | + { |
|
| 512 | 549 | $req = "SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP() GROUP BY pokemon_id"; |
| 513 | 550 | $result = $this->mysqli->query($req); |
| 514 | 551 | $counts = array(); |
@@ -518,7 +555,8 @@ discard block |
||
| 518 | 555 | return $counts; |
| 519 | 556 | } |
| 520 | 557 | |
| 521 | - public function getPokemonCountsLastDay() { |
|
| 558 | + public function getPokemonCountsLastDay() |
|
| 559 | + { |
|
| 522 | 560 | $req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day |
| 523 | 561 | FROM pokemon |
| 524 | 562 | WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY |
@@ -532,7 +570,8 @@ discard block |
||
| 532 | 570 | return $counts; |
| 533 | 571 | } |
| 534 | 572 | |
| 535 | - public function getPokemonSinceLastUpdate($pokemon_id, $last_update) { |
|
| 573 | + public function getPokemonSinceLastUpdate($pokemon_id, $last_update) |
|
| 574 | + { |
|
| 536 | 575 | $where = "WHERE p.pokemon_id = '".$pokemon_id."' AND (UNIX_TIMESTAMP(p.disappear_time) - (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900) > '".$last_update."'"; |
| 537 | 576 | $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 |
| 538 | 577 | FROM pokemon p |
@@ -550,7 +589,8 @@ discard block |
||
| 550 | 589 | return $data; |
| 551 | 590 | } |
| 552 | 591 | |
| 553 | - public function getRaidsSinceLastUpdate($pokemon_id, $last_update) { |
|
| 592 | + public function getRaidsSinceLastUpdate($pokemon_id, $last_update) |
|
| 593 | + { |
|
| 554 | 594 | $where = "WHERE pokemon_id = '".$pokemon_id."' AND UNIX_TIMESTAMP(start) > '".$last_update."'"; |
| 555 | 595 | $req = "SELECT UNIX_TIMESTAMP(start) as start_timestamp, end, (CONVERT_TZ(end, '+00:00', '".self::$time_offset."')) AS end_time_real, latitude, longitude, count |
| 556 | 596 | FROM raid r |
@@ -568,14 +608,16 @@ discard block |
||
| 568 | 608 | return $data; |
| 569 | 609 | } |
| 570 | 610 | |
| 571 | - public function getCaptchaCount() { |
|
| 611 | + public function getCaptchaCount() |
|
| 612 | + { |
|
| 572 | 613 | $req = "SELECT SUM(accounts_captcha) AS total FROM mainworker"; |
| 573 | 614 | $result = $this->mysqli->query($req); |
| 574 | 615 | $data = $result->fetch_object(); |
| 575 | 616 | return $data; |
| 576 | 617 | } |
| 577 | 618 | |
| 578 | - public function getNestData() { |
|
| 619 | + public function getNestData() |
|
| 620 | + { |
|
| 579 | 621 | $pokemon_exclude_sql = ""; |
| 580 | 622 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 581 | 623 | $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", self::$config->system->nest_exclude_pokemon).")"; |