From 7137099d10c222e588fdb81cb28323b97a0704cd Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 15 Apr 2024 18:25:19 +0200 Subject: [PATCH 1/3] Upgrade API to also respond with confirmation state --- application/controllers/Api.php | 27 ++++++++++++++++++++++----- application/models/Logbook_model.php | 26 ++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index ebad93112..b30de75f5 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -364,6 +364,13 @@ class API extends CI_Controller { $band = null; } + // If $obj['cnfm'] exists + if(isset($obj['cnfm'])) { + $cnfm = $obj['cnfm']; + } else { + $cnfm = null; + } + $this->load->model('logbooks_model'); if($this->logbooks_model->public_slug_exists($logbook_slug)) { @@ -388,15 +395,25 @@ class API extends CI_Controller { // Search Logbook for callsign $this->load->model('logbook_model'); - $result = $this->logbook_model->check_if_grid_worked_in_logbook($grid, $logbooks_locations_array, $band); - + $query = $this->logbook_model->check_if_grid_worked_in_logbook($grid, $logbooks_locations_array, $band, $cnfm); http_response_code(201); - if($result > 0) - { + if ($query->num_rows() == 0) { + echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Not Found']); + } else if ($cnfm == null) { echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Found']); } else { - echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Not Found']); + $arr = []; + foreach($query->result() as $line) { + $arr[] = $line->gridorcnfm; + } + if (in_array('Y', $arr)) { + print_r($arr); + echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Confirmed']); + } else { + echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Worked']); + } } + } else { // Logbook not found http_response_code(404); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index ad0626076..630875ff7 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2136,7 +2136,7 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = } - function check_if_grid_worked_in_logbook($grid, $StationLocationsArray = null, $band = null) { + function check_if_grid_worked_in_logbook($grid, $StationLocationsArray = null, $band = null, $cnfm = null) { if($StationLocationsArray == null) { $this->load->model('logbooks_model'); @@ -2145,7 +2145,26 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = $logbooks_locations_array = $StationLocationsArray; } - $this->db->select('COL_GRIDSQUARE'); + switch($cnfm) { + case 'qsl': + $this->db->select('COL_QSL_RCVD as gridorcnfm'); + $this->db->group_by('COL_QSL_RCVD'); + break; + case 'lotw': + $this->db->select('COL_LOTW_QSL_RCVD as gridorcnfm'); + $this->db->group_by('COL_LOTW_QSL_RCVD'); + break; + case 'eqsl': + $this->db->select('COL_EQSL_QSL_RCVD as gridorcnfm'); + $this->db->group_by('COL_EQSL_QSL_RCVD'); + break; + default: + $this->db->select('SUBSTR(COL_GRIDSQUARE,1 ,4) as gridorcnfm'); + $this->db->group_by('gridorcnfm'); + break; + break; + } + $this->db->order_by('gridorcnfm'); $this->db->where_in('station_id', $logbooks_locations_array); $this->db->group_start(); $this->db->like('COL_GRIDSQUARE', $grid); @@ -2158,11 +2177,10 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = // Where col_sat_name is not empty $this->db->where('COL_SAT_NAME !=', ''); } - $this->db->limit('2'); $query = $this->db->get($this->config->item('table_name')); - return $query->num_rows(); + return $query; } From 0a16f897a15a5dbef801a2c4bb166949a24db9b7 Mon Sep 17 00:00:00 2001 From: phl0 Date: Mon, 15 Apr 2024 18:26:35 +0200 Subject: [PATCH 2/3] Delete erroneous line --- application/models/Logbook_model.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 630875ff7..7654393ed 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2162,7 +2162,6 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = $this->db->select('SUBSTR(COL_GRIDSQUARE,1 ,4) as gridorcnfm'); $this->db->group_by('gridorcnfm'); break; - break; } $this->db->order_by('gridorcnfm'); $this->db->where_in('station_id', $logbooks_locations_array); From 23ebb808203505ee822c82c3c3fac61e928e7ca3 Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 16 Apr 2024 01:27:32 +0200 Subject: [PATCH 3/3] Remove debug output --- application/controllers/Api.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index b30de75f5..191fdafaa 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -407,7 +407,6 @@ class API extends CI_Controller { $arr[] = $line->gridorcnfm; } if (in_array('Y', $arr)) { - print_r($arr); echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Confirmed']); } else { echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Worked']);