Skip to content

Commit

Permalink
Revert "Added new gym area feature"
Browse files Browse the repository at this point in the history
This reverts commit 139369b.
  • Loading branch information
jinnatar committed Aug 29, 2021
1 parent b0f142e commit 91674f1
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 217 deletions.
8 changes: 3 additions & 5 deletions commands/deletegym.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
// Check access.
bot_access_check($update, 'gym-delete');

// Set keys.
$keys_and_gymarea = raid_edit_gyms_first_letter_keys('gym_delete', false, false, 'gym_letter');
$keys = $keys_and_gymarea['keys'];

// Set message.
$msg = '<b>' . getTranslation('gym_delete') . SP . '' . SP . getTranslation('select_gym_first_letter') . '</b>';
$msg.= (($keys_and_gymarea['gymarea_name'] != '') ? CR . CR . getTranslation('current_gymarea') . ': ' . $keys_and_gymarea['gymarea_name'] : '');

// Set keys.
$keys = raid_edit_gyms_first_letter_keys('gym_delete');

// Add key for hidden gyms.
$h_keys = [];
Expand Down
10 changes: 4 additions & 6 deletions commands/gym.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
// Check access.
bot_access_check($update, 'gym-details');

// Set keys.
$keys_and_gymarea = raid_edit_gyms_first_letter_keys('gym_details', false, false, 'gym_letter');
$keys = $keys_and_gymarea['keys'];

// Set message.
$msg = '<b>' . getTranslation('show_gym_details') . CR . CR . getTranslation('select_gym_first_letter') . '</b>';
$msg.= (($keys_and_gymarea['gymarea_name'] != '') ? CR . CR . getTranslation('current_gymarea') . ': ' . $keys_and_gymarea['gymarea_name'] : '');
$msg = '<b>' . getTranslation('show_gym_details') . SP . '' . SP . getTranslation('select_gym_first_letter') . '</b>';

// Set keys.
$keys = raid_edit_gyms_first_letter_keys('gym_details');

// Add key for hidden gyms.
$h_keys = [];
Expand Down
8 changes: 3 additions & 5 deletions commands/listall.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
// Check access.
if(!isset($skip_access) or $skip_access != true) bot_access_check($update, 'list');

// Set keys.
$keys_and_gymarea = raid_edit_gyms_first_letter_keys('list_by_gym', false, false, 'listall');
$keys = $keys_and_gymarea['keys'];

// Set message.
$msg = '<b>' . getTranslation('list_all_active_raids') . '</b>' . CR;
$msg.= (($keys_and_gymarea['gymarea_name'] != '') ? getTranslation('current_gymarea') . ': ' . $keys_and_gymarea['gymarea_name'] . CR: '');
$msg .= '<b>' . getTranslation('select_gym_first_letter') . '</b>' . CR;

// Set keys.
$keys = raid_edit_gyms_first_letter_keys('list_by_gym');

// Send message.
send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true], 'disable_web_page_preview' => 'true']);

Expand Down
7 changes: 2 additions & 5 deletions commands/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@

// Get the keys if nothing was returned.
if(!$keys) {
$keys_and_gymarea = raid_edit_gyms_first_letter_keys();
$keys = $keys_and_gymarea['keys'];
$keys = raid_edit_gyms_first_letter_keys();
}

// No keys found.
Expand All @@ -68,9 +67,7 @@
}

// Set message.
$msg = '<b>' . getTranslation('select_gym_first_letter') . '</b>';
$msg.= (($keys_and_gymarea['gymarea_name'] != '') ? CR . CR . getTranslation('current_gymarea') . ': ' . $keys_and_gymarea['gymarea_name'] : '');
$msg.= ($config->RAID_VIA_LOCATION ? (CR . CR . getTranslation('send_location')) : '');
$msg = '<b>' . getTranslation('select_gym_first_letter') . '</b>' . ($config->RAID_VIA_LOCATION ? (CR2 . CR . getTranslation('send_location')) : '');

