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