From 25bffdce83f9990f4d0da0812eea1670ba36bd2a Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Fri, 17 Sep 2021 18:11:25 +0200 Subject: [PATCH] [Gridsquare Map] Bugfix. The confirmed fields would not be correct. Or_where seems to work only when where are two conditions in the where statement. --- application/models/Gridsquares_model.php | 89 ++++++++++++------------ 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/application/models/Gridsquares_model.php b/application/models/Gridsquares_model.php index 8ab81181..933a50aa 100644 --- a/application/models/Gridsquares_model.php +++ b/application/models/Gridsquares_model.php @@ -7,7 +7,7 @@ class Gridsquares_model extends CI_Model { // Call the Model constructor parent::__construct(); } - + function get_worked_sat_squares() { $CI =& get_instance(); $CI->load->model('logbooks_model'); @@ -21,36 +21,34 @@ class Gridsquares_model extends CI_Model { return $this->db->get($this->config->item('table_name')); } + function get_confirmed_sat_squares() { + $CI =& get_instance(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - function get_confirmed_sat_squares() { - $CI =& get_instance(); - $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)."'"; - $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'); + $sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as SAT_SQUARE, COL_SAT_NAME FROM ' + . $this->config->item('table_name') + . ' WHERE station_id in (' . $location_list . ') AND COL_GRIDSQUARE != "" AND COL_SAT_NAME != "" AND (COL_LOTW_QSL_RCVD = "Y" OR COL_QSL_RCVD = "Y")'; - return $this->db->get($this->config->item('table_name')); - } + return $this->db->query($sql); + } - function get_confirmed_sat_vucc_squares() { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - $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'); + function get_confirmed_sat_vucc_squares() { + $CI =& get_instance(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); - return $this->db->get($this->config->item('table_name')); - } + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $sql = 'SELECT COL_VUCC_GRIDS, COL_SAT_NAME FROM ' + . $this->config->item('table_name') + . ' WHERE station_id in (' . $location_list . ') 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")'; + + return $this->db->query($sql); + } function get_worked_sat_vucc_squares() { $CI =& get_instance(); @@ -86,30 +84,31 @@ class Gridsquares_model extends CI_Model { return $this->db->get($this->config->item('table_name')); } - function get_band_confirmed($band) { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + function get_band_confirmed($band) { + $CI =& get_instance(); + $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)."'"; - $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 in (' + .$location_list.') 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 = ""'; + } - 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 =', ""); - } + $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->get($this->config->item('table_name')); - } + return $this->db->query($sql); + } function search_band($band, $gridsquare) { $CI =& get_instance();