From cb71e0961fddb2056642263603d6504986a01cbf Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Mon, 1 May 2023 12:35:24 +0200 Subject: [PATCH] [Advanced Logbook] ADIF export fetches sort order from table sort (not all columns) --- application/controllers/Logbookadvanced.php | 3 ++- application/models/Logbookadvanced_model.php | 19 +++++++++++++++++-- assets/js/sections/logbookadvanced.js | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index fd48b189..6f054479 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -125,9 +125,10 @@ class Logbookadvanced extends CI_Controller { $this->load->model('logbookadvanced_model'); $ids = xss_clean($this->input->post('id')); + $sortorder = xss_clean($this->input->post('sortorder')); $user_id = (int)$this->session->userdata('user_id'); - $data['qsos'] = $this->logbookadvanced_model->getQsosForAdif($ids, $user_id); + $data['qsos'] = $this->logbookadvanced_model->getQsosForAdif($ids, $user_id, $sortorder); $this->load->view('adif/data/exportall', $data); } diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index 019fe030..4317ad51 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -112,7 +112,7 @@ class Logbookadvanced_model extends CI_Model { return $qsos; } - public function getQsosForAdif($ids, $user_id) : object { + public function getQsosForAdif($ids, $user_id, $sortorder) : object { $binding = [$user_id]; $conditions[] = "COL_PRIMARY_KEY in ?"; $binding[] = json_decode($ids, true); @@ -122,6 +122,21 @@ class Logbookadvanced_model extends CI_Model { $where = "AND $where"; } + $sortorder = explode(',', $sortorder); + + switch($sortorder[0]) { + case 1: $order = 'ORDER BY qsos.COL_TIME_ON ' . $sortorder[1]; break; + case 2: $order = 'ORDER BY station_profile.station_callsign ' . $sortorder[1]; break; + case 3: $order = 'ORDER BY qsos.COL_CALL ' . $sortorder[1]; break; + case 4: $order = 'ORDER BY qsos.COL_MODE' . $sortorder[1] . ', qsos.COL_SUBMODE ' . $sortorder[1]; break; + case 7: $order = 'ORDER BY qsos.COL_BAND ' . $sortorder[1] . ', qsos.COL_SAT_NAME ' . $sortorder[1]; break; + case 15: $order = 'ORDER BY qsos.COL_COUNTRY ' . $sortorder[1]; break; + case 16: $order = 'ORDER BY qso.COL_STATE ' . $sortorder[1]; break; + case 17: $order = 'ORDER BY qsos.COL_CQZ ' . $sortorder[1]; break; + case 18: $order = 'ORDER BY qsos.COL_IOTA ' . $sortorder[1]; break; + default: $order = 'ORDER BY qsos.COL_TIME_ON desc'; break; + } + $sql = " SELECT *, dxcc_entities.name AS station_country FROM " . $this->config->item('table_name') . " qsos @@ -129,7 +144,7 @@ class Logbookadvanced_model extends CI_Model { LEFT OUTER JOIN dxcc_entities ON qsos.COL_MY_DXCC = dxcc_entities.adif WHERE station_profile.user_id = ? $where - ORDER BY qsos.COL_TIME_ON desc + $order "; return $this->db->query($sql, $binding); diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 83c2c796..7a4c9747 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -50,7 +50,7 @@ function loadQSOTable(rows) { "scrollCollapse": true, "paging": false, "scrollX": true, - "order": [ 0, 'asc' ], + "order": [ 1, 'desc' ], }); }); @@ -293,7 +293,7 @@ $(document).ready(function () { xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // You should set responseType as blob for binary responses xhttp.responseType = 'blob'; - xhttp.send("id=" + JSON.stringify(id_list, null, 2)); + xhttp.send("id=" + JSON.stringify(id_list, null, 2)+"&sortorder=" +$('.table').DataTable().order()); $('#exportAdif').prop("disabled", false); });