From dd4ac6ff24a6fd4142fa5221ec6b673cd9de82c6 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 22 Oct 2022 21:04:33 +0200 Subject: [PATCH] [Gridsquare map] Fix for vucc grids on map --- application/controllers/Gridsquares.php | 52 +++++++++++++++++++ application/models/Gridsquares_model.php | 63 ++++++++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/application/controllers/Gridsquares.php b/application/controllers/Gridsquares.php index 87dbafe0..3defd4ba 100644 --- a/application/controllers/Gridsquares.php +++ b/application/controllers/Gridsquares.php @@ -295,6 +295,58 @@ class Gridsquares extends CI_Controller { } } + $query_vucc = $this->gridsquares_model->get_band_worked_vucc_squares($band); + + if ($query && $query_vucc->num_rows() > 0) + { + foreach ($query_vucc->result() as $row) + { + + $grids = explode(",", $row->COL_VUCC_GRIDS); + + foreach($grids as $key) { + $grid_two = strtoupper(substr($key,0,2)); + $grid_four = strtoupper(substr($key,0,4)); + + // Check if 2 Char is in array + if(!in_array($grid_two, $array_grid_2char)){ + array_push($array_grid_2char, $grid_two); + } + + + if(!in_array($grid_four, $array_grid_4char)){ + array_push($array_grid_4char, $grid_four); + } + } + } + } + + // Confirmed Squares + $query_vucc = $this->gridsquares_model->get_band_confirmed_vucc_squares($band); + + if ($query && $query_vucc->num_rows() > 0) + { + foreach ($query_vucc->result() as $row) + { + + $grids = explode(",", $row->COL_VUCC_GRIDS); + + foreach($grids as $key) { + $grid_2char_confirmed = strtoupper(substr($key,0,2)); + $grid_4char_confirmed = strtoupper(substr($key,0,4)); + + // Check if 2 Char is in array + if(!in_array($grid_2char_confirmed, $array_grid_2char_confirmed)){ + array_push($array_grid_2char_confirmed, $grid_2char_confirmed); + } + + + if(!in_array($grid_4char_confirmed, $array_grid_4char_confirmed)){ + array_push($array_grid_4char_confirmed, $grid_4char_confirmed); + } + } + } + } function js_str($s) { diff --git a/application/models/Gridsquares_model.php b/application/models/Gridsquares_model.php index 6bd36304..430be3ed 100644 --- a/application/models/Gridsquares_model.php +++ b/application/models/Gridsquares_model.php @@ -147,6 +147,69 @@ class Gridsquares_model extends CI_Model { return $this->db->query($sql); } + function get_band_worked_vucc_squares($band, $StationLocationsArray = null) { + if($StationLocationsArray == null) { + $CI =& get_instance(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + } else { + $logbooks_locations_array = $StationLocationsArray; + } + + if (!$logbooks_locations_array) { + return null; + } + + $this->db->select('distinct COL_VUCC_GRIDS, COL_BAND', FALSE); + $this->db->where_in('station_id', $logbooks_locations_array); + $this->db->where('COL_VUCC_GRIDS !=', ''); + + if ($band != 'All') { + $this->db->where('COL_BAND', $band); + $this->db->where('COL_PROP_MODE !=', "SAT"); + $this->db->where('COL_PROP_MODE !=', "INTERNET"); + $this->db->where('COL_PROP_MODE !=', "ECH"); + $this->db->where('COL_PROP_MODE !=', "RPT"); + $this->db->where('COL_SAT_NAME =', ""); + } + + return $this->db->get($this->config->item('table_name')); + } + + function get_band_confirmed_vucc_squares($band, $StationLocationsArray = null) { + if($StationLocationsArray == null) { + $CI =& get_instance(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + } else { + $logbooks_locations_array = $StationLocationsArray; + } + + if (!$logbooks_locations_array) { + return null; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $sql = 'SELECT distinct COL_VUCC_GRIDS, COL_BAND FROM ' + .$this->config->item('table_name') + .' WHERE station_id in (' + .$location_list.') AND COL_VUCC_GRIDS != ""'; + if ($band != 'All') { + $sql .= ' AND COL_BAND = "' . $band + .'" + AND COL_PROP_MODE != "SAT" + AND COL_PROP_MODE != "INTERNET" + AND COL_PROP_MODE != "ECH" + AND COL_PROP_MODE != "RPT" + AND COL_SAT_NAME = ""'; + } + + $sql .= ' AND (COL_LOTW_QSL_RCVD = "Y" OR COL_QSL_RCVD = "Y")'; + + return $this->db->query($sql); + } + function search_band($band, $gridsquare, $StationLocationsArray = null) { if($StationLocationsArray == null) { $CI =& get_instance();