@@ -216,6 +216,9 @@ |
||
| 216 | 216 | ######################################################################## |
| 217 | 217 | // used in get_tree_at_depth |
| 218 | 218 | ######################################################################## |
| 219 | +/** |
|
| 220 | + * @param boolean $correct_arrow |
|
| 221 | + */ |
|
| 219 | 222 | function tree_check_array($array_check, $array_add, $correct_arrow) { |
| 220 | 223 | $count = count($array_check); |
| 221 | 224 | $i = 0; |
@@ -372,7 +372,7 @@ |
||
| 372 | 372 | |
| 373 | 373 | $firstElePoly = $polygons[$index][0]; |
| 374 | 374 | $lastElePoly = $polygons[$index][count($polygons[$index]) - 1]; |
| 375 | - if ($firstElePoly == $lastElePoly){ |
|
| 375 | + if ($firstElePoly == $lastElePoly) { |
|
| 376 | 376 | $index++; |
| 377 | 377 | } |
| 378 | 378 | } |
@@ -181,7 +181,8 @@ discard block |
||
| 181 | 181 | // |
| 182 | 182 | // Retruns max depth of array |
| 183 | 183 | ######################################################################## |
| 184 | -function get_depth($arr) { |
|
| 184 | +function get_depth($arr) |
|
| 185 | +{ |
|
| 185 | 186 | $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr)); |
| 186 | 187 | $depth = 0; |
| 187 | 188 | foreach ($it as $v) { |
@@ -199,12 +200,16 @@ discard block |
||
| 199 | 200 | // |
| 200 | 201 | // Return all pokemon with data at a certain tree depth |
| 201 | 202 | ######################################################################## |
| 202 | -function get_tree_at_depth($trees, $depth, $max_pokemon, $currentDepth = 0) { |
|
| 203 | - if ($depth == $currentDepth) { // Found depth |
|
| 203 | +function get_tree_at_depth($trees, $depth, $max_pokemon, $currentDepth = 0) |
|
| 204 | +{ |
|
| 205 | + if ($depth == $currentDepth) { |
|
| 206 | +// Found depth |
|
| 204 | 207 | return tree_remove_bellow($trees, $max_pokemon); |
| 205 | - } else { // Go deeper |
|
| 208 | + } else { |
|
| 209 | +// Go deeper |
|
| 206 | 210 | $arr = array(); |
| 207 | - foreach ($trees as $temp) { // Go into all trees |
|
| 211 | + foreach ($trees as $temp) { |
|
| 212 | +// Go into all trees |
|
| 208 | 213 | $tree = $temp->evolutions; |
| 209 | 214 | $results = tree_remove_bellow(get_tree_at_depth($tree, $depth, $max_pokemon, $currentDepth + 1), $max_pokemon); |
| 210 | 215 | $arr = tree_check_array($results, $arr, $depth - $currentDepth == 1); |
@@ -216,12 +221,16 @@ discard block |
||
| 216 | 221 | ######################################################################## |
| 217 | 222 | // used in get_tree_at_depth |
| 218 | 223 | ######################################################################## |
| 219 | -function tree_check_array($array_check, $array_add, $correct_arrow) { |
|
| 224 | +function tree_check_array($array_check, $array_add, $correct_arrow) |
|
| 225 | +{ |
|
| 220 | 226 | $count = count($array_check); |
| 221 | 227 | $i = 0; |
| 222 | - if (!is_null($array_check)) { // check if exists |
|
| 223 | - foreach ($array_check as $res) { // Check if above, equal or bellow center |
|
| 224 | - if ($count != 1 && $correct_arrow) { // only add arrow once |
|
| 228 | + if (!is_null($array_check)) { |
|
| 229 | +// check if exists |
|
| 230 | + foreach ($array_check as $res) { |
|
| 231 | +// Check if above, equal or bellow center |
|
| 232 | + if ($count != 1 && $correct_arrow) { |
|
| 233 | +// only add arrow once |
|
| 225 | 234 | $num = $i / ($count - 1); |
| 226 | 235 | if ($num < 0.5) { |
| 227 | 236 | $res->array_sufix = "_up"; |
@@ -249,7 +258,8 @@ discard block |
||
| 249 | 258 | return null; |
| 250 | 259 | } |
| 251 | 260 | $arr = array(); |
| 252 | - foreach ($tree as $item) { // Check if above, equal or bellow center |
|
| 261 | + foreach ($tree as $item) { |
|
| 262 | +// Check if above, equal or bellow center |
|
| 253 | 263 | if ($item->id <= $max_pokemon) { |
| 254 | 264 | $arr[] = $item; |
| 255 | 265 | } |
@@ -283,7 +293,8 @@ discard block |
||
| 283 | 293 | ######################################################################## |
| 284 | 294 | // check if point is inside porygon |
| 285 | 295 | ######################################################################## |
| 286 | -function pointIsInsidePolygon($lat, $lng, $geos, $bounds) { |
|
| 296 | +function pointIsInsidePolygon($lat, $lng, $geos, $bounds) |
|
| 297 | +{ |
|
| 287 | 298 | if ($lat >= $bounds["minlat"] && $lat <= $bounds["maxlat"] && $lng >= $bounds["minlon"] && $lng <= $bounds["maxlon"]) { |
| 288 | 299 | |
| 289 | 300 | $intersections = 0; |
@@ -292,15 +303,18 @@ discard block |
||
| 292 | 303 | for ($i = 1; $i < $geos_count; $i++) { |
| 293 | 304 | $geo1 = $geos[$i - 1]; |
| 294 | 305 | $geo2 = $geos[$i]; |
| 295 | - if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { // On one of the coords |
|
| 306 | + if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { |
|
| 307 | +// On one of the coords |
|
| 296 | 308 | return true; |
| 297 | 309 | } |
| 298 | - if ($geo1['lng'] == $geo2['lng'] and $geo1['lng'] == $lng and $lat > min($geo1['lat'], $geo2['lat']) and $lat < max($geo1['lat'], $geo2['lat'])) { // Check if point is on an horizontal polygon boundary |
|
| 310 | + if ($geo1['lng'] == $geo2['lng'] and $geo1['lng'] == $lng and $lat > min($geo1['lat'], $geo2['lat']) and $lat < max($geo1['lat'], $geo2['lat'])) { |
|
| 311 | +// Check if point is on an horizontal polygon boundary |
|
| 299 | 312 | return true; |
| 300 | 313 | } |
| 301 | 314 | if ($lng > min($geo1['lng'], $geo2['lng']) and $lng <= max($geo1['lng'], $geo2['lng']) and $lat <= max($geo1['lat'], $geo2['lat']) and $geo1['lng'] != $geo2['lng']) { |
| 302 | 315 | $xinters = ($lng - $geo1['lng']) * ($geo2['lat'] - $geo1['lat']) / ($geo2['lng'] - $geo1['lng']) + $geo1['lat']; |
| 303 | - if ($xinters == $lat) { // Check if point is on the polygon boundary (other than horizontal) |
|
| 316 | + if ($xinters == $lat) { |
|
| 317 | +// Check if point is on the polygon boundary (other than horizontal) |
|
| 304 | 318 | return true; |
| 305 | 319 | } |
| 306 | 320 | if ($geo1['lat'] == $geo2['lat'] || $lat <= $xinters) { |
@@ -322,7 +336,8 @@ discard block |
||
| 322 | 336 | ######################################################################## |
| 323 | 337 | // check if $boundsIn is inside (or equal to) $boundsOut |
| 324 | 338 | ######################################################################## |
| 325 | -function polyIsInsidePolygon($geoIn, $boundsIn, $geoOut, $boundsOut) { |
|
| 339 | +function polyIsInsidePolygon($geoIn, $boundsIn, $geoOut, $boundsOut) |
|
| 340 | +{ |
|
| 326 | 341 | if ($boundsIn["minlat"] >= $boundsOut["minlat"] && $boundsIn["maxlat"] <= $boundsOut["maxlat"] && $boundsIn["minlon"] >= $boundsOut["minlon"] && $boundsIn["maxlon"] <= $boundsOut["maxlon"]) { |
| 327 | 342 | $insideCount = 0; |
| 328 | 343 | foreach ($geoIn as $coord) { |
@@ -339,7 +354,8 @@ discard block |
||
| 339 | 354 | ######################################################################## |
| 340 | 355 | // compine outer ways into porygon |
| 341 | 356 | ######################################################################## |
| 342 | -function combineOuter($outers) { |
|
| 357 | +function combineOuter($outers) |
|
| 358 | +{ |
|
| 343 | 359 | $polygons = array(); |
| 344 | 360 | $index = 0; |
| 345 | 361 | $count = 0; |
@@ -372,7 +388,7 @@ discard block |
||
| 372 | 388 | |
| 373 | 389 | $firstElePoly = $polygons[$index][0]; |
| 374 | 390 | $lastElePoly = $polygons[$index][count($polygons[$index]) - 1]; |
| 375 | - if ($firstElePoly == $lastElePoly){ |
|
| 391 | + if ($firstElePoly == $lastElePoly) { |
|
| 376 | 392 | $index++; |
| 377 | 393 | } |
| 378 | 394 | } |
@@ -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 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | } while ($migration < new DateTime()); |
| 91 | 91 | $migration = $migrationPrev->getTimestamp(); |
| 92 | 92 | |
| 93 | -if ( filemtime($nests_parks_file) - $migration <= 0 ) { |
|
| 93 | +if (filemtime($nests_parks_file) - $migration <= 0) { |
|
| 94 | 94 | file_put_contents($nests_file, json_encode(array())); |
| 95 | 95 | file_put_contents($nests_parks_file, json_encode(array())); |
| 96 | 96 | touch($nests_parks_file, 1); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | touch($pokedex_rarity_file); |
| 104 | 104 | // update pokedex rarity |
| 105 | 105 | include_once(SYS_PATH.'/core/cron/pokedex_rarity.cron.php'); |
| 106 | -} elseif ( (file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400) ) { # extra update 12h after migration |
|
| 106 | +} elseif ((file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400)) { # extra update 12h after migration |
|
| 107 | 107 | if (is_file($nests_parks_file)) { |
| 108 | 108 | $prevNestTime = filemtime($nests_parks_file); |
| 109 | 109 | } else { |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | touch($nests_parks_file); |
| 116 | 116 | // update nests |
| 117 | 117 | $nestTime = 12; |
| 118 | - include_once(SYS_PATH . '/core/cron/nests.cron.php'); |
|
| 119 | -} elseif ( (file_update_ago($nests_parks_file) >= 86400) && (time() - $migration >= 86400) ) { |
|
| 118 | + include_once(SYS_PATH.'/core/cron/nests.cron.php'); |
|
| 119 | +} elseif ((file_update_ago($nests_parks_file) >= 86400) && (time() - $migration >= 86400)) { |
|
| 120 | 120 | if (is_file($nests_parks_file)) { |
| 121 | 121 | $prevNestTime = filemtime($nests_parks_file); |
| 122 | 122 | } else { |
@@ -128,5 +128,5 @@ discard block |
||
| 128 | 128 | touch($nests_parks_file); |
| 129 | 129 | // update nests |
| 130 | 130 | $nestTime = 24; |
| 131 | - include_once(SYS_PATH . '/core/cron/nests.cron.php'); |
|
| 131 | + include_once(SYS_PATH.'/core/cron/nests.cron.php'); |
|
| 132 | 132 | } |
@@ -103,7 +103,8 @@ |
||
| 103 | 103 | touch($pokedex_rarity_file); |
| 104 | 104 | // update pokedex rarity |
| 105 | 105 | include_once(SYS_PATH.'/core/cron/pokedex_rarity.cron.php'); |
| 106 | -} elseif ( (file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400) ) { # extra update 12h after migration |
|
| 106 | +} elseif ( (file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400) ) { |
|
| 107 | +# extra update 12h after migration |
|
| 107 | 108 | if (is_file($nests_parks_file)) { |
| 108 | 109 | $prevNestTime = filemtime($nests_parks_file); |
| 109 | 110 | } else { |
@@ -25,7 +25,8 @@ |
||
| 25 | 25 | $minLongitude = $totalMinLon + $iLng * 0.5; |
| 26 | 26 | $maxLongitude = min($minLongitude + 0.5 ,$totalMaxLon); |
| 27 | 27 | |
| 28 | - if ($manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total == 0) { //Skip empty areas |
|
| 28 | + if ($manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total == 0) { |
|
| 29 | +//Skip empty areas |
|
| 29 | 30 | $iLng++; |
| 30 | 31 | continue; |
| 31 | 32 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | $minLatitude = $totalMinLat + $iLat * 0.5; |
| 24 | 24 | $maxLatitude = min($minLatitude + 0.5, $totalMaxLat); |
| 25 | 25 | $minLongitude = $totalMinLon + $iLng * 0.5; |
| 26 | - $maxLongitude = min($minLongitude + 0.5 ,$totalMaxLon); |
|
| 26 | + $maxLongitude = min($minLongitude + 0.5, $totalMaxLon); |
|
| 27 | 27 | |
| 28 | 28 | if ($manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total == 0) { //Skip empty areas |
| 29 | 29 | $iLng++; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // Get Parks from overpass |
| 34 | - $req = '[timeout:600][out:json][date:"2017-01-22T00:00:00Z"][bbox:' . $minLatitude . ',' . $minLongitude . ',' . $maxLatitude . ',' . $maxLongitude . ']; |
|
| 34 | + $req = '[timeout:600][out:json][date:"2017-01-22T00:00:00Z"][bbox:'.$minLatitude.','.$minLongitude.','.$maxLatitude.','.$maxLongitude.']; |
|
| 35 | 35 | ( |
| 36 | 36 | way["leisure"="park"]; |
| 37 | 37 | way["leisure"="garden"]; |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | $curl = curl_init($endpoint); |
| 90 | 90 | |
| 91 | 91 | curl_setopt($curl, CURLOPT_POST, 1); |
| 92 | - curl_setopt($curl, CURLOPT_POSTFIELDS, "data=" . urlencode($req)); |
|
| 93 | - curl_setopt($curl, CURLOPT_USERAGENT,"Worldopole/NestUpdater ".$config->infos->site_name); |
|
| 92 | + curl_setopt($curl, CURLOPT_POSTFIELDS, "data=".urlencode($req)); |
|
| 93 | + curl_setopt($curl, CURLOPT_USERAGENT, "Worldopole/NestUpdater ".$config->infos->site_name); |
|
| 94 | 94 | curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); |
| 95 | 95 | curl_setopt($curl, CURLOPT_TIMEOUT, 660); |
| 96 | 96 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | echo "Got Error 429: Trying again in 5 Minutes...\n"; |
| 219 | 219 | sleep(300); |
| 220 | 220 | } else { |
| 221 | - echo "Error " . $status . " while getting nests from overpass-turbo. Aborting Nest Update.\n"; |
|
| 221 | + echo "Error ".$status." while getting nests from overpass-turbo. Aborting Nest Update.\n"; |
|
| 222 | 222 | touch($nests_parks_file, $prevNestTime); |
| 223 | 223 | exit(); |
| 224 | 224 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
| 174 | 174 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS \"IV\", move_1 as move_1, move_2, form |
| 175 | 175 | FROM sightings |
| 176 | - WHERE pokemon_id = '" . $pokemon_id . "' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 176 | + WHERE pokemon_id = '" . $pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 177 | 177 | ORDER BY $top_order_by $top_direction, expire_timestamp DESC |
| 178 | 178 | LIMIT 50 OFFSET 0"; |
| 179 | 179 | $result = pg_query($this->db, $req); |
@@ -187,13 +187,13 @@ discard block |
||
| 187 | 187 | function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
| 188 | 188 | $trainer_blacklist = ""; |
| 189 | 189 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 190 | - $trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')"; |
|
| 190 | + $trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | $req = "SELECT owner_name as trainer_name, ROUND((100.0*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS \"IV\", move_1, move_2, cp as cp, |
| 194 | 194 | TO_TIMESTAMP(last_modified) AS lasttime, last_modified as last_seen |
| 195 | 195 | FROM gym_defenders |
| 196 | - WHERE pokemon_id = '" . $pokemon_id . "'" . $trainer_blacklist . " |
|
| 196 | + WHERE pokemon_id = '" . $pokemon_id."'".$trainer_blacklist." |
|
| 197 | 197 | ORDER BY $best_order_by $best_direction, owner_name ASC |
| 198 | 198 | LIMIT 50 OFFSET 0"; |
| 199 | 199 | |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
| 237 | 237 | $inmap_pkms_filter = ""; |
| 238 | - $where = " WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = " . $pokemon_id; |
|
| 238 | + $where = " WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = ".$pokemon_id; |
|
| 239 | 239 | |
| 240 | - $reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings " . $where; |
|
| 240 | + $reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings ".$where; |
|
| 241 | 241 | $resultTestIv = pg_query($this->db, $reqTestIv); |
| 242 | 242 | $testIv = pg_fetch_object($resultTestIv); |
| 243 | 243 | if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) { |
@@ -245,20 +245,20 @@ discard block |
||
| 245 | 245 | $inmap_pkms_filter .= "'".$inmap."',"; |
| 246 | 246 | } |
| 247 | 247 | $inmap_pkms_filter = rtrim($inmap_pkms_filter, ","); |
| 248 | - $where .= " AND encounter_id NOT IN (" . $inmap_pkms_filter . ") "; |
|
| 248 | + $where .= " AND encounter_id NOT IN (".$inmap_pkms_filter.") "; |
|
| 249 | 249 | } |
| 250 | 250 | if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) { |
| 251 | - $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (" . $ivMin . ") "; |
|
| 251 | + $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (".$ivMin.") "; |
|
| 252 | 252 | } |
| 253 | 253 | if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) { |
| 254 | - $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (" . $ivMax . ") "; |
|
| 254 | + $where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (".$ivMax.") "; |
|
| 255 | 255 | } |
| 256 | 256 | $req = "SELECT pokemon_id, lat AS latitude, lon AS longitude, |
| 257 | 257 | TO_TIMESTAMP(expire_timestamp) AS disappear_time, |
| 258 | 258 | TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, |
| 259 | 259 | atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina, |
| 260 | 260 | move_1, move_2 |
| 261 | - FROM sightings " . $where . " |
|
| 261 | + FROM sightings " . $where." |
|
| 262 | 262 | LIMIT 5000"; |
| 263 | 263 | $result = pg_query($this->db, $req); |
| 264 | 264 | $spawns = array(); |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points |
| 330 | 330 | FROM forts f |
| 331 | 331 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
| 332 | - WHERE fs.team = '" . $team_id . "'"; |
|
| 332 | + WHERE fs.team = '" . $team_id."'"; |
|
| 333 | 333 | $result = pg_query($this->db, $req); |
| 334 | 334 | $data = pg_fetch_object($result); |
| 335 | 335 | return $data; |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | { |
| 417 | 417 | $req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name |
| 418 | 418 | FROM gym_defenders |
| 419 | - WHERE fort_id = '". $gym_id ."' |
|
| 419 | + WHERE fort_id = '". $gym_id."' |
|
| 420 | 420 | ORDER BY deployment_time"; |
| 421 | 421 | $result = $this->mysqli->query($req); |
| 422 | 422 | $pokemons = array(); |
@@ -436,9 +436,9 @@ discard block |
||
| 436 | 436 | $req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, TO_TIMESTAMP(fs.last_modified) as last_modified, last_modified as last_modified_real |
| 437 | 437 | FROM fort_sightings fs |
| 438 | 438 | LEFT JOIN forts f ON f.id = fs.fort_id |
| 439 | - WHERE f.id = '". $gym_id ."' |
|
| 439 | + WHERE f.id = '". $gym_id."' |
|
| 440 | 440 | ORDER BY fs.last_modified DESC |
| 441 | - LIMIT ".($pageSize+1)." OFFSET ".($page * $pageSize); |
|
| 441 | + LIMIT ".($pageSize + 1)." OFFSET ".($page * $pageSize); |
|
| 442 | 442 | $result = $this->mysqli->query($req); |
| 443 | 443 | $history = array(); |
| 444 | 444 | $count = 0; |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name |
| 471 | 471 | FROM gym_history_defenders ghd |
| 472 | 472 | JOIN gym_defenders gd ON ghd.defender_id = gd.external_id |
| 473 | - WHERE ghd.fort_id = '". $gym_id ."' AND date = '".$last_modified."' |
|
| 473 | + WHERE ghd.fort_id = '". $gym_id."' AND date = '".$last_modified."' |
|
| 474 | 474 | ORDER BY gd.deployment_time"; |
| 475 | 475 | $result = $this->mysqli->query($req); |
| 476 | 476 | $pokemons = array(); |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | /////////// |
| 486 | 486 | |
| 487 | 487 | public function getAllRaids($page) { |
| 488 | - $limit = " LIMIT 10 OFFSET ". ($page * 10); |
|
| 488 | + $limit = " LIMIT 10 OFFSET ".($page * 10); |
|
| 489 | 489 | $req = "SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, TO_TIMESTAMP(r.time_spawn) AS spawn, TO_TIMESTAMP(r.time_battle) AS start, TO_TIMESTAMP(r.time_end) AS end, TO_TIMESTAMP(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude |
| 490 | 490 | FROM forts f |
| 491 | 491 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
@@ -537,8 +537,8 @@ discard block |
||
| 537 | 537 | WHERE fort_id IS NOT NULL |
| 538 | 538 | GROUP BY owner_name |
| 539 | 539 | ) active ON active.owner_name = gd.owner_name |
| 540 | - WHERE level IS NOT NULL " . $where . " |
|
| 541 | - GROUP BY gd.owner_name" . $order . $limit; |
|
| 540 | + WHERE level IS NOT NULL " . $where." |
|
| 541 | + GROUP BY gd.owner_name" . $order.$limit; |
|
| 542 | 542 | $result = $this->mysqli->query($req); |
| 543 | 543 | $trainers = array(); |
| 544 | 544 | while ($data = $result->fetch_object()) { |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | } |
| 549 | 549 | $trainers[$data->name] = $data; |
| 550 | 550 | |
| 551 | - $pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name)); |
|
| 551 | + $pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name)); |
|
| 552 | 552 | |
| 553 | 553 | $trainers[$data->name]->gyms = $data->active; |
| 554 | 554 | $trainers[$data->name]->pokemons = $pokemon; |
@@ -662,9 +662,9 @@ discard block |
||
| 662 | 662 | JOIN (SELECT COUNT(*) AS count |
| 663 | 663 | FROM FROM sightings p |
| 664 | 664 | LEFT JOIN spawnpoints s ON p.spawn_id = s.spawn_id |
| 665 | - " . $where. " |
|
| 665 | + " . $where." |
|
| 666 | 666 | ) count ON 1 = 1 |
| 667 | - " . $where . " |
|
| 667 | + " . $where." |
|
| 668 | 668 | ORDER BY last_timestamp DESC |
| 669 | 669 | LIMIT 1 OFFSET 0"; |
| 670 | 670 | $result = pg_query($this->db, $req); |
@@ -699,14 +699,14 @@ discard block |
||
| 699 | 699 | public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) { |
| 700 | 700 | $pokemon_exclude_sql = ""; |
| 701 | 701 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 702 | - $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")"; |
|
| 702 | + $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", self::$config->system->nest_exclude_pokemon).")"; |
|
| 703 | 703 | } |
| 704 | 704 | $req = "SELECT p.spawn_id, p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(s.updated) as latest_seen, coalesce(CASE WHEN MAX(duration) = 0 THEN NULL ELSE MAX(duration) END ,30)*60 as duration |
| 705 | 705 | FROM sightings p |
| 706 | 706 | INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id) |
| 707 | 707 | WHERE p.expire_timestamp > EXTRACT(EPOCH FROM NOW()) - ".($time * 3600)." |
| 708 | 708 | AND p.lat >= ".$minLatitude." AND p.lat < ".$maxLatitude." AND p.lon >= ".$minLongitude." AND p.lon < ".$maxLongitude." |
| 709 | - " . $pokemon_exclude_sql . " |
|
| 709 | + " . $pokemon_exclude_sql." |
|
| 710 | 710 | GROUP BY p.spawn_id, p.pokemon_id |
| 711 | 711 | HAVING COUNT(p.pokemon_id) >= ".($time / 4)." |
| 712 | 712 | ORDER BY p.pokemon_id"; |
@@ -6,13 +6,16 @@ discard block |
||
| 6 | 6 | * Time: 02:26 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -class QueryManagerPostgresqlMonocleAlternate extends QueryManagerPostgresql { |
|
| 9 | +class QueryManagerPostgresqlMonocleAlternate extends QueryManagerPostgresql |
|
| 10 | +{ |
|
| 10 | 11 | |
| 11 | - public function __construct() { |
|
| 12 | + public function __construct() |
|
| 13 | + { |
|
| 12 | 14 | parent::__construct(); |
| 13 | 15 | } |
| 14 | 16 | |
| 15 | - public function __destruct() { |
|
| 17 | + public function __destruct() |
|
| 18 | + { |
|
| 16 | 19 | parent::__destruct(); |
| 17 | 20 | } |
| 18 | 21 | |
@@ -20,7 +23,8 @@ discard block |
||
| 20 | 23 | // Tester |
| 21 | 24 | /////////// |
| 22 | 25 | |
| 23 | - function testTotalPokemon() { |
|
| 26 | + function testTotalPokemon() |
|
| 27 | + { |
|
| 24 | 28 | $req = "SELECT COUNT(*) as total FROM sightings"; |
| 25 | 29 | $result = pg_query($this->db, $req); |
| 26 | 30 | if ($result === false) { |
@@ -36,7 +40,8 @@ discard block |
||
| 36 | 40 | return 0; |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | - function testTotalGyms() { |
|
| 43 | + function testTotalGyms() |
|
| 44 | + { |
|
| 40 | 45 | $req = "SELECT COUNT(*) as total FROM forts"; |
| 41 | 46 | $result = pg_query($this->db, $req); |
| 42 | 47 | if ($result === false) { |
@@ -52,7 +57,8 @@ discard block |
||
| 52 | 57 | return 0; |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | - function testTotalPokestops() { |
|
| 60 | + function testTotalPokestops() |
|
| 61 | + { |
|
| 56 | 62 | $req = "SELECT COUNT(*) as total FROM pokestops"; |
| 57 | 63 | $result = pg_query($this->db, $req); |
| 58 | 64 | if ($result === false) { |
@@ -73,26 +79,30 @@ discard block |
||
| 73 | 79 | // Homepage |
| 74 | 80 | ///////////// |
| 75 | 81 | |
| 76 | - function getTotalPokemon() { |
|
| 82 | + function getTotalPokemon() |
|
| 83 | + { |
|
| 77 | 84 | $req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())"; |
| 78 | 85 | $result = pg_query($this->db, $req); |
| 79 | 86 | $data = pg_fetch_object($result); |
| 80 | 87 | return $data; |
| 81 | 88 | } |
| 82 | 89 | |
| 83 | - function getTotalLures() { |
|
| 90 | + function getTotalLures() |
|
| 91 | + { |
|
| 84 | 92 | $data = (object) array("total" => 0); |
| 85 | 93 | return $data; |
| 86 | 94 | } |
| 87 | 95 | |
| 88 | - function getTotalGyms() { |
|
| 96 | + function getTotalGyms() |
|
| 97 | + { |
|
| 89 | 98 | $req = "SELECT COUNT(*) AS total FROM forts"; |
| 90 | 99 | $result = pg_query($this->db, $req); |
| 91 | 100 | $data = pg_fetch_object($result); |
| 92 | 101 | return $data; |
| 93 | 102 | } |
| 94 | 103 | |
| 95 | - function getTotalRaids() { |
|
| 104 | + function getTotalRaids() |
|
| 105 | + { |
|
| 96 | 106 | $req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())"; |
| 97 | 107 | $result = pg_query($this->db, $req); |
| 98 | 108 | $data = pg_fetch_object($result); |
@@ -100,7 +110,8 @@ discard block |
||
| 100 | 110 | } |
| 101 | 111 | |
| 102 | 112 | |
| 103 | - function getTotalGymsForTeam($team_id) { |
|
| 113 | + function getTotalGymsForTeam($team_id) |
|
| 114 | + { |
|
| 104 | 115 | $req = "SELECT COUNT(*) AS total |
| 105 | 116 | FROM forts f |
| 106 | 117 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
@@ -110,7 +121,8 @@ discard block |
||
| 110 | 121 | return $data; |
| 111 | 122 | } |
| 112 | 123 | |
| 113 | - function getRecentAll() { |
|
| 124 | + function getRecentAll() |
|
| 125 | + { |
|
| 114 | 126 | $req = "SELECT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, |
| 115 | 127 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
| 116 | 128 | FROM sightings |
@@ -126,7 +138,8 @@ discard block |
||
| 126 | 138 | return $data; |
| 127 | 139 | } |
| 128 | 140 | |
| 129 | - function getRecentMythic($mythic_pokemon) { |
|
| 141 | + function getRecentMythic($mythic_pokemon) |
|
| 142 | + { |
|
| 130 | 143 | $req = "SELECT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, |
| 131 | 144 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
| 132 | 145 | FROM sightings |
@@ -147,7 +160,8 @@ discard block |
||
| 147 | 160 | // Single Pokemon |
| 148 | 161 | /////////////////// |
| 149 | 162 | |
| 150 | - function getGymsProtectedByPokemon($pokemon_id) { |
|
| 163 | + function getGymsProtectedByPokemon($pokemon_id) |
|
| 164 | + { |
|
| 151 | 165 | $req = "SELECT COUNT(f.id) AS total |
| 152 | 166 | FROM forts f |
| 153 | 167 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
@@ -157,7 +171,8 @@ discard block |
||
| 157 | 171 | return $data; |
| 158 | 172 | } |
| 159 | 173 | |
| 160 | - function getPokemonLastSeen($pokemon_id) { |
|
| 174 | + function getPokemonLastSeen($pokemon_id) |
|
| 175 | + { |
|
| 161 | 176 | $req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
| 162 | 177 | FROM sightings |
| 163 | 178 | WHERE pokemon_id = '".$pokemon_id."' |
@@ -168,7 +183,8 @@ discard block |
||
| 168 | 183 | return $data; |
| 169 | 184 | } |
| 170 | 185 | |
| 171 | - function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) { |
|
| 186 | + function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 187 | + { |
|
| 172 | 188 | $req = "SELECT expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS distime, pokemon_id as pokemon_id, TO_TIMESTAMP(expire_timestamp) as disappear_time, lat as latitude, lon as longitude, |
| 173 | 189 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
| 174 | 190 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS \"IV\", move_1 as move_1, move_2, form |
@@ -184,7 +200,8 @@ discard block |
||
| 184 | 200 | return $top; |
| 185 | 201 | } |
| 186 | 202 | |
| 187 | - function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
|
| 203 | + function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 204 | + { |
|
| 188 | 205 | $trainer_blacklist = ""; |
| 189 | 206 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 190 | 207 | $trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')"; |
@@ -205,7 +222,8 @@ discard block |
||
| 205 | 222 | return $toptrainer; |
| 206 | 223 | } |
| 207 | 224 | |
| 208 | - public function getPokemonHeatmap($pokemon_id, $start, $end) { |
|
| 225 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 226 | + { |
|
| 209 | 227 | $where = " WHERE pokemon_id = ".$pokemon_id." " |
| 210 | 228 | . "AND TO_TIMESTAMP(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
| 211 | 229 | $req = "SELECT lat AS latitude, lon AS longitude FROM sightings".$where." LIMIT 100000"; |
@@ -217,7 +235,8 @@ discard block |
||
| 217 | 235 | return $points; |
| 218 | 236 | } |
| 219 | 237 | |
| 220 | - public function getPokemonGraph($pokemon_id) { |
|
| 238 | + public function getPokemonGraph($pokemon_id) |
|
| 239 | + { |
|
| 221 | 240 | $req = "SELECT COUNT(*) AS total, EXTRACT(HOUR FROM disappear_time) AS disappear_hour |
| 222 | 241 | FROM (SELECT TO_TIMESTAMP(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
| 223 | 242 | GROUP BY disappear_hour |
@@ -233,7 +252,8 @@ discard block |
||
| 233 | 252 | return $array; |
| 234 | 253 | } |
| 235 | 254 | |
| 236 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
|
| 255 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
| 256 | + { |
|
| 237 | 257 | $inmap_pkms_filter = ""; |
| 238 | 258 | $where = " WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = " . $pokemon_id; |
| 239 | 259 | |
@@ -268,14 +288,16 @@ discard block |
||
| 268 | 288 | return $spawns; |
| 269 | 289 | } |
| 270 | 290 | |
| 271 | - public function getPokemonSliderMinMax() { |
|
| 291 | + public function getPokemonSliderMinMax() |
|
| 292 | + { |
|
| 272 | 293 | $req = "SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings"; |
| 273 | 294 | $result = pg_query($this->db, $req); |
| 274 | 295 | $data = pg_fetch_object($result); |
| 275 | 296 | return $data; |
| 276 | 297 | } |
| 277 | 298 | |
| 278 | - public function getMapsCoords() { |
|
| 299 | + public function getMapsCoords() |
|
| 300 | + { |
|
| 279 | 301 | $req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints"; |
| 280 | 302 | $result = pg_query($this->db, $req); |
| 281 | 303 | $data = pg_fetch_object($result); |
@@ -288,14 +310,16 @@ discard block |
||
| 288 | 310 | ////////////// |
| 289 | 311 | |
| 290 | 312 | |
| 291 | - function getTotalPokestops() { |
|
| 313 | + function getTotalPokestops() |
|
| 314 | + { |
|
| 292 | 315 | $req = "SELECT COUNT(*) as total FROM pokestops"; |
| 293 | 316 | $result = pg_query($this->db, $req); |
| 294 | 317 | $data = pg_fetch_object($result); |
| 295 | 318 | return $data; |
| 296 | 319 | } |
| 297 | 320 | |
| 298 | - public function getAllPokestops() { |
|
| 321 | + public function getAllPokestops() |
|
| 322 | + { |
|
| 299 | 323 | $req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, EXTRACT(EPOCH FROM NOW()) AS now, null AS lure_expiration_real FROM pokestops"; |
| 300 | 324 | $result = pg_query($this->db, $req); |
| 301 | 325 | $pokestops = array(); |
@@ -310,7 +334,8 @@ discard block |
||
| 310 | 334 | // Gyms |
| 311 | 335 | ///////// |
| 312 | 336 | |
| 313 | - function getTeamGuardians($team_id) { |
|
| 337 | + function getTeamGuardians($team_id) |
|
| 338 | + { |
|
| 314 | 339 | $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
| 315 | 340 | FROM forts f |
| 316 | 341 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
@@ -325,7 +350,8 @@ discard block |
||
| 325 | 350 | return $datas; |
| 326 | 351 | } |
| 327 | 352 | |
| 328 | - function getOwnedAndPoints($team_id) { |
|
| 353 | + function getOwnedAndPoints($team_id) |
|
| 354 | + { |
|
| 329 | 355 | $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points |
| 330 | 356 | FROM forts f |
| 331 | 357 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
@@ -335,7 +361,8 @@ discard block |
||
| 335 | 361 | return $data; |
| 336 | 362 | } |
| 337 | 363 | |
| 338 | - function getAllGyms() { |
|
| 364 | + function getAllGyms() |
|
| 365 | + { |
|
| 339 | 366 | $req = "SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level |
| 340 | 367 | FROM forts f |
| 341 | 368 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))"; |
@@ -347,7 +374,8 @@ discard block |
||
| 347 | 374 | return $gyms; |
| 348 | 375 | } |
| 349 | 376 | |
| 350 | - public function getGymData($gym_id) { |
|
| 377 | + public function getGymData($gym_id) |
|
| 378 | + { |
|
| 351 | 379 | $req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, TO_TIMESTAMP(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, fs.total_cp |
| 352 | 380 | FROM forts f |
| 353 | 381 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
@@ -358,7 +386,8 @@ discard block |
||
| 358 | 386 | return $data; |
| 359 | 387 | } |
| 360 | 388 | |
| 361 | - public function getGymDefenders($gym_id) { |
|
| 389 | + public function getGymDefenders($gym_id) |
|
| 390 | + { |
|
| 362 | 391 | $req = "SELECT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id |
| 363 | 392 | FROM gym_defenders |
| 364 | 393 | WHERE fort_id='".$gym_id."' |
@@ -484,7 +513,8 @@ discard block |
||
| 484 | 513 | // Raids |
| 485 | 514 | /////////// |
| 486 | 515 | |
| 487 | - public function getAllRaids($page) { |
|
| 516 | + public function getAllRaids($page) |
|
| 517 | + { |
|
| 488 | 518 | $limit = " LIMIT 10 OFFSET ". ($page * 10); |
| 489 | 519 | $req = "SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, TO_TIMESTAMP(r.time_spawn) AS spawn, TO_TIMESTAMP(r.time_battle) AS start, TO_TIMESTAMP(r.time_end) AS end, TO_TIMESTAMP(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude |
| 490 | 520 | FROM forts f |
@@ -505,7 +535,8 @@ discard block |
||
| 505 | 535 | // Trainers |
| 506 | 536 | ////////////// |
| 507 | 537 | |
| 508 | - public function getTrainers($trainer_name, $team, $page, $rankingNumber) { |
|
| 538 | + public function getTrainers($trainer_name, $team, $page, $rankingNumber) |
|
| 539 | + { |
|
| 509 | 540 | $ranking = $this->getTrainerLevelRanking(); |
| 510 | 541 | $where = ""; |
| 511 | 542 | if (!empty(self::$config->system->trainer_blacklist)) { |
@@ -557,7 +588,8 @@ discard block |
||
| 557 | 588 | return $trainers; |
| 558 | 589 | } |
| 559 | 590 | |
| 560 | - public function getTrainerLevelRanking() { |
|
| 591 | + public function getTrainerLevelRanking() |
|
| 592 | + { |
|
| 561 | 593 | $exclue = ""; |
| 562 | 594 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 563 | 595 | $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -578,7 +610,8 @@ discard block |
||
| 578 | 610 | return $levelData; |
| 579 | 611 | } |
| 580 | 612 | |
| 581 | - public function getActivePokemon($trainer_name) { |
|
| 613 | + public function getActivePokemon($trainer_name) |
|
| 614 | + { |
|
| 582 | 615 | $req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, TO_TIMESTAMP(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned |
| 583 | 616 | FROM gym_defenders |
| 584 | 617 | WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL |
@@ -591,7 +624,8 @@ discard block |
||
| 591 | 624 | return $pokemon; |
| 592 | 625 | } |
| 593 | 626 | |
| 594 | - public function getInactivePokemon($trainer_name) { |
|
| 627 | + public function getInactivePokemon($trainer_name) |
|
| 628 | + { |
|
| 595 | 629 | $req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, NULL AS deployment_time, '0' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned |
| 596 | 630 | FROM gym_defenders |
| 597 | 631 | WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL |
@@ -604,7 +638,8 @@ discard block |
||
| 604 | 638 | return $pokemon; |
| 605 | 639 | } |
| 606 | 640 | |
| 607 | - public function getTrainerLevelCount($team_id) { |
|
| 641 | + public function getTrainerLevelCount($team_id) |
|
| 642 | + { |
|
| 608 | 643 | $exclue = ""; |
| 609 | 644 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 610 | 645 | $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -630,7 +665,8 @@ discard block |
||
| 630 | 665 | // Cron |
| 631 | 666 | ///////// |
| 632 | 667 | |
| 633 | - public function getPokemonCountsActive() { |
|
| 668 | + public function getPokemonCountsActive() |
|
| 669 | + { |
|
| 634 | 670 | $req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) GROUP BY pokemon_id"; |
| 635 | 671 | $result = pg_query($this->db, $req); |
| 636 | 672 | $counts = array(); |
@@ -640,7 +676,8 @@ discard block |
||
| 640 | 676 | return $counts; |
| 641 | 677 | } |
| 642 | 678 | |
| 643 | - public function getPokemonCountsLastDay() { |
|
| 679 | + public function getPokemonCountsLastDay() |
|
| 680 | + { |
|
| 644 | 681 | $req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day |
| 645 | 682 | FROM sightings |
| 646 | 683 | WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings) |
@@ -654,7 +691,8 @@ discard block |
||
| 654 | 691 | return $counts; |
| 655 | 692 | } |
| 656 | 693 | |
| 657 | - public function getPokemonSinceLastUpdate($pokemon_id, $last_update) { |
|
| 694 | + public function getPokemonSinceLastUpdate($pokemon_id, $last_update) |
|
| 695 | + { |
|
| 658 | 696 | $where = "WHERE p.pokemon_id = '".$pokemon_id."' AND p.expire_timestamp - (coalesce(CASE WHEN duration = 0 THEN NULL ELSE duration END ,30)*60) > '".$last_update."'"; |
| 659 | 697 | $req = "SELECT count, p.expire_timestamp - (coalesce(CASE WHEN duration = 0 THEN NULL ELSE duration END ,30)*60) AS last_timestamp, (TO_TIMESTAMP(expire_timestamp)) AS disappear_time_real, lat as latitude, lon as longitude |
| 660 | 698 | FROM sightings p |
@@ -672,7 +710,8 @@ discard block |
||
| 672 | 710 | return $data; |
| 673 | 711 | } |
| 674 | 712 | |
| 675 | - public function getRaidsSinceLastUpdate($pokemon_id, $last_update) { |
|
| 713 | + public function getRaidsSinceLastUpdate($pokemon_id, $last_update) |
|
| 714 | + { |
|
| 676 | 715 | $where = "WHERE pokemon_id = '".$pokemon_id."' AND time_battle > '".$last_update."'"; |
| 677 | 716 | $req = "SELECT time_battle AS start_timestamp, time_end as end, (TO_TIMESTAMP(time_end)) AS end_time_real, lat as latitude, lon as longitude, count |
| 678 | 717 | FROM raids r |
@@ -689,14 +728,16 @@ discard block |
||
| 689 | 728 | return $data; |
| 690 | 729 | } |
| 691 | 730 | |
| 692 | - public function getCaptchaCount() { |
|
| 731 | + public function getCaptchaCount() |
|
| 732 | + { |
|
| 693 | 733 | $req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL"; |
| 694 | 734 | $result = pg_query($this->db, $req); |
| 695 | 735 | $data = pg_fetch_object($result); |
| 696 | 736 | return $data; |
| 697 | 737 | } |
| 698 | 738 | |
| 699 | - public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) { |
|
| 739 | + public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 740 | + { |
|
| 700 | 741 | $pokemon_exclude_sql = ""; |
| 701 | 742 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 702 | 743 | $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")"; |
@@ -718,7 +759,8 @@ discard block |
||
| 718 | 759 | return $nests; |
| 719 | 760 | } |
| 720 | 761 | |
| 721 | - public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) { |
|
| 762 | + public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 763 | + { |
|
| 722 | 764 | $req = "SELECT COUNT(*) as total |
| 723 | 765 | FROM spawnpoints |
| 724 | 766 | WHERE lat >= ".$minLatitude." AND lat < ".$maxLatitude." AND lon >= ".$minLongitude." AND lon < ".$maxLongitude; |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | ///////// |
| 300 | 300 | |
| 301 | 301 | function getTeamGuardians($team_id) { |
| 302 | - $req = "SELECT COUNT(*) AS total, guard_pokemon_id FROM gym WHERE team_id = '".$team_id ."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3"; |
|
| 302 | + $req = "SELECT COUNT(*) AS total, guard_pokemon_id FROM gym WHERE team_id = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3"; |
|
| 303 | 303 | $result = $this->mysqli->query($req); |
| 304 | 304 | $datas = array(); |
| 305 | 305 | while ($data = $result->fetch_object()) { |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | |
| 378 | 378 | $limit = " LIMIT ".($page * 10).",10"; |
| 379 | 379 | |
| 380 | - $req = "SELECT gymdetails.gym_id, name, team_id, total_cp, (6 - slots_available) as pokemon_count, (CONVERT_TZ(last_modified, '+00:00', '" . self::$time_offset . "')) as last_modified |
|
| 380 | + $req = "SELECT gymdetails.gym_id, name, team_id, total_cp, (6 - slots_available) as pokemon_count, (CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."')) as last_modified |
|
| 381 | 381 | FROM gymdetails |
| 382 | 382 | LEFT JOIN gym |
| 383 | 383 | ON gymdetails.gym_id = gym.gym_id |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | FROM gymmember |
| 397 | 397 | LEFT JOIN gympokemon |
| 398 | 398 | ON gymmember.pokemon_uid = gympokemon.pokemon_uid |
| 399 | - WHERE gymmember.gym_id = '". $gym_id ."' |
|
| 399 | + WHERE gymmember.gym_id = '". $gym_id."' |
|
| 400 | 400 | ORDER BY deployment_time"; |
| 401 | 401 | $result = $this->mysqli->query($req); |
| 402 | 402 | $pokemons = array(); |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | FROM gymhistory |
| 417 | 417 | WHERE gym_id='".$gym_id."' |
| 418 | 418 | ORDER BY last_modified DESC |
| 419 | - LIMIT ".($page * $pageSize).",".($pageSize+1); |
|
| 419 | + LIMIT ".($page * $pageSize).",".($pageSize + 1); |
|
| 420 | 420 | $result = $this->mysqli->query($req); |
| 421 | 421 | $history = array(); |
| 422 | 422 | $count = 0; |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | FROM gympokemon |
| 557 | 557 | INNER JOIN (SELECT gymmember.pokemon_uid, gymmember.gym_id FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember |
| 558 | 558 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name |
| 559 | - GROUP BY trainer.name " . $where . $order . $limit; |
|
| 559 | + GROUP BY trainer.name " . $where.$order.$limit; |
|
| 560 | 560 | |
| 561 | 561 | $result = $this->mysqli->query($req); |
| 562 | 562 | $trainers = array(); |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | return $data; |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - private function getTrainerActivePokemon($trainer_name){ |
|
| 580 | + private function getTrainerActivePokemon($trainer_name) { |
|
| 581 | 581 | $req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, filtered_gymmember.gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '1' AS active |
| 582 | 582 | FROM gympokemon INNER JOIN |
| 583 | 583 | (SELECT gymmember.pokemon_uid, gymmember.gym_id, gymmember.deployment_time FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.deployment_time, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | return $pokemons; |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | - private function getTrainerInactivePokemon($trainer_name){ |
|
| 595 | + private function getTrainerInactivePokemon($trainer_name) { |
|
| 596 | 596 | $req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, null AS gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '0' AS active |
| 597 | 597 | FROM gympokemon LEFT JOIN |
| 598 | 598 | (SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | JOIN spawnpoint s ON p.spawnpoint_id = s.id |
| 647 | 647 | " . $where." |
| 648 | 648 | ) x |
| 649 | - " . $where . " |
|
| 649 | + " . $where." |
|
| 650 | 650 | ORDER BY last_timestamp DESC |
| 651 | 651 | LIMIT 0,1"; |
| 652 | 652 | $result = $this->mysqli->query($req); |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | INNER JOIN spawnpoint s ON (p.spawnpoint_id = s.id) |
| 690 | 690 | WHERE p.disappear_time > UTC_TIMESTAMP() - INTERVAL ".($time)." HOUR |
| 691 | 691 | AND p.latitude >= ".$minLatitude." AND p.latitude < ".$maxLatitude." AND p.longitude >= ".$minLongitude." AND p.longitude < ".$maxLongitude." |
| 692 | - " . $pokemon_exclude_sql . " |
|
| 692 | + " . $pokemon_exclude_sql." |
|
| 693 | 693 | GROUP BY p.spawnpoint_id, p.pokemon_id |
| 694 | 694 | HAVING COUNT(p.pokemon_id) >= ".($time / 4)." |
| 695 | 695 | ORDER BY p.pokemon_id"; |
@@ -1,12 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -final class QueryManagerMysqlRocketmap extends QueryManagerMysql { |
|
| 3 | +final class QueryManagerMysqlRocketmap extends QueryManagerMysql |
|
| 4 | +{ |
|
| 4 | 5 | |
| 5 | - public function __construct() { |
|
| 6 | + public function __construct() |
|
| 7 | + { |
|
| 6 | 8 | parent::__construct(); |
| 7 | 9 | } |
| 8 | 10 | |
| 9 | - public function __destruct() { |
|
| 11 | + public function __destruct() |
|
| 12 | + { |
|
| 10 | 13 | parent::__destruct(); |
| 11 | 14 | } |
| 12 | 15 | |
@@ -14,7 +17,8 @@ discard block |
||
| 14 | 17 | // Tester |
| 15 | 18 | /////////// |
| 16 | 19 | |
| 17 | - function testTotalPokemon() { |
|
| 20 | + function testTotalPokemon() |
|
| 21 | + { |
|
| 18 | 22 | $req = "SELECT COUNT(*) as total FROM pokemon"; |
| 19 | 23 | $result = $this->mysqli->query($req); |
| 20 | 24 | if (!is_object($result)) { |
@@ -30,7 +34,8 @@ discard block |
||
| 30 | 34 | return 0; |
| 31 | 35 | } |
| 32 | 36 | |
| 33 | - function testTotalGyms() { |
|
| 37 | + function testTotalGyms() |
|
| 38 | + { |
|
| 34 | 39 | $req = "SELECT COUNT(*) as total FROM gym"; |
| 35 | 40 | $result = $this->mysqli->query($req); |
| 36 | 41 | if (!is_object($result)) { |
@@ -46,7 +51,8 @@ discard block |
||
| 46 | 51 | return 0; |
| 47 | 52 | } |
| 48 | 53 | |
| 49 | - function testTotalPokestops() { |
|
| 54 | + function testTotalPokestops() |
|
| 55 | + { |
|
| 50 | 56 | $req = "SELECT COUNT(*) as total FROM pokestop"; |
| 51 | 57 | $result = $this->mysqli->query($req); |
| 52 | 58 | if (!is_object($result)) { |
@@ -67,42 +73,48 @@ discard block |
||
| 67 | 73 | // Homepage |
| 68 | 74 | ///////////// |
| 69 | 75 | |
| 70 | - function getTotalPokemon() { |
|
| 76 | + function getTotalPokemon() |
|
| 77 | + { |
|
| 71 | 78 | $req = "SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()"; |
| 72 | 79 | $result = $this->mysqli->query($req); |
| 73 | 80 | $data = $result->fetch_object(); |
| 74 | 81 | return $data; |
| 75 | 82 | } |
| 76 | 83 | |
| 77 | - function getTotalLures() { |
|
| 84 | + function getTotalLures() |
|
| 85 | + { |
|
| 78 | 86 | $req = "SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()"; |
| 79 | 87 | $result = $this->mysqli->query($req); |
| 80 | 88 | $data = $result->fetch_object(); |
| 81 | 89 | return $data; |
| 82 | 90 | } |
| 83 | 91 | |
| 84 | - function getTotalGyms() { |
|
| 92 | + function getTotalGyms() |
|
| 93 | + { |
|
| 85 | 94 | $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym"; |
| 86 | 95 | $result = $this->mysqli->query($req); |
| 87 | 96 | $data = $result->fetch_object(); |
| 88 | 97 | return $data; |
| 89 | 98 | } |
| 90 | 99 | |
| 91 | - function getTotalRaids() { |
|
| 100 | + function getTotalRaids() |
|
| 101 | + { |
|
| 92 | 102 | $req = "SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP AND end >= UTC_TIMESTAMP()"; |
| 93 | 103 | $result = $this->mysqli->query($req); |
| 94 | 104 | $data = $result->fetch_object(); |
| 95 | 105 | return $data; |
| 96 | 106 | } |
| 97 | 107 | |
| 98 | - function getTotalGymsForTeam($team_id) { |
|
| 108 | + function getTotalGymsForTeam($team_id) |
|
| 109 | + { |
|
| 99 | 110 | $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'"; |
| 100 | 111 | $result = $this->mysqli->query($req); |
| 101 | 112 | $data = $result->fetch_object(); |
| 102 | 113 | return $data; |
| 103 | 114 | } |
| 104 | 115 | |
| 105 | - function getRecentAll() { |
|
| 116 | + function getRecentAll() |
|
| 117 | + { |
|
| 106 | 118 | $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, |
| 107 | 119 | latitude, longitude, cp, individual_attack, individual_defense, individual_stamina |
| 108 | 120 | FROM pokemon |
@@ -118,7 +130,8 @@ discard block |
||
| 118 | 130 | return $data; |
| 119 | 131 | } |
| 120 | 132 | |
| 121 | - function getRecentMythic($mythic_pokemons) { |
|
| 133 | + function getRecentMythic($mythic_pokemons) |
|
| 134 | + { |
|
| 122 | 135 | $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, |
| 123 | 136 | latitude, longitude, cp, individual_attack, individual_defense, individual_stamina |
| 124 | 137 | FROM pokemon |
@@ -139,14 +152,16 @@ discard block |
||
| 139 | 152 | // Single Pokemon |
| 140 | 153 | /////////////////// |
| 141 | 154 | |
| 142 | - function getGymsProtectedByPokemon($pokemon_id) { |
|
| 155 | + function getGymsProtectedByPokemon($pokemon_id) |
|
| 156 | + { |
|
| 143 | 157 | $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'"; |
| 144 | 158 | $result = $this->mysqli->query($req); |
| 145 | 159 | $data = $result->fetch_object(); |
| 146 | 160 | return $data; |
| 147 | 161 | } |
| 148 | 162 | |
| 149 | - function getPokemonLastSeen($pokemon_id) { |
|
| 163 | + function getPokemonLastSeen($pokemon_id) |
|
| 164 | + { |
|
| 150 | 165 | $req = "SELECT disappear_time, (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, latitude, longitude |
| 151 | 166 | FROM pokemon |
| 152 | 167 | WHERE pokemon_id = '".$pokemon_id."' |
@@ -157,7 +172,8 @@ discard block |
||
| 157 | 172 | return $data; |
| 158 | 173 | } |
| 159 | 174 | |
| 160 | - function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) { |
|
| 175 | + function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 176 | + { |
|
| 161 | 177 | $req = "SELECT (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS distime, pokemon_id, disappear_time, latitude, longitude, |
| 162 | 178 | cp, individual_attack, individual_defense, individual_stamina, |
| 163 | 179 | ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, move_1, move_2, form |
@@ -174,7 +190,8 @@ discard block |
||
| 174 | 190 | return $top; |
| 175 | 191 | } |
| 176 | 192 | |
| 177 | - function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
|
| 193 | + function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 194 | + { |
|
| 178 | 195 | $trainer_blacklist = ""; |
| 179 | 196 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 180 | 197 | $trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -195,7 +212,8 @@ discard block |
||
| 195 | 212 | return $toptrainer; |
| 196 | 213 | } |
| 197 | 214 | |
| 198 | - public function getPokemonHeatmap($pokemon_id, $start, $end) { |
|
| 215 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 216 | + { |
|
| 199 | 217 | $where = " WHERE pokemon_id = ".$pokemon_id." " |
| 200 | 218 | . "AND disappear_time BETWEEN '".$start."' AND '".$end."'"; |
| 201 | 219 | $req = "SELECT latitude, longitude FROM pokemon".$where." LIMIT 10000"; |
@@ -207,7 +225,8 @@ discard block |
||
| 207 | 225 | return $points; |
| 208 | 226 | } |
| 209 | 227 | |
| 210 | - public function getPokemonGraph($pokemon_id) { |
|
| 228 | + public function getPokemonGraph($pokemon_id) |
|
| 229 | + { |
|
| 211 | 230 | $req = "SELECT COUNT(*) AS total, |
| 212 | 231 | HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour |
| 213 | 232 | FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
@@ -224,7 +243,8 @@ discard block |
||
| 224 | 243 | return $array; |
| 225 | 244 | } |
| 226 | 245 | |
| 227 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
|
| 246 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
| 247 | + { |
|
| 228 | 248 | $inmap_pkms_filter = ""; |
| 229 | 249 | $where = " WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = ".$pokemon_id; |
| 230 | 250 | |
@@ -257,14 +277,16 @@ discard block |
||
| 257 | 277 | return $spawns; |
| 258 | 278 | } |
| 259 | 279 | |
| 260 | - public function getPokemonSliderMinMax() { |
|
| 280 | + public function getPokemonSliderMinMax() |
|
| 281 | + { |
|
| 261 | 282 | $req = "SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon"; |
| 262 | 283 | $result = $this->mysqli->query($req); |
| 263 | 284 | $data = $result->fetch_object(); |
| 264 | 285 | return $data; |
| 265 | 286 | } |
| 266 | 287 | |
| 267 | - public function getMapsCoords() { |
|
| 288 | + public function getMapsCoords() |
|
| 289 | + { |
|
| 268 | 290 | $req = "SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude FROM spawnpoint"; |
| 269 | 291 | $result = $this->mysqli->query($req); |
| 270 | 292 | $data = $result->fetch_object(); |
@@ -276,14 +298,16 @@ discard block |
||
| 276 | 298 | // Pokestops |
| 277 | 299 | ////////////// |
| 278 | 300 | |
| 279 | - function getTotalPokestops() { |
|
| 301 | + function getTotalPokestops() |
|
| 302 | + { |
|
| 280 | 303 | $req = "SELECT COUNT(*) as total FROM pokestop"; |
| 281 | 304 | $result = $this->mysqli->query($req); |
| 282 | 305 | $data = $result->fetch_object(); |
| 283 | 306 | return $data; |
| 284 | 307 | } |
| 285 | 308 | |
| 286 | - public function getAllPokestops() { |
|
| 309 | + public function getAllPokestops() |
|
| 310 | + { |
|
| 287 | 311 | $req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now, (CONVERT_TZ(lure_expiration, '+00:00', '".self::$time_offset."')) AS lure_expiration_real FROM pokestop"; |
| 288 | 312 | $result = $this->mysqli->query($req); |
| 289 | 313 | $pokestops = array(); |
@@ -298,7 +322,8 @@ discard block |
||
| 298 | 322 | // Gyms |
| 299 | 323 | ///////// |
| 300 | 324 | |
| 301 | - function getTeamGuardians($team_id) { |
|
| 325 | + function getTeamGuardians($team_id) |
|
| 326 | + { |
|
| 302 | 327 | $req = "SELECT COUNT(*) AS total, guard_pokemon_id FROM gym WHERE team_id = '".$team_id ."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3"; |
| 303 | 328 | $result = $this->mysqli->query($req); |
| 304 | 329 | $datas = array(); |
@@ -308,14 +333,16 @@ discard block |
||
| 308 | 333 | return $datas; |
| 309 | 334 | } |
| 310 | 335 | |
| 311 | - function getOwnedAndPoints($team_id) { |
|
| 336 | + function getOwnedAndPoints($team_id) |
|
| 337 | + { |
|
| 312 | 338 | $req = "SELECT COUNT(DISTINCT(gym_id)) AS total, ROUND(AVG(total_cp),0) AS average_points FROM gym WHERE team_id = '".$team_id."'"; |
| 313 | 339 | $result = $this->mysqli->query($req); |
| 314 | 340 | $data = $result->fetch_object(); |
| 315 | 341 | return $data; |
| 316 | 342 | } |
| 317 | 343 | |
| 318 | - function getAllGyms() { |
|
| 344 | + function getAllGyms() |
|
| 345 | + { |
|
| 319 | 346 | $req = "SELECT gym_id, team_id, latitude, longitude, (CONVERT_TZ(last_scanned, '+00:00', '".self::$time_offset."')) AS last_scanned, (6 - slots_available) AS level FROM gym"; |
| 320 | 347 | $result = $this->mysqli->query($req); |
| 321 | 348 | $gyms = array(); |
@@ -325,7 +352,8 @@ discard block |
||
| 325 | 352 | return $gyms; |
| 326 | 353 | } |
| 327 | 354 | |
| 328 | - public function getGymData($gym_id) { |
|
| 355 | + public function getGymData($gym_id) |
|
| 356 | + { |
|
| 329 | 357 | $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team, |
| 330 | 358 | (CONVERT_TZ(gym.last_scanned, '+00:00', '".self::$time_offset."')) AS last_scanned, gym.guard_pokemon_id AS guard_pokemon_id, gym.total_cp AS total_cp, (6 - gym.slots_available) AS level |
| 331 | 359 | FROM gymdetails |
@@ -336,7 +364,8 @@ discard block |
||
| 336 | 364 | return $data; |
| 337 | 365 | } |
| 338 | 366 | |
| 339 | - public function getGymDefenders($gym_id) { |
|
| 367 | + public function getGymDefenders($gym_id) |
|
| 368 | + { |
|
| 340 | 369 | $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id |
| 341 | 370 | FROM gympokemon INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid |
| 342 | 371 | GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id |
@@ -356,7 +385,8 @@ discard block |
||
| 356 | 385 | // Gym History |
| 357 | 386 | //////////////// |
| 358 | 387 | |
| 359 | - public function getGymHistories($gym_name, $team, $page, $ranking) { |
|
| 388 | + public function getGymHistories($gym_name, $team, $page, $ranking) |
|
| 389 | + { |
|
| 360 | 390 | $where = ''; |
| 361 | 391 | if (isset($gym_name) && $gym_name != '') { |
| 362 | 392 | $where = " WHERE name LIKE '%".$gym_name."%'"; |
@@ -391,7 +421,8 @@ discard block |
||
| 391 | 421 | return $gym_history; |
| 392 | 422 | } |
| 393 | 423 | |
| 394 | - public function getGymHistoriesPokemon($gym_id) { |
|
| 424 | + public function getGymHistoriesPokemon($gym_id) |
|
| 425 | + { |
|
| 395 | 426 | $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name |
| 396 | 427 | FROM gymmember |
| 397 | 428 | LEFT JOIN gympokemon |
@@ -406,7 +437,8 @@ discard block |
||
| 406 | 437 | return $pokemons; |
| 407 | 438 | } |
| 408 | 439 | |
| 409 | - public function getHistoryForGym($page, $gym_id) { |
|
| 440 | + public function getHistoryForGym($page, $gym_id) |
|
| 441 | + { |
|
| 410 | 442 | if (isset(self::$config->system->gymhistory_hide_cp_changes) && self::$config->system->gymhistory_hide_cp_changes === true) { |
| 411 | 443 | $pageSize = 25; |
| 412 | 444 | } else { |
@@ -442,7 +474,8 @@ discard block |
||
| 442 | 474 | return array("last_page" => $last_page, "data" => $history); |
| 443 | 475 | } |
| 444 | 476 | |
| 445 | - private function getHistoryForGymPokemon($pkm_uids) { |
|
| 477 | + private function getHistoryForGymPokemon($pkm_uids) |
|
| 478 | + { |
|
| 446 | 479 | $req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name |
| 447 | 480 | FROM gympokemon |
| 448 | 481 | WHERE pokemon_uid IN ('".implode("','", $pkm_uids)."') |
@@ -460,7 +493,8 @@ discard block |
||
| 460 | 493 | // Raids |
| 461 | 494 | /////////// |
| 462 | 495 | |
| 463 | - public function getAllRaids($page) { |
|
| 496 | + public function getAllRaids($page) |
|
| 497 | + { |
|
| 464 | 498 | $limit = " LIMIT ".($page * 10).",10"; |
| 465 | 499 | $req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2, CONVERT_TZ(raid.spawn, '+00:00', '".self::$time_offset."') AS spawn, CONVERT_TZ(raid.start, '+00:00', '".self::$time_offset."') AS start, CONVERT_TZ(raid.end, '+00:00', '".self::$time_offset."') AS end, CONVERT_TZ(raid.last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned, gymdetails.name, gym.latitude, gym.longitude FROM raid |
| 466 | 500 | JOIN gymdetails ON gymdetails.gym_id = raid.gym_id |
@@ -480,7 +514,8 @@ discard block |
||
| 480 | 514 | // Trainers |
| 481 | 515 | ////////////// |
| 482 | 516 | |
| 483 | - public function getTrainers($trainer_name, $team, $page, $ranking) { |
|
| 517 | + public function getTrainers($trainer_name, $team, $page, $ranking) |
|
| 518 | + { |
|
| 484 | 519 | $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking); |
| 485 | 520 | foreach ($trainers as $trainer) { |
| 486 | 521 | |
@@ -505,7 +540,8 @@ discard block |
||
| 505 | 540 | return $trainers; |
| 506 | 541 | } |
| 507 | 542 | |
| 508 | - public function getTrainerLevelCount($team_id) { |
|
| 543 | + public function getTrainerLevelCount($team_id) |
|
| 544 | + { |
|
| 509 | 545 | $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'"; |
| 510 | 546 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 511 | 547 | $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -526,7 +562,8 @@ discard block |
||
| 526 | 562 | return $levelData; |
| 527 | 563 | } |
| 528 | 564 | |
| 529 | - private function getTrainerData($trainer_name, $team, $page, $ranking) { |
|
| 565 | + private function getTrainerData($trainer_name, $team, $page, $ranking) |
|
| 566 | + { |
|
| 530 | 567 | $where = ""; |
| 531 | 568 | |
| 532 | 569 | if (!empty(self::$config->system->trainer_blacklist)) { |
@@ -567,7 +604,8 @@ discard block |
||
| 567 | 604 | return $trainers; |
| 568 | 605 | } |
| 569 | 606 | |
| 570 | - private function getTrainerLevelRating($level) { |
|
| 607 | + private function getTrainerLevelRating($level) |
|
| 608 | + { |
|
| 571 | 609 | $req = "SELECT COUNT(1) AS rank FROM trainer WHERE level = ".$level; |
| 572 | 610 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 573 | 611 | $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -577,7 +615,8 @@ discard block |
||
| 577 | 615 | return $data; |
| 578 | 616 | } |
| 579 | 617 | |
| 580 | - private function getTrainerActivePokemon($trainer_name){ |
|
| 618 | + private function getTrainerActivePokemon($trainer_name) |
|
| 619 | + { |
|
| 581 | 620 | $req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, filtered_gymmember.gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '1' AS active |
| 582 | 621 | FROM gympokemon INNER JOIN |
| 583 | 622 | (SELECT gymmember.pokemon_uid, gymmember.gym_id, gymmember.deployment_time FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.deployment_time, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember |
@@ -592,7 +631,8 @@ discard block |
||
| 592 | 631 | return $pokemons; |
| 593 | 632 | } |
| 594 | 633 | |
| 595 | - private function getTrainerInactivePokemon($trainer_name){ |
|
| 634 | + private function getTrainerInactivePokemon($trainer_name) |
|
| 635 | + { |
|
| 596 | 636 | $req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, null AS gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '0' AS active |
| 597 | 637 | FROM gympokemon LEFT JOIN |
| 598 | 638 | (SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember |
@@ -612,7 +652,8 @@ discard block |
||
| 612 | 652 | // Cron |
| 613 | 653 | ///////// |
| 614 | 654 | |
| 615 | - public function getPokemonCountsActive() { |
|
| 655 | + public function getPokemonCountsActive() |
|
| 656 | + { |
|
| 616 | 657 | $req = "SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP() GROUP BY pokemon_id"; |
| 617 | 658 | $result = $this->mysqli->query($req); |
| 618 | 659 | $counts = array(); |
@@ -622,7 +663,8 @@ discard block |
||
| 622 | 663 | return $counts; |
| 623 | 664 | } |
| 624 | 665 | |
| 625 | - public function getPokemonCountsLastDay() { |
|
| 666 | + public function getPokemonCountsLastDay() |
|
| 667 | + { |
|
| 626 | 668 | $req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day |
| 627 | 669 | FROM pokemon |
| 628 | 670 | WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY |
@@ -636,7 +678,8 @@ discard block |
||
| 636 | 678 | return $counts; |
| 637 | 679 | } |
| 638 | 680 | |
| 639 | - public function getPokemonSinceLastUpdate($pokemon_id, $last_update) { |
|
| 681 | + public function getPokemonSinceLastUpdate($pokemon_id, $last_update) |
|
| 682 | + { |
|
| 640 | 683 | $where = "WHERE p.pokemon_id = '".$pokemon_id."' AND (UNIX_TIMESTAMP(p.disappear_time) - (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900) > '".$last_update."'"; |
| 641 | 684 | $req = "SELECT count, (UNIX_TIMESTAMP(p.disappear_time) - (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900) as last_timestamp, (CONVERT_TZ(p.disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, p.latitude, p.longitude |
| 642 | 685 | FROM pokemon p |
@@ -654,7 +697,8 @@ discard block |
||
| 654 | 697 | return $data; |
| 655 | 698 | } |
| 656 | 699 | |
| 657 | - public function getRaidsSinceLastUpdate($pokemon_id, $last_update) { |
|
| 700 | + public function getRaidsSinceLastUpdate($pokemon_id, $last_update) |
|
| 701 | + { |
|
| 658 | 702 | $where = "WHERE pokemon_id = '".$pokemon_id."' AND UNIX_TIMESTAMP(start) > '".$last_update."'"; |
| 659 | 703 | $req = "SELECT UNIX_TIMESTAMP(start) as start_timestamp, end, (CONVERT_TZ(end, '+00:00', '".self::$time_offset."')) AS end_time_real, latitude, longitude, count |
| 660 | 704 | FROM raid r |
@@ -672,14 +716,16 @@ discard block |
||
| 672 | 716 | return $data; |
| 673 | 717 | } |
| 674 | 718 | |
| 675 | - public function getCaptchaCount() { |
|
| 719 | + public function getCaptchaCount() |
|
| 720 | + { |
|
| 676 | 721 | $req = "SELECT SUM(accounts_captcha) AS total FROM mainworker"; |
| 677 | 722 | $result = $this->mysqli->query($req); |
| 678 | 723 | $data = $result->fetch_object(); |
| 679 | 724 | return $data; |
| 680 | 725 | } |
| 681 | 726 | |
| 682 | - public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) { |
|
| 727 | + public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 728 | + { |
|
| 683 | 729 | $pokemon_exclude_sql = ""; |
| 684 | 730 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 685 | 731 | $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", self::$config->system->nest_exclude_pokemon).")"; |
@@ -701,7 +747,8 @@ discard block |
||
| 701 | 747 | return $nests; |
| 702 | 748 | } |
| 703 | 749 | |
| 704 | - public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) { |
|
| 750 | + public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 751 | + { |
|
| 705 | 752 | $req = "SELECT COUNT(*) as total |
| 706 | 753 | FROM spawnpoint |
| 707 | 754 | WHERE latitude >= ".$minLatitude." AND latitude < ".$maxLatitude." AND longitude >= ".$minLongitude." AND longitude < ".$maxLongitude; |