From 49a6ca53e145a9821565b306f4010bf868bbe195 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 19 Aug 2020 17:23:24 +0200 Subject: [PATCH] Fixed summary to include SAT. Also split the query for the was summary in two. Some configurations of mysql didn't like this type of query. --- application/controllers/Awards.php | 2 +- application/models/Was.php | 56 +++++++++++++++++++------- application/views/awards/was/index.php | 13 +++--- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index ac9bde3a..11d2ed4c 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -346,7 +346,7 @@ class Awards extends CI_Controller { } $data['was_array'] = $this->was->get_was_array($bands, $postdata); - $data['was_summary'] = $this->was->get_was_summary(); + $data['was_summary'] = $this->was->get_was_summary($bands); // Render Page $data['page_title'] = "Awards - WAS (Worked all states)"; diff --git a/application/models/Was.php b/application/models/Was.php index 0e63d42a..6f246eb9 100644 --- a/application/models/Was.php +++ b/application/models/Was.php @@ -135,30 +135,58 @@ class was extends CI_Model { /* * Function gets worked and confirmed summary on each band on the active stationprofile */ - function get_was_summary() { + function get_was_summary($bands) + { $CI =& get_instance(); $CI->load->model('Stations'); $station_id = $CI->Stations->find_active(); - $stateArray = explode(',', $this->stateString); + foreach ($bands as $band) { + $worked = $this->getSummaryByBand($band, $station_id); + $confirmed = $this->getSummaryByBandConfirmed($band, $station_id); + $wasSummary['worked'][$band] = $worked[0]->count; + $wasSummary['confirmed'][$band] = $confirmed[0]->count; + } - $states = array(); // Used for keeping track of which states that are not worked + return $wasSummary; + } - $sql = "SELECT thcv.col_band, count(distinct thcv.col_state) as count, coalesce (cfmwas.count, 0) as cfmwas FROM " . $this->config->item('table_name') . " thcv"; - - $sql .= " left outer join ( - select col_band, count(distinct col_state) as count from " . $this->config->item('table_name') . " thcv"; - $sql .= " where station_id = " . $station_id; - $sql .= $this->addStateToQuery(); - - $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y') - group by col_band"; - $sql .= ") cfmwas on thcv.col_band = cfmwas.col_band "; + function getSummaryByBand($band, $station_id) + { + $sql = "SELECT thcv.col_band, count(distinct thcv.col_state) as count FROM " . $this->config->item('table_name') . " thcv"; $sql .= " where station_id = " . $station_id; + if ($band == 'SAT') { + $sql .= " and thcv.col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and thcv.col_prop_mode !='SAT'"; + $sql .= " and thcv.col_band ='" . $band . "'"; + } + $sql .= $this->addStateToQuery(); - $sql .= " group by thcv.col_band order by thcv.col_band+0 desc"; + + $query = $this->db->query($sql); + + return $query->result(); + } + + function getSummaryByBandConfirmed($band, $station_id) + { + $sql = "SELECT thcv.col_band, count(distinct thcv.col_state) as count FROM " . $this->config->item('table_name') . " thcv"; + + $sql .= " where station_id = " . $station_id; + + if ($band == 'SAT') { + $sql .= " and thcv.col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and thcv.col_prop_mode !='SAT'"; + $sql .= " and thcv.col_band ='" . $band . "'"; + } + + $sql .= $this->addStateToQuery(); + + $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; $query = $this->db->query($sql); diff --git a/application/views/awards/was/index.php b/application/views/awards/was/index.php index b6ec561d..5b0bf30d 100644 --- a/application/views/awards/was/index.php +++ b/application/views/awards/was/index.php @@ -100,9 +100,10 @@ '; - foreach ($was_summary as $was) { // Fills the table with the data - echo '' . $was->col_band . ''; + foreach($bands as $band) { + echo '' . $band . ''; } + echo ''; echo ' @@ -110,14 +111,14 @@ Total worked'; - foreach ($was_summary as $was) { // Fills the table with the data - echo '' . $was->count . ''; + foreach ($was_summary['worked'] as $was) { // Fills the table with the data + echo '' . $was . ''; } echo ' Total confirmed'; - foreach ($was_summary as $was) { // Fills the table with the data - echo '' . $was->cfmwas . ''; + foreach ($was_summary['confirmed'] as $was) { // Fills the table with the data + echo '' . $was . ''; } echo '