From 20dc1caa27bfbc4f5fd1eef9e7f61805b220ded4 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 6 Oct 2020 21:12:14 +0200 Subject: [PATCH] Implemented dynamic loading of chart and table. Band and award is now selectable. --- application/controllers/Accumulated.php | 37 ++--- application/models/Accumulate_model.php | 127 +++++++++++++++++- application/views/accumulate/index.php | 81 +++++------ application/views/interface_assets/footer.php | 106 +++++++++++++++ 4 files changed, 286 insertions(+), 65 deletions(-) diff --git a/application/controllers/Accumulated.php b/application/controllers/Accumulated.php index a943c06c..e8bcfe48 100644 --- a/application/controllers/Accumulated.php +++ b/application/controllers/Accumulated.php @@ -18,39 +18,26 @@ class Accumulated extends CI_Controller { $this->load->model('Accumulate_model'); - if ($this->input->post('band') != NULL) { // Band is not set when page first loads. - $band = $this->input->post('band'); - } - else { - $band = 'All'; - } - - $data['accumulated_dxcc_array'] = $this->Accumulate_model->get_accumulated_dxcc($band); $data['worked_bands'] = $this->Accumulate_model->get_worked_bands(); - $data['bandselect'] = $band; $this->load->view('interface_assets/header', $data); $this->load->view('accumulate/index'); $this->load->view('interface_assets/footer'); } - public function details() { - $this->load->model('logbook_model'); + /* + * Used for ajax-call in javascript to fetch the data and insert into table and chart + */ + public function get_accumulated_data(){ + //load model + $this->load->model('accumulate_model'); + $band = $this->input->post('Band'); + $award = $this->input->post('Award'); - $adif = str_replace('"', "", $this->input->post("Adif")); - $country = $this->logbook_model->get_entity($adif); - $band = str_replace('"', "", $this->input->post("Band")); - $data['results'] = $this->logbook_model->timeline_qso_details($adif, $band); - - // Render Page - $data['page_title'] = "Log View - DXCC"; - $data['filter'] = "country ". $country['name']; - - if ($band != "All") { - $data['filter'] .= " and " . $band; - } - - $this->load->view('timeline/details', $data); + // get data + $data = $this->accumulate_model->get_accumulated_data($band, $award); + header('Content-Type: application/json'); + echo json_encode($data); } } \ No newline at end of file diff --git a/application/models/Accumulate_model.php b/application/models/Accumulate_model.php index 9eaa2416..709b8da1 100644 --- a/application/models/Accumulate_model.php +++ b/application/models/Accumulate_model.php @@ -9,11 +9,22 @@ class Accumulate_model extends CI_Model parent::__construct(); } - function get_accumulated_dxcc($band) { + function get_accumulated_data($band, $award) { $CI =& get_instance(); $CI->load->model('Stations'); $station_id = $CI->Stations->find_active(); + switch ($award) { + case 'dxcc': $result = $this->get_accumulated_dxcc($band, $station_id); break; + case 'was': $result = $this->get_accumulated_was($band, $station_id); break; + case 'iota': $result = $this->get_accumulated_iota($band, $station_id); break; + case 'waz': $result = $this->get_accumulated_waz($band, $station_id); break; + } + + return $result; + } + + function get_accumulated_dxcc($band, $station_id) { $sql = "SELECT year(col_time_on) as year, (select count(distinct b.col_dxcc) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id; @@ -29,6 +40,120 @@ class Accumulate_model extends CI_Model $sql .=") total from " . $this->config->item('table_name') . " as a where a.station_id = ". $station_id; + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + $sql .= " group by year(a.col_time_on) + order by year(a.col_time_on)"; + + $query = $this->db->query($sql); + + return $query->result(); + } + + function get_accumulated_was($band, $station_id) { + $sql = "SELECT year(col_time_on) as year, + (select count(distinct b.col_state) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + $sql .= " and COL_DXCC in ('291', '6', '110')"; + $sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')"; + + $sql .=") total from " . $this->config->item('table_name') . " as a + where a.station_id = ". $station_id; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + $sql .= " and COL_DXCC in ('291', '6', '110')"; + $sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')"; + + $sql .= " group by year(a.col_time_on) + order by year(a.col_time_on)"; + + $query = $this->db->query($sql); + + return $query->result(); + } + + function get_accumulated_iota($band, $station_id) { + $sql = "SELECT year(col_time_on) as year, + (select count(distinct b.col_iota) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + $sql .=") total from " . $this->config->item('table_name') . " as a + where a.station_id = ". $station_id; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + $sql .= " group by year(a.col_time_on) + order by year(a.col_time_on)"; + + $query = $this->db->query($sql); + + return $query->result(); + } + + function get_accumulated_waz($band, $station_id) { + $sql = "SELECT year(col_time_on) as year, + (select count(distinct b.col_cqz) from " . $this->config->item('table_name') . " as b where year(col_time_on) <= year and b.station_id = ". $station_id; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + $sql .=") total from " . $this->config->item('table_name') . " as a + where a.station_id = ". $station_id; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + $sql .= " group by year(a.col_time_on) order by year(a.col_time_on)"; diff --git a/application/views/accumulate/index.php b/application/views/accumulate/index.php index afc96360..1a2f7089 100644 --- a/application/views/accumulate/index.php +++ b/application/views/accumulate/index.php @@ -1,59 +1,62 @@

-
-
+ +
- + input->post('band') == $band) echo ' selected'; - echo '>' . $band . ''."\n"; + echo ''."\n"; } ?>
- - -
- -
- +
+
+ + +
+
+ + +
+
+ + +
+
+ +
-
+ + +
+
+ +
+
+ +
- - - - # - Year - Accumulated # of DXCC\'s worked - - - '; +
+ +
+
- foreach ($accumulated_dxcc_array as $line) { - echo ' - ' . $i++ . ' - ' . $line->year . ' - ' . $line->total . ' - '; - } - echo '
'; - } - else { - echo ''; - } - ?> diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 0d3e8e32..573f9ce6 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -1790,6 +1790,112 @@ $(document).ready(function(){ +uri->segment(1) == "accumulated") { ?> + + +