From d71af44fbb8e547d2bb23a3224cc9efa3b54e7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Mel=C3=ADk?= Date: Thu, 27 Feb 2025 21:52:19 +0100 Subject: [PATCH] add qso widget configuration into settings --- application/controllers/User.php | 3 ++ application/controllers/Widgets.php | 43 +++++++++++++++++++++++---- application/models/Logbooks_model.php | 13 ++++++++ application/models/User_model.php | 4 ++- application/views/user/edit.php | 19 ++++++++++++ 5 files changed, 75 insertions(+), 7 deletions(-) diff --git a/application/controllers/User.php b/application/controllers/User.php index bca2951dc..fdb18a4f6 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -288,6 +288,7 @@ class User extends CI_Controller { $this->input->post('on_air_widget_enabled'), $this->input->post('on_air_widget_display_last_seen'), $this->input->post('on_air_widget_show_only_most_recent_radio'), + $this->input->post('qso_widget_display_qso_time'), $this->input->post('clubstation') == '1' ? true : false )) { // Check for errors @@ -786,6 +787,7 @@ class User extends CI_Controller { $data['on_air_widget_display_last_seen'] = ($this->user_options_model->get_options('widget', array('option_name'=>'on_air', 'option_key' => 'display_last_seen'), $this->uri->segment(3))->row()->option_value ?? "false"); $data['on_air_widget_show_only_most_recent_radio'] = ($this->user_options_model->get_options('widget', array('option_name'=>'on_air', 'option_key' => 'display_only_most_recent_radio'), $this->uri->segment(3))->row()->option_value ?? "true"); $data['on_air_widget_url'] = site_url('widgets/on_air/' . $q->slug); + $data['qso_widget_display_qso_time'] = ($this->user_options_model->get_options('widget', array('option_name'=>'qso', 'option_key' => 'display_qso_time'), $this->uri->segment(3))->row()->option_value ?? "false"); $this->load->view('interface_assets/header', $data); $this->load->view('user/edit', $data); @@ -887,6 +889,7 @@ class User extends CI_Controller { $data['on_air_widget_enabled'] = $this->input->post('on_air_widget_enabled', true); $data['on_air_widget_display_last_seen'] = $this->input->post('on_air_widget_display_last_seen', true); $data['on_air_widget_show_only_most_recent_radio'] = $this->input->post('on_air_widget_show_only_most_recent_radio', true); + $data['qso_widget_display_qso_time'] = $this->input->post('qso_widget_display_qso_time', true); $this->load->view('user/edit'); $this->load->view('interface_assets/footer'); diff --git a/application/controllers/Widgets.php b/application/controllers/Widgets.php index 05192360a..6f574d39f 100644 --- a/application/controllers/Widgets.php +++ b/application/controllers/Widgets.php @@ -34,11 +34,6 @@ class Widgets extends CI_Controller { $data['theme'] = "default"; } - // should we show time? - // TODO - $data['show_time'] = (($this->config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))); - $data['show_time'] = true; - // determine text size $text_size = $this->input->get('text_size', true) ?? 1; $data['text_size_class'] = $this->prepare_text_size_css_class($text_size); @@ -57,7 +52,6 @@ class Widgets extends CI_Controller { $this->load->model('logbook_model'); $this->load->model('logbooks_model'); if($this->logbooks_model->public_slug_exists($logbook_slug)) { - // Load the public view $logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($logbook_slug); if($logbook_id != false) @@ -73,6 +67,11 @@ class Widgets extends CI_Controller { show_404(__("Unknown Public Page.")); } + // Get widget settings + $user_id = $this->logbooks_model->user_id_from_logbook_slug($logbook_slug); + $widget_options = $this->get_qso_widget_options($user_id); + + $data['show_time'] = $widget_options->display_qso_time; $data['last_qsos_list'] = $this->logbook_model->get_last_qsos($qso_count, $logbooks_locations_array); $this->load->view('widgets/qsos', $data); @@ -221,6 +220,38 @@ class Widgets extends CI_Controller { } } + /** + * Fetch and prepare user options for QSO widget + * + * @return stdClass + */ + private function get_qso_widget_options($user_id) { + $raw_widget_options = $this->user_options_model->get_options('widget', null, $user_id)->result_array(); + + // default values + $options = new \stdClass(); + $options->display_qso_time = false; + + if ($raw_widget_options === null) { + return $options; + } + + foreach ($raw_widget_options as $opt_data) { + if ($opt_data["option_name"] !== 'qso') { + continue; + } + + $key = $opt_data["option_key"]; + $value = $opt_data["option_value"]; + + if ($key === "display_qso_time") { + $options->display_qso_time = $value === "true"; + } + } + + return $options; + } + /** * Fetch and prepare user options for on air widget * diff --git a/application/models/Logbooks_model.php b/application/models/Logbooks_model.php index df69861ec..2b594314a 100644 --- a/application/models/Logbooks_model.php +++ b/application/models/Logbooks_model.php @@ -188,6 +188,19 @@ class Logbooks_model extends CI_Model { } } + function user_id_from_logbook_slug($slug) { + $this->db->where('public_slug', $this->security->xss_clean($slug)); + $query = $this->db->get('station_logbooks'); + + if ($query->num_rows() > 0){ + foreach ($query->result() as $row) { + return $row->user_id; + } + } else { + return null; + } + } + function is_public_slug_available($slug) { // Clean public_slug $clean_slug = $this->security->xss_clean($slug); diff --git a/application/models/User_model.php b/application/models/User_model.php index 147d3dcd2..d2a1b18ed 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -215,7 +215,7 @@ class User_Model extends CI_Model { $user_wwff_to_qso_tab, $user_pota_to_qso_tab, $user_sig_to_qso_tab, $user_dok_to_qso_tab, $user_lotw_name, $user_lotw_password, $user_eqsl_name, $user_eqsl_password, $user_clublog_name, $user_clublog_password, $user_winkey, $on_air_widget_enabled, $on_air_widget_display_last_seen, $on_air_widget_show_only_most_recent_radio, - $clubstation = 0) { + $qso_widget_display_qso_time, $clubstation = 0) { // Check that the user isn't already used if(!$this->exists($username)) { $data = array( @@ -301,6 +301,7 @@ class User_Model extends CI_Model { $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'widget','on_air','enabled','".(xss_clean($on_air_widget_enabled ?? 'false'))."');"); $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'widget','on_air','display_last_seen','".(xss_clean($on_air_widget_display_last_seen ?? 'false'))."');"); $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'widget','on_air','display_only_most_recent_radio','".(xss_clean($on_air_widget_show_only_most_recent_radio ?? 'true'))."');"); + $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'widget','qso','display_qso_time','".(xss_clean($qso_widget_display_qso_time ?? 'false'))."');"); return OK; } else { @@ -369,6 +370,7 @@ class User_Model extends CI_Model { $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'widget','on_air','enabled','".(xss_clean($fields['on_air_widget_enabled'] ?? 'false'))."');"); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'widget','on_air','display_last_seen','".(xss_clean($fields['on_air_widget_display_last_seen'] ?? 'false'))."');"); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'widget','on_air','display_only_most_recent_radio','".(xss_clean($fields['on_air_widget_show_only_most_recent_radio'] ?? 'true'))."');"); + $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'widget','qso','display_qso_time','".(xss_clean($fields['qso_widget_display_qso_time'] ?? 'false'))."');"); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'dashboard','last_qso_count','count','".$dashboard_last_qso_count."');"); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'qso_tab','last_qso_count','count','".$qso_page_last_qso_count."');"); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'dashboard','show_map','boolean','".xss_clean($fields['user_dashboard_map'] ?? 'Y')."');"); diff --git a/application/views/user/edit.php b/application/views/user/edit.php index 8798adbb1..5fdb0307c 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -892,6 +892,25 @@ +
+ +
+
+
+
+
+ + + + +
+
+
+
+