// Send message.
send_message($update['message']['chat']['id'], $msg, $keys, ['reply_markup' => ['selective' => true, 'one_time_keyboard' => true]]);
Expand Down
2 changes: 0 additions & 2 deletions config/defaults-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
"OSM_LOOKUP": false,
"AUTO_REFRESH_POLLS":false,
"CUSTOM_TRAINERNAME": true,
"ENABLE_GYM_AREAS": false,
"DEFAULT_GYM_AREA": false,
"RAID_VIA_LOCATION": true,
"RAID_VIA_LOCATION_REMOTE_RAID": false,
"RAID_EGG_DURATION":"60",
Expand Down
4 changes: 0 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1442,10 +1442,6 @@ Config reference
- URL to your map. This is displayed under every raid poll.
* - CUSTOM_TRAINERNAME
- Book, allow users to add custom trainernames via ``/trainer`` command
* - ENABLE_GYM_AREAS
- To divide gyms into areas when making selections through ``/start``, ``/listall`` etc. set this to true. Areas are defined in geoconfig.json.
* - DEFAULT_GYM_AREA": false,
- ID of default gymarea. Can also be set to false to only display areas.
* - PORTAL_IMPORT
- Bool, allow importing gyms via portal import Telegram bots
* - RAID_ANYTIME
Expand Down
16 changes: 2 additions & 14 deletions lang/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -1394,14 +1394,14 @@
"change_extended_gym_details": {
"NL": "Verander de extra gym informatie?",
"DE": "Erweiterte Arena Details ändern?",
"EN": "Save extended gym details?",
"EN": "Change extended gym details?",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Tallenna salin lisätiedot?"
"FI": "Muuta salin lisätietoja?"
},
"new_extended_gym_detail": {
"NL": "Nieuwe extra gym informatie:",
Expand Down Expand Up @@ -3346,17 +3346,5 @@
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Päivämäärä"
},
"current_gymarea": {
"NL": "TRANSLATE",
"DE": "TRANSLATE",
"EN": "Current gymarea",
"IT": "TRANSLATE",
"PT-BR": "TRANSLATE",
"RU": "TRANSLATE",
"NO": "TRANSLATE",
"FR": "TRANSLATE",
"PL": "TRANSLATE",
"FI": "Salit alueelta"
}
}
22 changes: 3 additions & 19 deletions logic/raid_edit_gym_keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/**
* Raid edit gym keys with active raids marker.
* @param $first
* @param $gymarea_id
* @param $warn
* @param $action
* @param $delete
* @param $hidden
* @return array
*/
function raid_edit_gym_keys($first, $gymarea_id = false, $action = 'edit_raidlevel', $delete = false, $hidden = false)
function raid_edit_gym_keys($first, $warn = true, $action = 'edit_raidlevel', $delete = false, $hidden = false)
{
global $config;
// Length of first letter.
Expand All @@ -30,22 +30,7 @@ function raid_edit_gym_keys($first, $gymarea_id = false, $action = 'edit_raidlev
$not .= SP . "AND UPPER(LEFT(gym_name, " . $length . ")) != UPPER('" . $letter . "')" . SP;
}
}
$gymarea_query = '';
if($gymarea_id != false) {
$json = json_decode(file_get_contents(CONFIG_PATH . '/geoconfig.json'),1);
$points = [];
foreach($json as $area) {
if($gymarea_id == $area['id']) {
foreach($area['path'] as $point) {
$points[] = $point[0].' '.$point[1];
}
if($points[0] != $points[count($points)-1]) $points[] = $points[0];
break;
}
}
$polygon_string = implode(',', $points);
$gymarea_query = "AND ST_CONTAINS(ST_GEOMFROMTEXT('POLYGON((".$polygon_string."))'), ST_GEOMFROMTEXT(CONCAT('POINT(',lat,' ',lon,')')))";
}

