| @@ 395-428 (lines=34) @@ | ||
| 392 | // Gym History |
|
| 393 | //////////////// |
|
| 394 | ||
| 395 | public function getGymHistories($gym_name, $team, $page, $ranking) |
|
| 396 | { |
|
| 397 | $where = ""; |
|
| 398 | if (isset($gym_name) && $gym_name != '') { |
|
| 399 | $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
| 400 | } |
|
| 401 | if (isset($team) && $team != '') { |
|
| 402 | $where .= ($where === "" ? " WHERE" : " AND")." fs.team = ".$team; |
|
| 403 | } |
|
| 404 | switch ($ranking) { |
|
| 405 | case 1: |
|
| 406 | $order = " ORDER BY name, last_modified DESC"; |
|
| 407 | break; |
|
| 408 | case 2: |
|
| 409 | $order = " ORDER BY total_cp DESC, last_modified DESC"; |
|
| 410 | break; |
|
| 411 | default: |
|
| 412 | $order = " ORDER BY last_modified DESC, name"; |
|
| 413 | } |
|
| 414 | ||
| 415 | $limit = " LIMIT ".($page * 10).",10"; |
|
| 416 | ||
| 417 | $req = "SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, FROM_UNIXTIME(last_modified) AS last_modified |
|
| 418 | FROM forts f |
|
| 419 | 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)) |
|
| 420 | ".$where.$order.$limit; |
|
| 421 | $result = $this->mysqli->query($req); |
|
| 422 | $gym_history = array(); |
|
| 423 | while ($data = $result->fetch_object()) { |
|
| 424 | $gym_history[] = $data; |
|
| 425 | } |
|
| 426 | return $gym_history; |
|
| 427 | } |
|
| 428 | ||
| 429 | public function getGymHistoriesPokemon($gym_id) |
|
| 430 | { |
|
| 431 | $req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name |
|
| @@ 359-392 (lines=34) @@ | ||
| 356 | // Gym History |
|
| 357 | //////////////// |
|
| 358 | ||
| 359 | public function getGymHistories($gym_name, $team, $page, $ranking) { |
|
| 360 | $where = ''; |
|
| 361 | if (isset($gym_name) && $gym_name != '') { |
|
| 362 | $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
| 363 | } |
|
| 364 | if (isset($team) && $team != '') { |
|
| 365 | $where .= ($where == "" ? " WHERE" : " AND")." team_id = ".$team; |
|
| 366 | } |
|
| 367 | switch ($ranking) { |
|
| 368 | case 1: |
|
| 369 | $order = " ORDER BY name, last_modified DESC"; |
|
| 370 | break; |
|
| 371 | case 2: |
|
| 372 | $order = " ORDER BY total_cp DESC, last_modified DESC"; |
|
| 373 | break; |
|
| 374 | default: |
|
| 375 | $order = " ORDER BY last_modified DESC, name"; |
|
| 376 | } |
|
| 377 | ||
| 378 | $limit = " LIMIT ".($page * 10).",10"; |
|
| 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 |
|
| 381 | FROM gymdetails |
|
| 382 | LEFT JOIN gym |
|
| 383 | ON gymdetails.gym_id = gym.gym_id |
|
| 384 | ".$where.$order.$limit; |
|
| 385 | ||
| 386 | $result = $this->mysqli->query($req); |
|
| 387 | $gym_history = array(); |
|
| 388 | while ($data = $result->fetch_object()) { |
|
| 389 | $gym_history[] = $data; |
|
| 390 | } |
|
| 391 | return $gym_history; |
|
| 392 | } |
|
| 393 | ||
| 394 | public function getGymHistoriesPokemon($gym_id) { |
|
| 395 | $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name |
|
| @@ 380-413 (lines=34) @@ | ||
| 377 | // Gym History |
|
| 378 | //////////////// |
|
| 379 | ||
| 380 | public function getGymHistories($gym_name, $team, $page, $ranking) |
|
| 381 | { |
|
| 382 | $where = ""; |
|
| 383 | if (isset($gym_name) && $gym_name != '') { |
|
| 384 | $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
| 385 | } |
|
| 386 | if (isset($team) && $team != '') { |
|
| 387 | $where .= ($where === "" ? " WHERE" : " AND")." fs.team = ".$team; |
|
| 388 | } |
|
| 389 | switch ($ranking) { |
|
| 390 | case 1: |
|
| 391 | $order = " ORDER BY name, last_modified DESC"; |
|
| 392 | break; |
|
| 393 | case 2: |
|
| 394 | $order = " ORDER BY total_cp DESC, last_modified DESC"; |
|
| 395 | break; |
|
| 396 | default: |
|
| 397 | $order = " ORDER BY last_modified DESC, name"; |
|
| 398 | } |
|
| 399 | ||
| 400 | $limit = " LIMIT 10 OFFSET ".($page * 10); |
|
| 401 | ||
| 402 | $req = "SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, TO_TIMESTAMP(last_modified) AS last_modified |
|
| 403 | FROM forts f |
|
| 404 | 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)) |
|
| 405 | ".$where.$order.$limit; |
|
| 406 | ||
| 407 | $result = $this->mysqli->query($req); |
|
| 408 | $gym_history = array(); |
|
| 409 | while ($data = $result->fetch_object()) { |
|
| 410 | $gym_history[] = $data; |
|
| 411 | } |
|
| 412 | return $gym_history; |
|
| 413 | } |
|
| 414 | ||
| 415 | public function getGymHistoriesPokemon($gym_id) |
|
| 416 | { |
|