From d9b3c3d502c8040334b3054aa870ae63f773db9e Mon Sep 17 00:00:00 2001 From: int2001 Date: Mon, 30 Dec 2024 14:16:33 +0000 Subject: [PATCH] Calculate and fill distance (API) --- application/controllers/Api.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 3e496f9ae..a94798177 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -166,6 +166,10 @@ class API extends CI_Controller { $this->load->model('stations'); + if (!$this->load->is_loaded('Qra')) { + $this->load->library('Qra'); + } + $return_msg = array(); $return_count = 0; @@ -192,6 +196,8 @@ class API extends CI_Controller { echo json_encode(['status' => 'failed', 'reason' => "station id does not belong to the API key owner."]); die(); } + $mystation=$this->stations->profile_clean($obj['station_profile_id']); + $mygrid=($mystation->station_gridsquare ?? ''); if($obj['type'] == "adif" && $obj['string'] != "") { // Load the logbook model for adding QSO records @@ -219,6 +225,9 @@ class API extends CI_Controller { if(count($record) == 0) { break; }; + if ((key_exists('gridsquare',$record)) && (($mygrid ?? '') != '') && (($record['gridsquare'] ?? '') != '') && (!(key_exists('distance',$record)))) { + $record['distance'] = $this->qra->distance($mygrid, $record['gridsquare'], 'K'); + } array_push($alladif,$record); $adif_count++; };