From 163c02a867d4d2e3d6514f27d7af88fa8be4fe78 Mon Sep 17 00:00:00 2001 From: DB4SCW Date: Fri, 23 Aug 2024 20:29:50 +0000 Subject: [PATCH] initial implementation of lib version for maxdistance --- application/controllers/Reg1test.php | 4 ++++ application/libraries/Qra.php | 28 ++++++++++++++++++++++++ application/libraries/Reg1testformat.php | 11 ++++++++-- application/views/reg1test/export.php | 2 +- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/application/controllers/Reg1test.php b/application/controllers/Reg1test.php index 4d88fe28b..42a47b1ec 100644 --- a/application/controllers/Reg1test.php +++ b/application/controllers/Reg1test.php @@ -152,6 +152,9 @@ class Reg1test extends CI_Controller { $this->load->model('stations'); $this->load->model('user_model'); + //Load distance calculator + $this->load->library('Qra'); + //deny access if station is not accessible $station_id = $this->input->post('station_id', true); if (!$this->stations->check_station_is_accessible($station_id)) { @@ -204,6 +207,7 @@ class Reg1test extends CI_Controller { $data['rxequipment'] = $this->input->post('rxequipment', true); $data['antenna'] = $this->input->post('antenna', true); $data['antennaheight'] = $this->input->post('antennaheight', true); + $data['maxdistanceqso'] = $this->qra->getMaxDistanceQSO($station->station_gridsquare, $data['qsos'], "K"); $data['soapbox'] = $this->input->post('soapbox', true); diff --git a/application/libraries/Qra.php b/application/libraries/Qra.php index d14e0ceb1..ea8cd4065 100644 --- a/application/libraries/Qra.php +++ b/application/libraries/Qra.php @@ -125,6 +125,34 @@ class Qra { } return $echo; } + + function getMaxDistanceQSO($mylocator, $qsos, $unit = "M") + { + //return nothing for empty QSO set + if(count($qsos->result()) < 1){ + return [null, 0]; + } + + //collect maximum data + $maxdistance = 0; + $maxdistanceqso = null; + + //iterate through all qsos + foreach ($qsos->result() as $row) { + + //get distance in kilometers + $distance = $this->distance($mylocator, $row->COL_GRIDSQUARE, $unit); + + //store new highscore if present + if($distance > $maxdistance) { + $maxdistance = $distance; + $maxdistanceqso = $row; + } + } + + //return findings + return [$maxdistanceqso, $maxdistance]; + } } diff --git a/application/libraries/Reg1testformat.php b/application/libraries/Reg1testformat.php index 83ac9e103..6d4b9805f 100644 --- a/application/libraries/Reg1testformat.php +++ b/application/libraries/Reg1testformat.php @@ -5,7 +5,7 @@ class Reg1testformat { public function header($contest_id, $from, $to, $callsign, $gridlocator, $contestaddress1, $contestaddress2, $categoryoperator, $band, $club, $name, $responsible_operator, $address1, $address2, $addresspostalcode, $addresscity, $addresscountry, $operatorphone, $operators, - $soapbox, $qso_count, $sentexchange, $txequipment, $power, $rxequipment, $antenna, $antennaheight) { + $soapbox, $qso_count, $sentexchange, $txequipment, $power, $rxequipment, $antenna, $antennaheight, $maxdistanceqso) { //build header $edi_header = "[REG1TEST;1]" . "\r\n"; @@ -44,7 +44,14 @@ class Reg1testformat { $edi_header .= "CDXCs=" . "\r\n"; //Arguments describe the claimed number of DXCCs worked, the number of bonus points claimed for each new DXCC and the DXCC multiplier. Leave empty. $edi_header .= "CDXCB=" . "\r\n"; //Argument describes the claimed total number of DXCC bonus points. Leave empty. $edi_header .= "CToSc=" . "\r\n"; //Argument describes the total claimed score. Leave empty. - $edi_header .= "CODXC=" . "\r\n"; //Arguments describe the claimed ODX contact call, WWL and distance. Leave empty. + + //set QSO info for QSO with max distance only if we can determine it + if($maxdistanceqso[0] != null){ + $edi_header .= "CODXC=" . strtoupper($maxdistanceqso[0]->COL_CALL) . ";" . substr(strtoupper($maxdistanceqso[0]->COL_GRIDSQUARE), 0, 6) . ";" . (int)$maxdistanceqso[1] . "\r\n"; //Arguments describe the claimed ODX contact call, WWL and distance. + }else{ + $edi_header .= "CODXC=" . "\r\n"; //Arguments describe the claimed ODX contact call, WWL and distance. Leave empty. + } + $edi_header .= "[Remarks]" . "\r\n" . $soapbox . "\r\n"; //Remarks $edi_header .= "[QSORecords;" . $qso_count . "]" . "\r\n"; //QSO Header and QSO Count diff --git a/application/views/reg1test/export.php b/application/views/reg1test/export.php index 0575a01ac..15c8635e6 100644 --- a/application/views/reg1test/export.php +++ b/application/views/reg1test/export.php @@ -10,7 +10,7 @@ header('Content-Disposition: attachment; filename="'.$callsign.'-'.$contest_id.' //get header echo $CI->reg1testformat->header($contest_id, $from, $to, $callsign, $gridlocator, $contestaddress1, $contestaddress2, $categoryoperator, $band, $club, $name, $responsible_operator, $address1, $address2, $addresspostalcode, $addresscity, $addresscountry, $operatorphone, $operators, - $soapbox, $qso_count, $sentexchange, $txequipment, $power, $rxequipment, $antenna, $antennaheight); + $soapbox, $qso_count, $sentexchange, $txequipment, $power, $rxequipment, $antenna, $antennaheight, $maxdistanceqso); //write QSO details while keeping track of the QSO number $i = 1;