diff --git a/application/controllers/Distancerecords.php b/application/controllers/Distancerecords.php index 54711d2dc..fec4a228b 100644 --- a/application/controllers/Distancerecords.php +++ b/application/controllers/Distancerecords.php @@ -33,6 +33,31 @@ class Distancerecords extends CI_Controller { case 'M d, y': $usethisformat = 'MMM D, YY';break; } + if ($this->session->userdata('user_measurement_base') == NULL) { + $measurement_base = $this->config->item('measurement_base'); + } else { + $measurement_base = $this->session->userdata('user_measurement_base'); + } + + switch ($measurement_base) { + case 'M': + $unit = "mi"; + $factor = 0.621371; + break; + case 'K': + $unit = "km"; + $factor = 1; + break; + case 'N': + $unit = "nmi"; + $factor = 0.539957; + break; + default: + $unit = "km"; + $factor = 1; + break; + } + $data['scripts'] = [ 'assets/js/sections/distancerecords.js', ]; @@ -41,6 +66,8 @@ class Distancerecords extends CI_Controller { $data['custom_date_format'] = $custom_date_format; $data['page_title'] = __("Satellite Distance Records"); $data['distances'] = $this->distancerecords_model->get_records(); + $data['factor'] = $factor; + $data['unit'] = $unit; $footerData['usethisformat'] = $usethisformat; diff --git a/application/models/Distancerecords_model.php b/application/models/Distancerecords_model.php index 4947450a4..e614591be 100644 --- a/application/models/Distancerecords_model.php +++ b/application/models/Distancerecords_model.php @@ -20,18 +20,21 @@ class Distancerecords_model extends CI_Model { if (!$logbooks_locations_array) { return null; } - $sql = 'SELECT t1.sat, t1.distance, t2.COL_TIME_ON AS time, t2.COL_CALL AS callsign, t2.COL_GRIDSQUARE AS grid, t2.COL_MODE AS mode, t2.COL_PRIMARY_KEY AS primarykey + $sql = 'SELECT t1.sat, t1.distance, t2.COL_TIME_ON AS time, t2.COL_CALL AS callsign, t2.COL_GRIDSQUARE AS grid, t2.COL_MODE AS mode, t2.COL_PRIMARY_KEY AS primarykey, t2.station_gridsquare AS mygrid FROM ( SELECT MAX(col_distance) AS distance, COL_SAT_NAME AS sat FROM '.$this->config->item('table_name').' WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') AND COALESCE(COL_SAT_NAME, "") <> "" + AND COL_DISTANCE IS NOT NULL + AND COL_GRIDSQUARE IS NOT NULL GROUP BY col_sat_name ) t1 LEFT JOIN ( - SELECT *, ROW_NUMBER() OVER (PARTITION BY COL_SAT_NAME, COL_DISTANCE ORDER BY COL_TIME_ON asc) AS rn + SELECT COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_GRIDSQUARE, COL_MODE, COL_SAT_NAME, COL_DISTANCE, station_gridsquare, ROW_NUMBER() OVER (PARTITION BY COL_SAT_NAME, COL_DISTANCE ORDER BY COL_TIME_ON asc) AS rn FROM '.$this->config->item('table_name').' - WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') + LEFT JOIN station_profile ON station_profile.station_id = '.$this->config->item('table_name').'.station_id + WHERE '.$this->config->item('table_name').'.station_id IN ('.implode(', ', $logbooks_locations_array).') ) t2 ON t1.sat = t2.COL_SAT_NAME AND t1.distance = t2.COL_DISTANCE @@ -55,6 +58,8 @@ class Distancerecords_model extends CI_Model { FROM '.$this->config->item('table_name').' WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') AND COALESCE(COL_SAT_NAME, "") <> "" + AND COL_DISTANCE IS NOT NULL + AND COL_GRIDSQUARE IS NOT NULL GROUP BY col_sat_name ORDER BY distance DESC;'; $query = $this->db->query($sql); @@ -64,9 +69,10 @@ class Distancerecords_model extends CI_Model { // With that query for oldest QSO per sat and distance foreach ($query->result() as $row) { $bindings=[]; - $subsql = 'SELECT COL_SAT_NAME AS sat, COL_TIME_ON as time, COL_CALL as callsign, COL_GRIDSQUARE as grid, COL_MODE AS mode, COL_PRIMARY_KEY as primarykey + $subsql = 'SELECT COL_SAT_NAME AS sat, COL_TIME_ON as time, COL_CALL as callsign, COL_GRIDSQUARE as grid, station_profile.station_gridsquare AS mygrid, COL_MODE AS mode, COL_PRIMARY_KEY as primarykey FROM '.$this->config->item('table_name').' - WHERE station_id IN ('.implode(', ', $logbooks_locations_array).') + LEFT JOIN station_profile ON station_profile.station_id = '.$this->config->item('table_name').'.station_id + WHERE '.$this->config->item('table_name').'.station_id IN ('.implode(', ', $logbooks_locations_array).') AND COL_SAT_NAME = ? AND COL_DISTANCE = ? ORDER BY COL_TIME_ON ASC LIMIT 1;'; @@ -74,7 +80,7 @@ class Distancerecords_model extends CI_Model { $bindings[]=$row->distance; $subquery = $this->db->query($subsql, $bindings); $subrow = $subquery->row(); - array_push($result, (object) ["sat" => $row->sat, "distance" => $row->distance, "time" => $subrow->time, "primarykey" => $subrow->primarykey, "callsign" => $subrow->callsign, "mode" => $subrow->mode, "grid" => $subrow->grid]); + array_push($result, (object) ["sat" => $row->sat, "distance" => $row->distance, "time" => $subrow->time, "primarykey" => $subrow->primarykey, "callsign" => $subrow->callsign, "mode" => $subrow->mode, "grid" => $subrow->grid, "mygrid" => $subrow->mygrid]); } return($result); } diff --git a/application/views/distancerecords/index.php b/application/views/distancerecords/index.php index 4df552d0a..6645e1c3a 100644 --- a/application/views/distancerecords/index.php +++ b/application/views/distancerecords/index.php @@ -12,12 +12,13 @@