diff --git a/application/controllers/Dayswithqso.php b/application/controllers/Dayswithqso.php index 5d3262cc0..f280632f4 100644 --- a/application/controllers/Dayswithqso.php +++ b/application/controllers/Dayswithqso.php @@ -48,4 +48,14 @@ class Dayswithqso extends CI_Controller { echo json_encode($data); } + public function get_months() { + //load model + $this->load->model('dayswithqso_model'); + + // get data + $data = $this->dayswithqso_model->getMonthsOfYear(); + header('Content-Type: application/json'); + echo json_encode($data); + } + } diff --git a/application/models/Dayswithqso_model.php b/application/models/Dayswithqso_model.php index 2a895d4a6..452ec7c77 100644 --- a/application/models/Dayswithqso_model.php +++ b/application/models/Dayswithqso_model.php @@ -200,4 +200,31 @@ class Dayswithqso_model extends CI_Model return $query->result(); } + /* + * Returns the total number of QSOs made for each day of the week (Monday to Sunday) + */ + function getMonthsOfYear() { + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + if (!$logbooks_locations_array) { + return null; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $sql = "SELECT MONTHNAME(col_time_off) AS month, COUNT(*) AS qsos + FROM " . $this->config->item('table_name') . " + WHERE MONTH(col_time_off) BETWEEN 1 AND 12 + AND station_id IN (" . $location_list . ") + GROUP BY month + ORDER BY FIELD(month, 'January', 'February', 'March', 'April', 'May', 'June', + 'July', 'August', 'September', 'October', 'November', 'December')"; + + + $query = $this->db->query($sql); + + return $query->result(); + } + } diff --git a/application/views/dayswithqso/index.php b/application/views/dayswithqso/index.php index b5582371a..e10cfc69f 100644 --- a/application/views/dayswithqso/index.php +++ b/application/views/dayswithqso/index.php @@ -16,6 +16,9 @@ + @@ -61,6 +64,12 @@ +
+
+

+ +
+

diff --git a/assets/js/sections/dayswithqso.js b/assets/js/sections/dayswithqso.js index c99d8849d..fc5061924 100644 --- a/assets/js/sections/dayswithqso.js +++ b/assets/js/sections/dayswithqso.js @@ -1,5 +1,6 @@ daysPerYear(); weekDays(); +months(); function daysPerYear() { $.ajax({ @@ -108,3 +109,57 @@ function weekDays() { } }); } + +function months() { + $.ajax({ + url: base_url + 'index.php/dayswithqso/get_months', + success: function (data) { + if ($.trim(data)) { + var labels = []; + var dataDays = []; + $.each(data, function () { + labels.push(this.month); + dataDays.push(this.qsos); + }); + var ctx = document.getElementById("monthChart").getContext('2d'); + var color = ifDarkModeThemeReturn('white', 'grey'); + var myChart = new Chart(ctx, { + type: 'bar', + data: { + labels: labels, + datasets: [{ + label: lang_qsos_this_weekday, + data: dataDays, + backgroundColor: 'rgba(54, 162, 235, 0.2)', + borderColor: 'rgba(54, 162, 235, 1)', + borderWidth: 2, + color: color + }] + }, + options: { + scales: { + y: { + ticks: { + beginAtZero: true, + color: color + } + }, + x: { + ticks: { + color: color + } + } + }, + plugins: { + legend: { + labels: { + color: color + } + } + } + } + }); + } + } + }); +}