| @@ 430-467 (lines=38) @@ | ||
| 427 | return $pokemons; |
|
| 428 | } |
|
| 429 | ||
| 430 | public function getHistoryForGym($page, $gym_id) |
|
| 431 | { |
|
| 432 | if (isset(self::$config->system->gymhistory_hide_cp_changes) && self::$config->system->gymhistory_hide_cp_changes === true) { |
|
| 433 | $pageSize = 25; |
|
| 434 | } else { |
|
| 435 | $pageSize = 10; |
|
| 436 | } |
|
| 437 | $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 |
|
| 438 | FROM fort_sightings fs |
|
| 439 | LEFT JOIN forts f ON f.id = fs.fort_id |
|
| 440 | WHERE f.id = '". $gym_id ."' |
|
| 441 | ORDER BY fs.last_modified DESC |
|
| 442 | LIMIT ".($pageSize+1)." OFFSET ".($page * $pageSize); |
|
| 443 | $result = $this->mysqli->query($req); |
|
| 444 | $history = array(); |
|
| 445 | $count = 0; |
|
| 446 | while ($data = $result->fetch_object()) { |
|
| 447 | $count++; |
|
| 448 | if ($data->total_cp == 0) { |
|
| 449 | $data->pokemon = array(); |
|
| 450 | $data->pokemon_count = 0; |
|
| 451 | $data->pokemon_uids = ""; |
|
| 452 | } else { |
|
| 453 | $data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real); |
|
| 454 | $data->pokemon_count = count($data->pokemon); |
|
| 455 | $data->pokemon_uids = implode(",", array_keys($data->pokemon)); |
|
| 456 | } |
|
| 457 | if ($data->total_cp === 0 || $data->pokemon_count !== 0) { |
|
| 458 | $history[] = $data; |
|
| 459 | } |
|
| 460 | } |
|
| 461 | if ($count !== ($pageSize + 1)) { |
|
| 462 | $last_page = true; |
|
| 463 | } else { |
|
| 464 | $last_page = false; |
|
| 465 | } |
|
| 466 | return array("last_page" => $last_page, "data" => $history); |
|
| 467 | } |
|
| 468 | ||
| 469 | private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
| 470 | { |
|
| @@ 444-481 (lines=38) @@ | ||
| 441 | return $pokemons; |
|
| 442 | } |
|
| 443 | ||
| 444 | public function getHistoryForGym($page, $gym_id) |
|
| 445 | { |
|
| 446 | if (isset(self::$config->system->gymhistory_hide_cp_changes) && self::$config->system->gymhistory_hide_cp_changes === true) { |
|
| 447 | $pageSize = 25; |
|
| 448 | } else { |
|
| 449 | $pageSize = 10; |
|
| 450 | } |
|
| 451 | $req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, FROM_UNIXTIME(fs.last_modified) as last_modified, last_modified as last_modified_real |
|
| 452 | FROM fort_sightings fs |
|
| 453 | LEFT JOIN forts f ON f.id = fs.fort_id |
|
| 454 | WHERE f.id = '". $gym_id ."' |
|
| 455 | ORDER BY fs.last_modified DESC |
|
| 456 | LIMIT ".($page * $pageSize).",".($pageSize+1); |
|
| 457 | $result = $this->mysqli->query($req); |
|
| 458 | $history = array(); |
|
| 459 | $count = 0; |
|
| 460 | while ($data = $result->fetch_object()) { |
|
| 461 | $count++; |
|
| 462 | if ($data->total_cp == 0) { |
|
| 463 | $data->pokemon = array(); |
|
| 464 | $data->pokemon_count = 0; |
|
| 465 | $data->pokemon_uids = ""; |
|
| 466 | } else { |
|
| 467 | $data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real); |
|
| 468 | $data->pokemon_count = count($data->pokemon); |
|
| 469 | $data->pokemon_uids = implode(",", array_keys($data->pokemon)); |
|
| 470 | } |
|
| 471 | if ($data->total_cp === 0 || $data->pokemon_count !== 0) { |
|
| 472 | $history[] = $data; |
|
| 473 | } |
|
| 474 | } |
|
| 475 | if ($count !== ($pageSize + 1)) { |
|
| 476 | $last_page = true; |
|
| 477 | } else { |
|
| 478 | $last_page = false; |
|
| 479 | } |
|
| 480 | return array("last_page" => $last_page, "data" => $history); |
|
| 481 | } |
|
| 482 | ||
| 483 | private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
| 484 | { |
|