diff --git a/application/controllers/Widgets.php b/application/controllers/Widgets.php index 80b7d0045..9dcb9698f 100644 --- a/application/controllers/Widgets.php +++ b/application/controllers/Widgets.php @@ -1,9 +1,9 @@ logbook_model->get_last_qsos(15, $logbooks_locations_array); - + $this->load->view('widgets/qsos', $data); } } @@ -49,7 +49,7 @@ class Widgets extends CI_Controller { public function oqrs($user_callsign = 'CALL MISSING') { $this->load->model('oqrs_model'); $stations = $this->oqrs_model->get_oqrs_stations(); - + if ($stations->result() === NULL) { show_404(__("No stations found that are using Wavelog OQRS.")); return; @@ -68,7 +68,7 @@ class Widgets extends CI_Controller { } else { $data['theme'] = $this->config->item('option_theme'); } - + $data['user_callsign'] = strtoupper($this->security->xss_clean($user_callsign)); $this->load->view('widgets/oqrs', $data); } @@ -91,10 +91,10 @@ class Widgets extends CI_Controller { show_404($e->getMessage()); return; } - - $user_id = $user->user_id; + + $user_id = $user->user_id; $widget_options = $this->get_on_air_widget_options($user_id); - + if ($widget_options->is_enabled === false) { show_404(__("User has on-air widget disabled")); return; @@ -103,6 +103,13 @@ class Widgets extends CI_Controller { $this->load->model('cat'); $query = $this->cat->status_for_user_id($user_id); + // determine theme + $theme = $this->input->get('theme', true) ?? $this->config->item('option_theme'); + + // determine text size + $text_size = $this->input->get('text_size', true) ?? 1; + + if ($query->num_rows() > 0) { $radio_timeout_seconds = $this->get_radio_timeout_seconds(); $cat_timeout_interval_minutes = floor($radio_timeout_seconds / 60); @@ -112,7 +119,7 @@ class Widgets extends CI_Controller { foreach ($query->result() as $radio_data) { // There can be multiple radios online, we need to take into account all of them $radio_updated_ago_minutes = $this->calculate_radio_updated_ago_minutes($radio_data->timestamp); - + if ($radio_updated_ago_minutes > $cat_timeout_interval_minutes) { // Radio was updated too long ago - calculate user's "last seen X days ago" value $mins_per_day = 1440; @@ -127,27 +134,22 @@ class Widgets extends CI_Controller { } } - // determine theme - $theme = $this->input->get('theme', true) ?? $this->config->item('option_theme'); - $data['theme'] = $theme; - - // determine text size - $text_size = $this->input->get('text_size', true) ?? 1; - $data['text_size_class'] = $this->prepare_text_size_css_class($text_size); - if (count($radios_online) > 1 && $widget_options->display_only_most_recent_radio) { // in case only most recent radio should be displayed, use only most recently updated radio as a result usort($radios_online, function($radio_a, $radio_b) { if ($radio_a->updated_at == $radio_b->updated_at) return 0; return ($radio_a->updated_at > $radio_b->updated_at) ? -1 : 1; }); - + $radios_online = [$radios_online[0]]; } // last seen text $last_seen_text = $widget_options->display_last_seen ? $this->prepare_last_seen_text($last_seen_days_ago) : null; + $data['theme'] = $theme; + $data['text_size_class'] = $this->prepare_text_size_css_class($text_size); + // prepare rest of the data for UI $data['user_callsign'] = strtoupper($user->user_callsign); $data['is_on_air'] = count($radios_online) > 0; @@ -157,10 +159,12 @@ class Widgets extends CI_Controller { $this->load->view('widgets/on_air', $data); } else { - show_error( - __("No CAT interfaced radios found. You need to have at least one radio interface configured.") - ); - return; + $theme = $this->input->get('theme', true) ?? $this->config->item('option_theme'); + $data['theme'] = $theme; + $data['text_size_class'] = $this->prepare_text_size_css_class($text_size); + $data['user_callsign'] = strtoupper($user->user_callsign); + $data['error'] = __("No CAT interfaced radios found. You need to have at least one radio interface configured."); + $this->load->view('widgets/on_air', $data); } } @@ -171,7 +175,7 @@ class Widgets extends CI_Controller { */ private function get_on_air_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->is_enabled = false; @@ -331,4 +335,4 @@ class Widgets extends CI_Controller { return trim(sprintf("%s / %s %s", $rx_frequency, $tx_frequency, $mode_string)); } } -} \ No newline at end of file +} diff --git a/application/views/widgets/on_air.php b/application/views/widgets/on_air.php index 4f35dfda0..5e9c3998a 100644 --- a/application/views/widgets/on_air.php +++ b/application/views/widgets/on_air.php @@ -1,6 +1,6 @@ -