From 3e302f2e5bcdabd1a514d1cc0363bd4f5dc6d7b6 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Wed, 8 Sep 2021 14:32:48 +0100 Subject: [PATCH] finalised gridsquare map code for showing grouped locations --- application/models/Gridsquares_model.php | 123 +++++++++++++---------- application/views/gridsquares/index.php | 4 +- 2 files changed, 73 insertions(+), 54 deletions(-) diff --git a/application/models/Gridsquares_model.php b/application/models/Gridsquares_model.php index a173da5d..8ab81181 100644 --- a/application/models/Gridsquares_model.php +++ b/application/models/Gridsquares_model.php @@ -7,41 +7,58 @@ class Gridsquares_model extends CI_Model { // Call the Model constructor parent::__construct(); } - + function get_worked_sat_squares() { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - $this->db->where("station_id", $station_id); + $this->db->select('distinct substring(COL_GRIDSQUARE,1,6) as SAT_SQUARE, COL_SAT_NAME', FALSE); + $this->db->where_in('station_id', $logbooks_locations_array); + $this->db->where('COL_GRIDSQUARE !=', ''); + $this->db->where('COL_SAT_NAME !=', ''); - return $this->db->query('SELECT distinct substring(COL_GRIDSQUARE,1,6) as SAT_SQUARE, COL_SAT_NAME FROM '.$this->config->item('table_name').' WHERE station_id = "'.$station_id.'" AND COL_GRIDSQUARE != "" AND COL_SAT_NAME != ""'); + return $this->db->get($this->config->item('table_name')); } function get_confirmed_sat_squares() { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - return $this->db->query('SELECT distinct substring(COL_GRIDSQUARE,1,6) as SAT_SQUARE, COL_SAT_NAME FROM '.$this->config->item('table_name').' WHERE station_id = "'.$station_id.'" AND COL_GRIDSQUARE != "" AND COL_SAT_NAME != "" AND (COL_LOTW_QSL_RCVD = "Y" OR COL_QSL_RCVD = "Y")'); + $this->db->select('distinct substring(COL_GRIDSQUARE,1,6) as SAT_SQUARE, COL_SAT_NAME', FALSE); + $this->db->where_in('station_id', $logbooks_locations_array); + $this->db->where('COL_GRIDSQUARE !=', ''); + $this->db->where('COL_SAT_NAME !=', ''); + $this->db->where('COL_LOTW_QSL_RCVD', 'Y'); + $this->db->or_where('COL_QSL_RCVD', 'Y'); + + return $this->db->get($this->config->item('table_name')); } function get_confirmed_sat_vucc_squares() { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - return $this->db->query('SELECT COL_VUCC_GRIDS, COL_SAT_NAME FROM '.$this->config->item('table_name').' WHERE station_id = "'.$station_id.'" AND COL_VUCC_GRIDS != "" AND COL_SAT_NAME != "" AND (COL_LOTW_QSL_RCVD = "Y" OR COL_QSL_RCVD = "Y") AND (COL_LOTW_QSL_RCVD = "Y" OR COL_QSL_RCVD = "Y")'); + $this->db->select('COL_VUCC_GRIDS, COL_SAT_NAME', FALSE); + $this->db->where_in('station_id', $logbooks_locations_array); + $this->db->where('COL_VUCC_GRIDS !=', ''); + $this->db->where('COL_SAT_NAME !=', ''); + $this->db->where('COL_LOTW_QSL_RCVD', 'Y'); + $this->db->or_where('COL_QSL_RCVD', 'Y'); + + return $this->db->get($this->config->item('table_name')); } function get_worked_sat_vucc_squares() { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - $this->db->select('COL_PRIMARY_KEY, COL_VUCC_GRIDS, COL_SAT_NAME'); - $this->db->where("station_id", $station_id); + $this->db->select('COL_PRIMARY_KEY, COL_VUCC_GRIDS, COL_SAT_NAME', FALSE); + $this->db->where_in('station_id', $logbooks_locations_array); $this->db->where('COL_VUCC_GRIDS !=', ""); $this->db->where('COL_SAT_NAME !=', ""); return $this->db->get($this->config->item('table_name')); @@ -49,59 +66,61 @@ class Gridsquares_model extends CI_Model { function get_band($band) { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + + $this->db->select('distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND', FALSE); + $this->db->where_in('station_id', $logbooks_locations_array); + $this->db->where('COL_GRIDSQUARE !=', ''); - $sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND FROM ' - .$this->config->item('table_name') - .' WHERE station_id = "' - .$station_id.'" AND COL_GRIDSQUARE != ""'; 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 = ""'; + $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->query($sql); + return $this->db->get($this->config->item('table_name')); } function get_band_confirmed($band) { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + + $this->db->select('distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND', FALSE); + $this->db->where_in('station_id', $logbooks_locations_array); + $this->db->where('COL_GRIDSQUARE !=', ''); - $sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND FROM ' - .$this->config->item('table_name') - .' WHERE station_id = "' - .$station_id.'" AND COL_GRIDSQUARE != ""'; 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 = ""'; + $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 =', ""); } - $sql .= ' AND (COL_LOTW_QSL_RCVD = "Y" OR COL_QSL_RCVD = "Y")'; + $this->db->where('COL_LOTW_QSL_RCVD', 'Y'); + $this->db->or_where('COL_QSL_RCVD', 'Y'); - - return $this->db->query($sql); + return $this->db->get($this->config->item('table_name')); } function search_band($band, $gridsquare) { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; $sql = 'SELECT COL_CALL, COL_TIME_ON, COL_BAND, COL_MODE, COL_GRIDSQUARE, COL_VUCC_GRIDS FROM ' .$this->config->item('table_name') - .' WHERE station_id = "' . $station_id . '" ' + .' WHERE station_id IN (' . $location_list . ') ' . ' AND (COL_GRIDSQUARE LIKE "%'.$gridsquare.'%" or COL_VUCC_GRIDS LIKE "%'.$gridsquare.'%")'; if ($band != 'All') { @@ -122,12 +141,14 @@ class Gridsquares_model extends CI_Model { function search_sat($gridsquare) { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; $sql = 'SELECT COL_CALL, COL_TIME_ON, COL_BAND, COL_MODE, COL_SAT_NAME, COL_GRIDSQUARE, COL_VUCC_GRIDS FROM ' . $this->config->item('table_name'). - ' WHERE station_id = "'.$station_id. '"' . + ' WHERE station_id IN ('.$location_list. ')' . ' AND (COL_GRIDSQUARE LIKE "%'.$gridsquare.'%" or COL_VUCC_GRIDS LIKE "%'.$gridsquare.'%")'. ' AND COL_PROP_MODE = "SAT"'; diff --git a/application/views/gridsquares/index.php b/application/views/gridsquares/index.php index f1b2b027..9bc61d13 100644 --- a/application/views/gridsquares/index.php +++ b/application/views/gridsquares/index.php @@ -26,15 +26,13 @@ uri->segment(2) == "satellites") { ?> uri->segment(2) == "band") { ?>