diff --git a/application/controllers/Map.php b/application/controllers/Map.php index 42b6bd946..73f193e8e 100644 --- a/application/controllers/Map.php +++ b/application/controllers/Map.php @@ -24,30 +24,35 @@ class Map extends CI_Controller { public function qso_map() { $this->load->library('Geojson'); $this->load->model('Map_model'); + $this->load->model('stations'); // Get supported DXCC countries with state data - $supported_dxccs = $this->geojson->getSupportedDxccs(); + $data['supported_dxccs'] = $this->geojson->getSupportedDxccs(); + + $supported_country_codes = array_keys($data['supported_dxccs']); // Fetch available countries from the logbook - $countries = $this->Map_model->get_available_countries(); - - // Filter countries to only include those with GeoJSON support - $supported_country_codes = array_keys($supported_dxccs); - $filtered_countries = array_filter($countries, function($country) use ($supported_country_codes) { - return in_array($country['COL_DXCC'], $supported_country_codes); - }); + $data['countries'] = $this->Map_model->get_available_countries($supported_country_codes); // Fetch station profiles - $station_profiles = $this->Map_model->get_station_profiles(); + $data['station_profiles'] = $this->stations->all_of_user()->result(); + + $data['homegrid'] = explode(',', $this->stations->find_gridsquare()); - $data['countries'] = $filtered_countries; - $data['station_profiles'] = $station_profiles; - $data['supported_dxccs'] = $supported_dxccs; $data['page_title'] = __("QSO Map"); + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/leaflet/geocoding.js', + 'assets/js/leaflet/L.Maidenhead.js', + 'assets/js/sections/qso_map.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/qso_map.js")), + 'assets/js/sections/itumap_geojson.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/itumap_geojson.js")), + 'assets/js/sections/cqmap_geojson.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/cqmap_geojson.js")), + ]; + $this->load->view('interface_assets/header', $data); - $this->load->view('map/qso_map', $data); - $this->load->view('interface_assets/footer'); + $this->load->view('map/qso_map'); + $this->load->view('interface_assets/footer', $footerData); } /** diff --git a/application/models/Map_model.php b/application/models/Map_model.php index 410ac75ad..3c62ebc29 100644 --- a/application/models/Map_model.php +++ b/application/models/Map_model.php @@ -5,32 +5,18 @@ class Map_model extends CI_Model { /** * Get available countries from the logbook with QSOs */ - public function get_available_countries() { - $this->db->select('DISTINCT dxcc_entities.name AS COL_COUNTRY, COL_DXCC, COUNT(*) as qso_count', FALSE); - $this->db->from($this->config->item('table_name')); - $this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); - $this->db->join('dxcc_entities', 'dxcc_entities.adif = ' . $this->config->item('table_name') . '.COL_DXCC'); - $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); - $this->db->where("LENGTH(COL_GRIDSQUARE) >=", 6); // At least 6 chars - $this->db->group_by('COL_COUNTRY, COL_DXCC'); - $this->db->order_by('COL_COUNTRY'); + public function get_available_countries($supported_country_codes) { + $sql = "select DISTINCT dxcc_entities.name AS dxcc_name, dxcc_entities.prefix, COL_DXCC, COUNT(*) as qso_count + from " . $this->config->item('table_name') . " thcv + join station_profile ON station_profile.station_id = thcv.station_id + join dxcc_entities ON dxcc_entities.adif = thcv.COL_DXCC + where station_profile.user_id = ? + and thcv.COL_DXCC IN (" . implode(',', array_fill(0, count($supported_country_codes), '?')) . ") + and LENGTH(thcv.COL_GRIDSQUARE) >= 6 + group by dxcc_name, thcv.COL_DXCC, dxcc_entities.prefix + order by prefix ASC"; - $query = $this->db->get(); - return $query->result_array(); - } - - /** - * Get available station profiles for the user - */ - public function get_station_profiles() { - $this->db->select('station_profile.station_id, station_profile.station_profile_name', FALSE); - $this->db->from($this->config->item('table_name')); - $this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); - $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); - $this->db->group_by('station_profile.station_id, station_profile.station_profile_name'); - $this->db->order_by('station_profile.station_profile_name'); - - $query = $this->db->get(); + $query = $this->db->query($sql, array_merge([$this->session->userdata('user_id')], $supported_country_codes)); return $query->result_array(); } @@ -45,21 +31,25 @@ class Map_model extends CI_Model { $this->load->library('DxccFlag'); } - $this->db->select('COL_PRIMARY_KEY, COL_CALL, COL_GRIDSQUARE, COL_COUNTRY, COL_DXCC, COL_MODE, COL_BAND, COL_TIME_ON, COL_RST_SENT, COL_RST_RCVD, station_profile.station_profile_name', FALSE); - $this->db->from($this->config->item('table_name')); - $this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); - $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); - $this->db->where('COL_COUNTRY', $country); + $sql = "select COL_PRIMARY_KEY, COL_CALL, COL_GRIDSQUARE, COL_COUNTRY, COL_DXCC, COL_MODE, COL_BAND, COL_TIME_ON, COL_RST_SENT, COL_RST_RCVD, station_profile.station_profile_name + from " . $this->config->item('table_name') . " + join station_profile ON station_profile.station_id = " . $this->config->item('table_name') . ".station_id + where station_profile.user_id = ? + and COL_COUNTRY = ?"; + + $bindings[] = $this->session->userdata('user_id'); + $bindings[] = $country; // Add station filter if specified if ($station_id !== null && $station_id !== '') { - $this->db->where('station_profile.station_id', $station_id); + $sql .= " and station_profile.station_id = ?"; + $bindings[] = $station_id; } - $this->db->where("LENGTH(COL_GRIDSQUARE) >=", 6); // At least 6 chars - $this->db->order_by('COL_TIME_ON', 'DESC'); + $sql .= "and LENGTH(COL_GRIDSQUARE) >= 6 + order by COL_TIME_ON DESC"; - $query = $this->db->get(); + $query = $this->db->query($sql, $bindings); $qsos = $query->result_array(); // Process QSOs and convert gridsquares to coordinates diff --git a/application/views/map/qso_map.php b/application/views/map/qso_map.php index 658109ce5..5a40de5fd 100644 --- a/application/views/map/qso_map.php +++ b/application/views/map/qso_map.php @@ -1,3 +1,12 @@ + +

@@ -7,9 +16,9 @@ @@ -19,8 +28,8 @@ @@ -46,14 +55,32 @@ + +