Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like QueryManagerMysqlRocketmap often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use QueryManagerMysqlRocketmap, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 3 | final class QueryManagerMysqlRocketmap extends QueryManagerMysql { |
||
|
|
|||
| 4 | |||
| 5 | public function __construct() { |
||
| 8 | |||
| 9 | public function __destruct() { |
||
| 12 | |||
| 13 | /////////// |
||
| 14 | // Tester |
||
| 15 | /////////// |
||
| 16 | |||
| 17 | View Code Duplication | function testTotalPokemon() { |
|
| 32 | |||
| 33 | View Code Duplication | function testTotalGyms() { |
|
| 48 | |||
| 49 | View Code Duplication | function testTotalPokestops() { |
|
| 64 | |||
| 65 | |||
| 66 | ///////////// |
||
| 67 | // Homepage |
||
| 68 | ///////////// |
||
| 69 | |||
| 70 | function getTotalPokemon() { |
||
| 76 | |||
| 77 | function getTotalLures() { |
||
| 83 | |||
| 84 | function getTotalGyms() { |
||
| 90 | |||
| 91 | function getTotalRaids() { |
||
| 97 | |||
| 98 | function getTotalGymsForTeam($team_id) { |
||
| 104 | |||
| 105 | function getRecentAll() { |
||
| 120 | |||
| 121 | function getRecentMythic($mythic_pokemons) { |
||
| 137 | |||
| 138 | /////////////////// |
||
| 139 | // Single Pokemon |
||
| 140 | /////////////////// |
||
| 141 | |||
| 142 | View Code Duplication | function getGymsProtectedByPokemon($pokemon_id) { |
|
| 148 | |||
| 149 | View Code Duplication | function getPokemonLastSeen($pokemon_id) { |
|
| 159 | |||
| 160 | View Code Duplication | function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) { |
|
| 161 | $req = "SELECT (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS distime, pokemon_id, disappear_time, latitude, longitude, |
||
| 162 | cp, individual_attack, individual_defense, individual_stamina, |
||
| 163 | ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, move_1, move_2, form |
||
| 164 | FROM pokemon |
||
| 165 | WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
||
| 166 | ORDER BY $top_order_by $top_direction, disappear_time DESC |
||
| 167 | LIMIT 0,50"; |
||
| 168 | |||
| 169 | $result = $this->mysqli->query($req); |
||
| 170 | $top = array(); |
||
| 171 | while ($data = $result->fetch_object()) { |
||
| 172 | $top[] = $data; |
||
| 173 | } |
||
| 174 | return $top; |
||
| 175 | } |
||
| 176 | |||
| 177 | View Code Duplication | function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
|
| 178 | $trainer_blacklist = ""; |
||
| 179 | if (!empty(self::$config->system->trainer_blacklist)) { |
||
| 180 | $trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
||
| 181 | } |
||
| 182 | |||
| 183 | $req = "SELECT trainer_name, ROUND(SUM(100*(iv_attack+iv_defense+iv_stamina)/45),1) AS IV, move_1, move_2, cp, |
||
| 184 | DATE_FORMAT(last_seen, '%Y-%m-%d') AS lasttime, last_seen |
||
| 185 | FROM gympokemon |
||
| 186 | WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist." |
||
| 187 | ORDER BY $best_order_by $best_direction, trainer_name ASC |
||
| 188 | LIMIT 0,50"; |
||
| 189 | |||
| 190 | $result = $this->mysqli->query($req); |
||
| 191 | $toptrainer = array(); |
||
| 192 | while ($data = $result->fetch_object()) { |
||
| 193 | $toptrainer[] = $data; |
||
| 194 | } |
||
| 195 | return $toptrainer; |
||
| 196 | } |
||
| 197 | |||
| 198 | View Code Duplication | public function getPokemonHeatmap($pokemon_id, $start, $end) { |
|
| 199 | $where = " WHERE pokemon_id = ".$pokemon_id." " |
||
| 200 | . "AND disappear_time BETWEEN '".$start."' AND '".$end."'"; |
||
| 201 | $req = "SELECT latitude, longitude FROM pokemon".$where." ORDER BY disappear_time DESC LIMIT 10000"; |
||
| 202 | $result = $this->mysqli->query($req); |
||
| 203 | $points = array(); |
||
| 204 | while ($data = $result->fetch_object()) { |
||
| 205 | $points[] = $data; |
||
| 206 | } |
||
| 207 | return $points; |
||
| 208 | } |
||
| 209 | |||
| 210 | View Code Duplication | public function getPokemonGraph($pokemon_id) { |
|
| 211 | $req = "SELECT COUNT(*) AS total, |
||
| 212 | HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour |
||
| 213 | FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered |
||
| 214 | GROUP BY disappear_hour |
||
| 215 | ORDER BY disappear_hour"; |
||
| 216 | $result = $this->mysqli->query($req); |
||
| 217 | $array = array_fill(0, 24, 0); |
||
| 218 | while ($result && $data = $result->fetch_object()) { |
||
| 219 | $array[$data->disappear_hour] = $data->total; |
||
| 220 | } |
||
| 221 | // shift array because AM/PM starts at 1AM not 0:00 |
||
| 222 | $array[] = $array[0]; |
||
| 223 | array_shift($array); |
||
| 224 | return $array; |
||
| 225 | } |
||
| 226 | |||
| 227 | View Code Duplication | public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
|
| 228 | $inmap_pkms_filter = ""; |
||
| 229 | $where = " WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = ".$pokemon_id; |
||
| 230 | |||
| 231 | $reqTestIv = "SELECT MAX(individual_attack) AS iv FROM pokemon ".$where; |
||
| 232 | $resultTestIv = $this->mysqli->query($reqTestIv); |
||
| 233 | $testIv = $resultTestIv->fetch_object(); |
||
| 234 | if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) { |
||
| 235 | foreach ($_POST['inmap_pokemons'] as $inmap) { |
||
| 236 | $inmap_pkms_filter .= "'".$inmap."',"; |
||
| 237 | } |
||
| 238 | $inmap_pkms_filter = rtrim($inmap_pkms_filter, ","); |
||
| 239 | $where .= " AND encounter_id NOT IN (".$inmap_pkms_filter.") "; |
||
| 240 | } |
||
| 241 | if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) { |
||
| 242 | $where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= (".$ivMin.") "; |
||
| 243 | } |
||
| 244 | if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) { |
||
| 245 | $where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= (".$ivMax.") "; |
||
| 246 | } |
||
| 247 | $req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time, |
||
| 248 | (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, |
||
| 249 | individual_attack, individual_defense, individual_stamina, move_1, move_2 |
||
| 250 | FROM pokemon ".$where." |
||
| 251 | ORDER BY disappear_time DESC |
||
| 252 | LIMIT 5000"; |
||
| 253 | $result = $this->mysqli->query($req); |
||
| 254 | $spawns = array(); |
||
| 255 | while ($data = $result->fetch_object()) { |
||
| 256 | $spawns[] = $data; |
||
| 257 | } |
||
| 258 | return $spawns; |
||
| 259 | } |
||
| 260 | |||
| 261 | public function getPokemonSliderMinMax() { |
||
| 262 | $req = "SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon"; |
||
| 263 | $result = $this->mysqli->query($req); |
||
| 264 | $data = $result->fetch_object(); |
||
| 265 | return $data; |
||
| 266 | } |
||
| 267 | |||
| 268 | public function getMapsCoords() { |
||
| 269 | $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 | $result = $this->mysqli->query($req); |
||
| 271 | $data = $result->fetch_object(); |
||
| 272 | return $data; |
||
| 273 | } |
||
| 274 | |||
| 275 | |||
| 276 | /////////////// |
||
| 277 | // Pokestops |
||
| 278 | ////////////// |
||
| 279 | |||
| 280 | function getTotalPokestops() { |
||
| 281 | $req = "SELECT COUNT(*) as total FROM pokestop"; |
||
| 282 | $result = $this->mysqli->query($req); |
||
| 283 | $data = $result->fetch_object(); |
||
| 284 | return $data; |
||
| 285 | } |
||
| 286 | |||
| 287 | public function getAllPokestops() { |
||
| 288 | $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 | $result = $this->mysqli->query($req); |
||
| 290 | $pokestops = array(); |
||
| 291 | while ($data = $result->fetch_object()) { |
||
| 292 | $pokestops[] = $data; |
||
| 293 | } |
||
| 294 | return $pokestops; |
||
| 295 | } |
||
| 296 | |||
| 297 | |||
| 298 | ///////// |
||
| 299 | // Gyms |
||
| 300 | ///////// |
||
| 301 | |||
| 302 | function getTeamGuardians($team_id) { |
||
| 303 | $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 | $result = $this->mysqli->query($req); |
||
| 305 | $datas = array(); |
||
| 306 | while ($data = $result->fetch_object()) { |
||
| 307 | $datas[] = $data; |
||
| 308 | } |
||
| 309 | return $datas; |
||
| 310 | } |
||
| 311 | |||
| 312 | function getOwnedAndPoints($team_id) { |
||
| 313 | $req = "SELECT COUNT(DISTINCT(gym_id)) AS total, ROUND(AVG(total_cp),0) AS average_points FROM gym WHERE team_id = '".$team_id."'"; |
||
| 314 | $result = $this->mysqli->query($req); |
||
| 315 | $data = $result->fetch_object(); |
||
| 316 | return $data; |
||
| 317 | } |
||
| 318 | |||
| 319 | function getAllGyms() { |
||
| 320 | $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 | $result = $this->mysqli->query($req); |
||
| 322 | $gyms = array(); |
||
| 323 | while ($data = $result->fetch_object()) { |
||
| 324 | $gyms[] = $data; |
||
| 325 | } |
||
| 326 | return $gyms; |
||
| 327 | } |
||
| 328 | |||
| 329 | View Code Duplication | public function getGymData($gym_id) { |
|
| 330 | $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team, |
||
| 331 | (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 | FROM gymdetails |
||
| 333 | LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id |
||
| 334 | WHERE gym.gym_id='".$gym_id."'"; |
||
| 335 | $result = $this->mysqli->query($req); |
||
| 336 | $data = $result->fetch_object(); |
||
| 337 | return $data; |
||
| 338 | } |
||
| 339 | |||
| 340 | public function getGymDefenders($gym_id) { |
||
| 341 | $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id |
||
| 342 | FROM gympokemon INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid |
||
| 343 | GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id |
||
| 344 | HAVING gymmember.gym_id='".$gym_id."' |
||
| 345 | ORDER BY cp DESC"; |
||
| 346 | $result = $this->mysqli->query($req); |
||
| 347 | $defenders = array(); |
||
| 348 | while ($data = $result->fetch_object()) { |
||
| 349 | $defenders[] = $data; |
||
| 350 | } |
||
| 351 | return $defenders; |
||
| 352 | } |
||
| 353 | |||
| 354 | |||
| 355 | /////////// |
||
| 356 | // Raids |
||
| 357 | /////////// |
||
| 358 | |||
| 359 | public function getAllRaids($page) { |
||
| 360 | $limit = " LIMIT ".($page * 10).",10"; |
||
| 361 | $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 | JOIN gymdetails ON gymdetails.gym_id = raid.gym_id |
||
| 363 | JOIN gym ON gym.gym_id = raid.gym_id |
||
| 364 | WHERE raid.end > UTC_TIMESTAMP() |
||
| 365 | ORDER BY raid.level DESC, raid.start".$limit; |
||
| 366 | $result = $this->mysqli->query($req); |
||
| 367 | $raids = array(); |
||
| 368 | while ($data = $result->fetch_object()) { |
||
| 369 | $raids[] = $data; |
||
| 370 | } |
||
| 371 | return $raids; |
||
| 372 | } |
||
| 373 | |||
| 374 | |||
| 375 | ////////////// |
||
| 376 | // Trainers |
||
| 377 | ////////////// |
||
| 378 | |||
| 379 | public function getTrainers($trainer_name, $team, $page, $ranking) { |
||
| 380 | $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking); |
||
| 381 | foreach ($trainers as $trainer) { |
||
| 382 | |||
| 383 | $trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank; |
||
| 384 | |||
| 385 | $active_gyms = 0; |
||
| 386 | $pkmCount = 0; |
||
| 387 | |||
| 388 | $trainer->pokemons = array(); |
||
| 389 | $active_pokemon = $this->getTrainerActivePokemon($trainer->name); |
||
| 390 | foreach ($active_pokemon as $pokemon) { |
||
| 391 | $active_gyms++; |
||
| 392 | $trainer->pokemons[$pkmCount++] = $pokemon; |
||
| 393 | } |
||
| 394 | |||
| 395 | $inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name); |
||
| 396 | foreach ($inactive_pokemon as $pokemon) { |
||
| 397 | $trainer->pokemons[$pkmCount++] = $pokemon; |
||
| 398 | } |
||
| 399 | $trainer->gyms = "".$active_gyms; |
||
| 400 | } |
||
| 401 | return $trainers; |
||
| 402 | } |
||
| 403 | |||
| 404 | public function getTrainerLevelCount($team_id) { |
||
| 405 | $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'"; |
||
| 406 | if (!empty(self::$config->system->trainer_blacklist)) { |
||
| 407 | $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
||
| 408 | } |
||
| 409 | $req .= " GROUP BY level"; |
||
| 410 | $result = $this->mysqli->query($req); |
||
| 411 | $levelData = array(); |
||
| 412 | while ($data = $result->fetch_object()) { |
||
| 413 | $levelData[$data['level']] = $data['count']; |
||
| 414 | } |
||
| 415 | for ($i = 5; $i <= 40; $i++) { |
||
| 416 | if (!isset($levelData[$i])) { |
||
| 417 | $levelData[$i] = 0; |
||
| 418 | } |
||
| 419 | } |
||
| 420 | # sort array again |
||
| 421 | ksort($levelData); |
||
| 422 | return $levelData; |
||
| 423 | } |
||
| 424 | |||
| 425 | private function getTrainerData($trainer_name, $team, $page, $ranking) { |
||
| 426 | $where = ""; |
||
| 427 | |||
| 428 | if (!empty(self::$config->system->trainer_blacklist)) { |
||
| 429 | $where .= ($where == "" ? " HAVING" : " AND")." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
||
| 430 | } |
||
| 431 | if ($trainer_name != "") { |
||
| 432 | $where = " HAVING name LIKE '%".$trainer_name."%'"; |
||
| 433 | } |
||
| 434 | if ($team != 0) { |
||
| 435 | $where .= ($where == "" ? " HAVING" : " AND")." team = ".$team; |
||
| 436 | } |
||
| 437 | switch ($ranking) { |
||
| 438 | case 1: |
||
| 439 | $order = " ORDER BY active DESC, level DESC"; |
||
| 440 | break; |
||
| 441 | case 2: |
||
| 442 | $order = " ORDER BY maxCp DESC, level DESC"; |
||
| 443 | break; |
||
| 444 | default: |
||
| 445 | $order = " ORDER BY level DESC, active DESC"; |
||
| 446 | } |
||
| 447 | $order .= ", last_seen DESC, name "; |
||
| 448 | $limit = " LIMIT ".($page * 10).",10 "; |
||
| 449 | $req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp |
||
| 450 | FROM trainer |
||
| 451 | LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned |
||
| 452 | FROM gympokemon |
||
| 453 | 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 |
||
| 454 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name |
||
| 455 | GROUP BY trainer.name " . $where . $order . $limit; |
||
| 456 | |||
| 457 | $result = $this->mysqli->query($req); |
||
| 458 | $trainers = array(); |
||
| 459 | while ($data = $result->fetch_object()) { |
||
| 460 | $data->last_seen = date("Y-m-d", strtotime($data->last_seen)); |
||
| 461 | $trainers[$data->name] = $data; |
||
| 462 | } |
||
| 463 | return $trainers; |
||
| 464 | } |
||
| 465 | |||
| 466 | private function getTrainerLevelRating($level) { |
||
| 467 | $req = "SELECT COUNT(1) AS rank FROM trainer WHERE level = ".$level; |
||
| 468 | if (!empty(self::$config->system->trainer_blacklist)) { |
||
| 469 | $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
||
| 470 | } |
||
| 471 | $result = $this->mysqli->query($req); |
||
| 472 | $data = $result->fetch_object(); |
||
| 473 | return $data; |
||
| 474 | } |
||
| 475 | |||
| 476 | View Code Duplication | private function getTrainerActivePokemon($trainer_name){ |
|
| 477 | $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 | FROM gympokemon INNER JOIN |
||
| 479 | (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 |
||
| 480 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
||
| 481 | WHERE gympokemon.trainer_name='".$trainer_name."' |
||
| 482 | ORDER BY gympokemon.cp DESC)"; |
||
| 483 | $result = $this->mysqli->query($req); |
||
| 484 | $pokemons = array(); |
||
| 485 | while ($data = $result->fetch_object()) { |
||
| 486 | $pokemons[] = $data; |
||
| 487 | } |
||
| 488 | return $pokemons; |
||
| 489 | } |
||
| 490 | |||
| 491 | View Code Duplication | private function getTrainerInactivePokemon($trainer_name){ |
|
| 492 | $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 | FROM gympokemon LEFT JOIN |
||
| 494 | (SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember |
||
| 495 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
||
| 496 | WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."' |
||
| 497 | ORDER BY gympokemon.cp DESC)"; |
||
| 498 | $result = $this->mysqli->query($req); |
||
| 499 | $pokemons = array(); |
||
| 500 | while ($data = $result->fetch_object()) { |
||
| 501 | $pokemons[] = $data; |
||
| 502 | } |
||
| 503 | return $pokemons; |
||
| 504 | } |
||
| 505 | |||
| 506 | |||
| 507 | ///////// |
||
| 508 | // Cron |
||
| 509 | ///////// |
||
| 510 | |||
| 511 | public function getPokemonCountsActive() { |
||
| 512 | $req = "SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP() GROUP BY pokemon_id"; |
||
| 513 | $result = $this->mysqli->query($req); |
||
| 514 | $counts = array(); |
||
| 515 | while ($data = $result->fetch_object()) { |
||
| 516 | $counts[$data->pokemon_id] = $data->total; |
||
| 517 | } |
||
| 518 | return $counts; |
||
| 519 | } |
||
| 520 | |||
| 521 | public function getPokemonCountsLastDay() { |
||
| 522 | $req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day |
||
| 523 | FROM pokemon |
||
| 524 | WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY |
||
| 525 | GROUP BY pokemon_id |
||
| 526 | ORDER BY pokemon_id ASC"; |
||
| 527 | $result = $this->mysqli->query($req); |
||
| 528 | $counts = array(); |
||
| 529 | while ($data = $result->fetch_object()) { |
||
| 530 | $counts[$data->pokemon_id] = $data->spawns_last_day; |
||
| 531 | } |
||
| 532 | return $counts; |
||
| 533 | } |
||
| 534 | |||
| 535 | View Code Duplication | public function getPokemonSinceLastUpdate($pokemon_id, $last_update) { |
|
| 536 | $where = "WHERE p.pokemon_id = '".$pokemon_id."' AND (UNIX_TIMESTAMP(p.disappear_time) - (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900) > '".$last_update."'"; |
||
| 537 | $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 | FROM pokemon p |
||
| 539 | JOIN spawnpoint s ON p.spawnpoint_id = s.id |
||
| 540 | JOIN (SELECT count(*) as count |
||
| 541 | FROM pokemon p |
||
| 542 | JOIN spawnpoint s ON p.spawnpoint_id = s.id |
||
| 543 | " . $where." |
||
| 544 | ) x |
||
| 545 | " . $where . " |
||
| 546 | ORDER BY last_timestamp DESC |
||
| 547 | LIMIT 0,1"; |
||
| 548 | $result = $this->mysqli->query($req); |
||
| 549 | $data = $result->fetch_object(); |
||
| 550 | return $data; |
||
| 551 | } |
||
| 552 | |||
| 553 | View Code Duplication | public function getRaidsSinceLastUpdate($pokemon_id, $last_update) { |
|
| 570 | |||
| 571 | public function getCaptchaCount() { |
||
| 577 | |||
| 578 | View Code Duplication | public function getNestData() { |
|
| 598 | |||
| 599 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.