forked from pokepark/PokemonBotMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetraids.php
More file actions
60 lines (52 loc) · 2.49 KB
/
getraids.php
File metadata and controls
60 lines (52 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
//Use same config as bot
require_once("config.php");
// Establish mysql connection.
$dbh = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4", DB_USER, DB_PASSWORD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$dbh->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING);
$sql = "
SELECT raids.*,
gyms.gym_name,
gyms.lat,
gyms.lon,
gyms.address,
gyms.ex_gym,
gyms.show_gym,
gyms.gym_note,
raids.start_time + INTERVAL TIMESTAMPDIFF(HOUR,UTC_TIMESTAMP(),NOW()) hour as start_timeNOW,
raids.end_time + INTERVAL TIMESTAMPDIFF(HOUR,UTC_TIMESTAMP(),NOW()) hour as end_timeNOW,
UNIX_TIMESTAMP(raids.end_time) AS ts_end,
UNIX_TIMESTAMP(raids.start_time) AS ts_start,
UNIX_TIMESTAMP(raids.end_time)-UNIX_TIMESTAMP(UTC_TIMESTAMP()) AS t_left,
pokemon.raid_level,
pokemon.pokedex_id,
pokemon.pokemon_name,
attendance.id AS interest,
SUM(CASE WHEN attendance.cancel=FALSE AND attendance.raid_done=FALSE THEN 1 ELSE 0 END) AS count,
SUM(CASE WHEN attendance.cancel=FALSE and attendance.raid_done=FALSE THEN attendance.extra_mystic ELSE 0 END) AS extra_mystic,
SUM(CASE WHEN attendance.cancel=FALSE and attendance.raid_done=FALSE THEN attendance.extra_valor ELSE 0 END) AS extra_valor,
SUM(CASE WHEN attendance.cancel=FALSE and attendance.raid_done=FALSE THEN attendance.extra_instinct ELSE 0 END) AS extra_instinct,
SUM(CASE WHEN attendance.cancel=FALSE and attendance.raid_done=FALSE THEN (attendance.extra_mystic+attendance.extra_valor+attendance.extra_instinct) ELSE 0 END) AS total_extras
FROM raids
LEFT JOIN pokemon ON CONCAT_WS('-',pokemon.pokedex_id,pokemon.pokemon_form)=raids.pokemon
LEFT JOIN attendance ON attendance.raid_id=raids.id
LEFT JOIN gyms ON gyms.id = raids.gym_id
WHERE raids.end_time > UTC_TIMESTAMP()
AND raids.end_time < UTC_TIMESTAMP() + INTERVAL " . MAP_RAID_END_TIME_OFFSET_HOURS . " hour
GROUP BY gyms.gym_name
ORDER BY raids.end_time ASC";
$rows = array();
try {
$result = $dbh->query($sql);
while($raid = $result->fetch(PDO::FETCH_ASSOC)) {
$rows[] = $raid;
}
}
catch (PDOException $exception) {
error_log($exception->getMessage());
$dbh = null;
exit;
}
print json_encode($rows);
$dbh = null;
?>