forked from pokepark/PokemonRaidBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraid_edit_gyms_first_letter_keys.php
121 lines (112 loc) · 3.67 KB
/
raid_edit_gyms_first_letter_keys.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Raid gym first letter selection
* @param $action
* @param $hidden
* @return array
*/
function raid_edit_gyms_first_letter_keys($action = 'raid_by_gym', $hidden = false)
{
global $config;
// Special/Custom gym letters?
$case = '';
if(!empty($config->RAID_CUSTOM_GYM_LETTERS)) {
// Explode special letters.
$special_keys = explode(',', $config->RAID_CUSTOM_GYM_LETTERS);
foreach($special_keys as $id => $letter)
{
$letter = trim($letter);
debug_log($letter, 'Special gym letter:');
// Fix chinese chars, prior: $length = strlen($letter);
$length = strlen(utf8_decode($letter));
$case .= SP . "WHEN UPPER(LEFT(gym_name, " . $length . ")) = '" . $letter . "' THEN UPPER(LEFT(gym_name, " . $length . "))" . SP;
}
}
// Show hidden gyms?
if($hidden == true) {
$show_gym = 0;
} else {
$show_gym = 1;
}
// Case or not?
if(!empty($case)) {
// List or other action?
if($action == 'list_by_gym') {
// Get gyms with active raids only from database
$rs = my_query(
"
SELECT CASE $case
ELSE UPPER(LEFT(gym_name, 1))
END AS first_letter
FROM raids
LEFT JOIN gyms
ON raids.gym_id = gyms.id
WHERE end_time>UTC_TIMESTAMP()
AND show_gym = {$show_gym}
GROUP BY 1
ORDER BY gym_name
"
);
} else {
// Get gyms from database
$rs = my_query(
"
SELECT CASE $case
ELSE UPPER(LEFT(gym_name, 1))
END AS first_letter
FROM gyms
WHERE show_gym = {$show_gym}
GROUP BY 1
ORDER BY gym_name
"
);
}
} else {
// List or other action?
if($action == 'list_by_gym') {
// Get gyms with active raids only from database
// Get gyms from database
$rs = my_query(
"
SELECT DISTINCT UPPER(SUBSTR(gym_name, 1, 1)) AS first_letter
FROM raids
LEFT JOIN gyms
ON raids.gym_id = gyms.id
WHERE end_time>UTC_TIMESTAMP()
AND show_gym = {$show_gym}
ORDER BY 1
"
);
} else {
// Get gyms from database
$rs = my_query(
"
SELECT DISTINCT UPPER(SUBSTR(gym_name, 1, 1)) AS first_letter
FROM gyms
WHERE show_gym = {$show_gym}
ORDER BY 1
"
);
}
}
// Init empty keys array.
$keys = [];
while ($gym = $rs->fetch()) {
// Add first letter to keys array
$keys[] = array(
'text' => $gym['first_letter'],
'callback_data' => $show_gym . ':' . $action . ':' . $gym['first_letter']
);
}
// Get the inline key array.
$keys = inline_key_array($keys, 4);
// Add back navigation key.
if($hidden == false) {
$nav_keys = [];
$nav_keys[] = universal_inner_key($keys, '0', 'exit', '0', getTranslation('abort'));
// Get the inline key array.
$keys[] = $nav_keys;
}
return $keys;
}
?>