forked from Ninjasoturi/PokemonRaidBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexreport.php
100 lines (87 loc) · 2.48 KB
/
exreport.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
// Write to log.
debug_log('EXREPORT()');
// For debug.
//debug_log($update);
//debug_log($data);
// Check access.
bot_access_check($update, 'ex-report');
// Init empty keys array.
$keys = [];
$keys[0]['text'] = 'Gym Name';
$keys[0]['callback_data'] = 0;
$keys[1]['text'] = 'Total Raided';
$keys[1]['callback_data'] = 0;
$keys[2]['text'] = 'Total Raids';
$keys[2]['callback_data'] = 0;
$keys[3]['text'] = 'Players Needed to Trigger';
$keys[3]['callback_data'] = 0;
$i = 4;
try {
$query = '
SELECT
g.gym_name ,
SUM(
CASE
WHEN a.cancel = FALSE
OR a.raid_done = FALSE THEN
(
a.extra_mystic + a.extra_valor + a.extra_instinct + 1
)
ELSE
0
END
) AS Total_attended ,
count(DISTINCT r.id) AS Total_raids ,
ROUND(
(
SUM(
CASE
WHEN a.cancel = FALSE
OR a.raid_done = FALSE THEN
(
a.extra_mystic + a.extra_valor + a.extra_instinct + 1
)
ELSE
0
END
) / count(DISTINCT r.id) * 2
) + 3
) AS players_needed_to_trigger
FROM
raids r
LEFT JOIN attendance a ON a.raid_id = r.id
LEFT JOIN gyms g ON g.id = r.gym_id
WHERE
g.ex_gym = 1
AND WEEK(r.start_time) BETWEEN WEEK(now()) - 2
AND WEEK(now())
GROUP BY
g.gym_name
';
$statement = $dbh->prepare( $query );
$statement->execute();
while ($row = $statement->fetch()) {
$keys[$i]['text'] = $row['gym_name'];
$keys[$i]['callback_data'] = 0;
$keys[$i+1]['text'] = $row['Total_attended'];
$keys[$i+1]['callback_data'] = 0;
$keys[$i+2]['text'] = $row['Total_raids'];
$keys[$i+2]['callback_data'] = 0;
$keys[$i+3]['text'] = $row['players_needed_to_trigger'];
$keys[$i+3]['callback_data'] = 0;
$i = $i+4;
}
}
catch (PDOException $exception) {
error_log($exception->getMessage());
$dbh = null;
exit;
}
// Get the inline key array.
$keys = inline_key_array($keys, 4);
// Set message.
$msg = '<b>EX Raid Report</b>';
// Send message.
send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]);
?>