forked from pokepark/PokemonRaidBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_remote_users_count.php
49 lines (43 loc) · 1.48 KB
/
get_remote_users_count.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
<?php
/**
* Get current remote users count.
* @param $raid_id
* @param $user_id
* @param $attend_time
* @return int
*/
function get_remote_users_count($raid_id, $user_id, $attend_time = false)
{
global $config;
if(!$attend_time) {
// If attend time is not given, get the one user has already voted for from database
$att_sql = "(
SELECT attend_time
FROM attendance
WHERE raid_id = {$raid_id}
AND user_id = {$user_id}
LIMIT 1
)";
}else {
// Use given attend time (needed when voting for new time)
$att_sql = "'{$attend_time}'";
}
// Check if max remote users limit is already reached!
// Ignore max limit if attend time is 'Anytime'
$rs = my_query(
"
SELECT IF(attend_time = '" . ANYTIME . "', 0, sum(1 + extra_in_person)) AS remote_users
FROM (SELECT DISTINCT user_id, extra_in_person, attend_time FROM attendance WHERE remote = 1 AND cancel = 0 AND raid_done = 0) as T
WHERE attend_time = {$att_sql}
GROUP BY attend_time
"
);
// Get the answer.
$answer = $rs->fetch();
$remote_users = empty($answer) ? 0 : $answer['remote_users'];
// Write to log.
debug_log($remote_users, 'Remote participants so far:');
debug_log($config->RAID_REMOTEPASS_USERS_LIMIT, 'Maximum remote participants:');
return $remote_users;
}
?>