// Show hidden gyms?
if($hidden == true) {
$show_gym = 0;
Expand All @@ -66,7 +51,6 @@ function raid_edit_gym_keys($first, $gymarea_id = false, $action = 'edit_raidlev
ON raids.gym_id = gyms.id
WHERE UPPER(LEFT(gym_name, $first_length)) = UPPER('{$first}')
$not
$gymarea_query
AND gyms.show_gym = {$show_gym}
GROUP BY gym_name, raids.gym_id, gyms.id, gyms.ex_gym
ORDER BY gym_name " . $query_collate . "
Expand Down
179 changes: 92 additions & 87 deletions logic/raid_edit_gyms_first_letter_keys.php
Original file line number Diff line number Diff line change
@@ -1,116 +1,121 @@
<?php
/**
* Raid gym first letter selection
* @param string $action
* @param bool $hidden
* @param int|false $gymarea_id
* @param $action
* @param $hidden
* @return array
*/
function raid_edit_gyms_first_letter_keys($action = 'raid_by_gym', $hidden = false, $gymarea_id = false, $gymarea_action = '')
function raid_edit_gyms_first_letter_keys($action = 'raid_by_gym', $hidden = false)
{
global $config;
$gymarea_query = $gymarea_name = '';
$gymarea_keys = [];
$skip_letter_keys = true;
if($config->ENABLE_GYM_AREAS) {
$json = json_decode(file_get_contents(CONFIG_PATH . '/geoconfig.json'),1);
$points = [];
foreach($json as $area) {
if($config->DEFAULT_GYM_AREA != false or $gymarea_id != false) {
$gymarea_id = ($gymarea_id != false) ? $gymarea_id : $config->DEFAULT_GYM_AREA;
if($gymarea_id == $area['id']) {
foreach($area['path'] as $point) {
$points[] = $point[0].' '.$point[1];
}
$gymarea_name = $area['name'];
if($points[0] != $points[count($points)-1]) $points[] = $points[0];
} else {
$gymarea_keys[] = [
'text' => $area['name'],
'callback_data' => $area['id'] . ':' . $gymarea_action . ':' . $action
];
}
$skip_letter_keys = false;
} else {
$gymarea_keys[] = [
'text' => $area['name'],
'callback_data' => $area['id'] . ':' . $gymarea_action . ':' . $action
];
}
// 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;
}
$polygon_string = implode(',', $points);
$gymarea_query = "AND ST_CONTAINS(ST_GEOMFROMTEXT('POLYGON((".$polygon_string."))'), ST_GEOMFROMTEXT(CONCAT('POINT(',lat,' ',lon,')')))";
}
// Init empty keys array.
$keys = [];

if(!$skip_letter_keys or !$config->ENABLE_GYM_AREAS or $hidden) {
// Special/Custom gym letters?
if(!empty($config->RAID_CUSTOM_GYM_LETTERS)) {
// Explode special letters.
$special_keys = explode(',', $config->RAID_CUSTOM_GYM_LETTERS);
$select = 'SELECT CASE ';
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));
$select .= SP . "WHEN UPPER(LEFT(gym_name, " . $length . ")) = '" . $letter . "' THEN UPPER(LEFT(gym_name, " . $length . "))" . SP;
}
$select .= 'ELSE UPPER(LEFT(gym_name, 1)) END AS first_letter';
$group_order = 'GROUP BY 1 ORDER BY gym_name';
}else {
$select = 'SELECT DISTINCT UPPER(SUBSTR(gym_name, 1, 1)) AS first_letter';
$group_order = 'ORDER BY 1';
}
// Show hidden gyms?
$show_gym = $hidden ? 0 : 1;
// 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') {
// Select only gyms with active raids
$query_condition = '
LEFT JOIN raids
ON raids.gym_id = gyms.id
WHERE end_time > UTC_TIMESTAMP()
AND show_gym = ' . $show_gym;
}else {
$query_condition = 'WHERE show_gym = ' . $show_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
"
);
}

$rs = my_query(
"
{$select}
FROM gyms
{$query_condition}
{$gymarea_query}
{$group_order}
"
);

while ($gym = $rs->fetch()) {
// Add first letter to keys array
$keys[] = array(
'text' => $gym['first_letter'],
'callback_data' => $show_gym . ':' . $action . ':' . $gym['first_letter'] . (($gymarea_id) ? ',' .$gymarea_id : 'false')
);
} 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
"
);
}
}

// Get the inline key array.
$keys = inline_key_array($keys, 4);
// 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 = [];
if(!empty($gymarea_keys)) $keys = array_merge($keys, inline_key_array($gymarea_keys, 2));
$nav_keys[] = universal_inner_key($keys, '0', 'exit', '0', getTranslation('abort'));

// Get the inline key array.
$keys[] = $nav_keys;
}

return ['keys' => $keys, 'gymarea_name' => $gymarea_name];
return $keys;
}

?>
Loading

0 comments on commit 91674f1

Please sign in to comment.