diff --git a/application/controllers/Dayswithqso.php b/application/controllers/Dayswithqso.php index c82567b55..5d3262cc0 100644 --- a/application/controllers/Dayswithqso.php +++ b/application/controllers/Dayswithqso.php @@ -11,16 +11,16 @@ class Dayswithqso extends CI_Controller { if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); } } - public function index() - { - $this->load->model('dayswithqso_model'); + public function index() { + $this->load->model('dayswithqso_model'); // Render Page - $data['page_title'] = __("Number of days with QSOs each year"); + $data['page_title'] = __("Days with QSOs"); $data['result'] = $this->dayswithqso_model->getDaysWithQso(); $data['streaks'] = $this->dayswithqso_model->getLongestStreak(); $data['currentstreak'] = $this->dayswithqso_model->getCurrentStreak(); $data['almostcurrentstreak'] = $this->dayswithqso_model->getAlmostCurrentStreak(); + $data['daysofweek'] = $this->dayswithqso_model->getDaysOfWeek(); $this->load->view('interface_assets/header', $data); $this->load->view('dayswithqso/index'); @@ -38,4 +38,14 @@ class Dayswithqso extends CI_Controller { echo json_encode($data); } -} \ No newline at end of file + public function get_weekdays() { + //load model + $this->load->model('dayswithqso_model'); + + // get data + $data = $this->dayswithqso_model->getDaysOfWeek(); + header('Content-Type: application/json'); + echo json_encode($data); + } + +} diff --git a/application/models/Dayswithqso_model.php b/application/models/Dayswithqso_model.php index cd5850086..2a895d4a6 100644 --- a/application/models/Dayswithqso_model.php +++ b/application/models/Dayswithqso_model.php @@ -5,9 +5,8 @@ class Dayswithqso_model extends CI_Model { function getDaysWithQso() { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + $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; @@ -34,13 +33,13 @@ class Dayswithqso_model extends CI_Model $dates = array_reverse($dates); $streak = 1; $firstrun = true; - + $dateprev = date_create(date('Y-m-d')); - + foreach($dates as $date) { // Loop through the result set $datecurr = date_create($date->date?? '1970-01-01 00:00:00'); $diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array - + if ($diff == 0) { $streaks['highstreak'] = $streak; $streaks['endstreak'] = $datecurr->format('Y-m-d'); @@ -55,7 +54,7 @@ class Dayswithqso_model extends CI_Model } $dateprev = date_create($date->date ?? '1970-01-01 00:00:00'); } - + if (isset($streaks) && is_array($streaks)) { return $streaks; } else { @@ -74,13 +73,13 @@ class Dayswithqso_model extends CI_Model $dates = array_reverse($dates); $streak = 1; $firstrun = true; - + $dateprev = date_create(date('Y-m-d')); - + foreach($dates as $date) { // Loop through the result set $datecurr = date_create($date->date ?? '1970-01-01 00:00:00'); $diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array - + if ($diff == 1 && $firstrun == true) { $streaks['highstreak'] = $streak++; $streaks['endstreak'] = $datecurr->format('Y-m-d'); @@ -95,7 +94,7 @@ class Dayswithqso_model extends CI_Model } $dateprev = date_create($date->date); } - + if (isset($streaks) && is_array($streaks)) { return $streaks; } else { @@ -137,7 +136,7 @@ class Dayswithqso_model extends CI_Model $dateprev = date_create($date->date); } } - + if (isset($streaks) && is_array($streaks)) { @@ -161,9 +160,8 @@ class Dayswithqso_model extends CI_Model * Returns all distinct dates from db on active profile */ function getDates() { - $CI =& get_instance(); - $CI->load->model('logbooks_model'); - $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + $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; @@ -180,4 +178,26 @@ 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 getDaysOfWeek() { + $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 DAYNAME(col_time_off) AS weekday, COUNT(*) AS qsos FROM " . $this->config->item('table_name') + . " WHERE WEEKDAY(col_time_off) BETWEEN 0 AND 6 AND station_id in (" . $location_list . ")" + . " GROUP BY weekday ORDER BY FIELD(weekday, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')"; + + $query = $this->db->query($sql); + + return $query->result(); + } + } diff --git a/application/views/dayswithqso/index.php b/application/views/dayswithqso/index.php index 0d3ef585c..015457889 100644 --- a/application/views/dayswithqso/index.php +++ b/application/views/dayswithqso/index.php @@ -1,125 +1,156 @@
-
-

- '; +
+
+ +
- echo ''; - echo ''; +
+
+
+

+
+
' . __("Year") . '
'; - foreach ($result as $master) { - echo ''; - } + echo ''; + echo ''; - echo ''; + foreach ($result as $master) { + echo ''; + } - echo ''; - echo ''; + echo ''; - foreach ($result as $master) { - echo ''; - } + echo ''; + echo ''; - echo ''; + foreach ($result as $master) { + echo ''; + } - echo '
' . $master->Year . '
' . __("Year") . '
' . $master->Year . '
' . __("Days") . '
' . $master->Days . '
' . __("Days") . '
' . $master->Days . '
'; - } - ?> - -

-

+ echo ''; - session->userdata('user_date_format')) { - // If Logged in and session exists - $custom_date_format = $this->session->userdata('user_date_format'); - } else { - // Get Default date format from /config/wavelog.php - $custom_date_format = $this->config->item('qso_date_format'); - } - ?> + echo ''; + } + ?> + + - '; +
+
+

+ +
- echo ''; - echo ''; +
+
+

+

+ + session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $this->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/wavelog.php + $custom_date_format = $this->config->item('qso_date_format'); + } + ?> + +
' . __("Streak (continuous days with QSOs)") . '
'; + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + foreach ($streaks as $streak) { + echo ''; + echo ''; + $beginstreak_newdate = strtotime($streak['beginstreak']); + echo ''; + $endstreak_newdate = strtotime($streak['endstreak']); + echo ''; + echo ''; + } + + echo '
' . __("Streak (continuous days with QSOs)") . '' . __("Start Date") . '' . __("End Date") . '
' . $streak['highstreak'] . '' . date($custom_date_format, $beginstreak_newdate) . '' . date($custom_date_format, $endstreak_newdate) . '
'; + } + else { + echo ''; + } + ?> + +

+ '; + + echo ''; + echo ''; echo ''; echo ''; echo ''; - foreach ($streaks as $streak) { + echo ''; + echo ''; + $beginstreak_newdate = strtotime($currentstreak['beginstreak']); + echo ''; + $endstreak_newdate = strtotime($currentstreak['endstreak']); + echo ''; + echo ''; + + echo '
' . __("Current streak (continuous days with QSOs)") . '' . __("Start Date") . '' . __("End Date") . '
' . $currentstreak['highstreak'] . '' . date($custom_date_format, $beginstreak_newdate) . '' . date($custom_date_format, $endstreak_newdate) . '
'; + } + elseif (is_array($almostcurrentstreak)) { + ?> + + '; + echo ''; - echo ''; - $beginstreak_newdate = strtotime($streak['beginstreak']); + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; + $beginstreak_newdate = strtotime($almostcurrentstreak['beginstreak']); echo ''; - $endstreak_newdate = strtotime($streak['endstreak']); + $endstreak_newdate = strtotime($almostcurrentstreak['endstreak']); echo ''; echo ''; + + echo '
' . $streak['highstreak'] . '' . __("Current streak (continuous days with QSOs)") . '' . __("Start Date") . '' . __("End Date") . '
' . $almostcurrentstreak['highstreak'] . '' . date($custom_date_format, $beginstreak_newdate) . '' . date($custom_date_format, $endstreak_newdate) . '
'; } - - echo ''; - } - else { - echo ''; - } - ?> - -

- '; - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - echo ''; - echo ''; - $beginstreak_newdate = strtotime($currentstreak['beginstreak']); - echo ''; - $endstreak_newdate = strtotime($currentstreak['endstreak']); - echo ''; - echo ''; - - echo '
' . __("Current streak (continuous days with QSOs)") . '' . __("Start Date") . '' . __("End Date") . '
' . $currentstreak['highstreak'] . '' . date($custom_date_format, $beginstreak_newdate) . '' . date($custom_date_format, $endstreak_newdate) . '
'; - } - elseif (is_array($almostcurrentstreak)) { - ?> - - '; - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - echo ''; - echo ''; - $beginstreak_newdate = strtotime($almostcurrentstreak['beginstreak']); - echo ''; - $endstreak_newdate = strtotime($almostcurrentstreak['endstreak']); - echo ''; - echo ''; - - echo '
' . __("Current streak (continuous days with QSOs)") . '' . __("Start Date") . '' . __("End Date") . '
' . $almostcurrentstreak['highstreak'] . '' . date($custom_date_format, $beginstreak_newdate) . '' . date($custom_date_format, $endstreak_newdate) . '
'; - } - else { - echo ''; - } - ?> + else { + echo ''; + } + ?> + + diff --git a/assets/js/sections/dayswithqso.js b/assets/js/sections/dayswithqso.js index e825a0697..c99d8849d 100644 --- a/assets/js/sections/dayswithqso.js +++ b/assets/js/sections/dayswithqso.js @@ -1,51 +1,110 @@ -$.ajax({ - url: base_url + 'index.php/dayswithqso/get_days', - success: function (data) { - if ($.trim(data)) { - var labels = []; - var dataDxcc = []; - $.each(data, function () { - labels.push(this.Year); - dataDxcc.push(this.Days); - }); - var ctx = document.getElementById("myChartDiff").getContext('2d'); - var color = ifDarkModeThemeReturn('white', 'grey'); - var myChart = new Chart(ctx, { - type: 'bar', - data: { - labels: labels, - datasets: [{ - label: lang_days_with_qso_short, - data: dataDxcc, - 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 +daysPerYear(); +weekDays(); + +function daysPerYear() { + $.ajax({ + url: base_url + 'index.php/dayswithqso/get_days', + success: function (data) { + if ($.trim(data)) { + var labels = []; + var dataDxcc = []; + $.each(data, function () { + labels.push(this.Year); + dataDxcc.push(this.Days); + }); + var ctx = document.getElementById("myChartDiff").getContext('2d'); + var color = ifDarkModeThemeReturn('white', 'grey'); + var myChart = new Chart(ctx, { + type: 'bar', + data: { + labels: labels, + datasets: [{ + label: lang_days_with_qso_short, + data: dataDxcc, + 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 + } } }, - x: { - ticks: { - color: color - } - } - }, - plugins: { - legend: { - labels: { - color: color + plugins: { + legend: { + labels: { + color: color + } } } } - } - }); + }); + } } - } -}); + }); +} + +function weekDays() { + $.ajax({ + url: base_url + 'index.php/dayswithqso/get_weekdays', + success: function (data) { + if ($.trim(data)) { + var labels = []; + var dataDays = []; + $.each(data, function () { + labels.push(this.weekday); + dataDays.push(this.qsos); + }); + var ctx = document.getElementById("weekdaysChart").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 + } + } + } + } + }); + } + } + }); +}