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 @@
| ' . __("Year") . ' | '; +
|---|
| ' . $master->Year . ' | '; - } + echo '
| ' . __("Year") . ' | '; - echo '' . $master->Year . ' | '; + } - echo '
|---|
| ' . __("Days") . ' | '; + echo '' . $master->Days . ' | '; - } + echo '
| ' . __("Days") . ' | '; - echo '' . $master->Days . ' | '; + } - echo '
= __("A maximum of the 10 longest streaks are shown!"); ?>
+ echo '| ' . __("Streak (continuous days with QSOs)") . ' | '; +
|---|
| ' . __("Streak (continuous days with QSOs)") . ' | '; + echo '' . __("Start Date") . ' | '; + echo '' . __("End Date") . ' | '; + echo '
|---|---|---|
| ' . $streak['highstreak'] . ' | '; + $beginstreak_newdate = strtotime($streak['beginstreak']); + echo '' . date($custom_date_format, $beginstreak_newdate) . ' | '; + $endstreak_newdate = strtotime($streak['endstreak']); + echo '' . date($custom_date_format, $endstreak_newdate) . ' | '; + echo '
| ' . __("Current streak (continuous days with QSOs)") . ' | '; echo '' . __("Start Date") . ' | '; echo '' . __("End Date") . ' | '; echo '
|---|---|---|
| ' . $currentstreak['highstreak'] . ' | '; + $beginstreak_newdate = strtotime($currentstreak['beginstreak']); + echo '' . date($custom_date_format, $beginstreak_newdate) . ' | '; + $endstreak_newdate = strtotime($currentstreak['endstreak']); + echo '' . date($custom_date_format, $endstreak_newdate) . ' | '; + echo '
| ' . $streak['highstreak'] . ' | '; - $beginstreak_newdate = strtotime($streak['beginstreak']); + echo '' . __("Current streak (continuous days with QSOs)") . ' | '; + echo '' . __("Start Date") . ' | '; + echo '' . __("End Date") . ' | '; + echo '
|---|---|---|---|
| ' . $almostcurrentstreak['highstreak'] . ' | '; + $beginstreak_newdate = strtotime($almostcurrentstreak['beginstreak']); echo '' . date($custom_date_format, $beginstreak_newdate) . ' | '; - $endstreak_newdate = strtotime($streak['endstreak']); + $endstreak_newdate = strtotime($almostcurrentstreak['endstreak']); echo '' . date($custom_date_format, $endstreak_newdate) . ' | '; echo '
| ' . __("Current streak (continuous days with QSOs)") . ' | '; - echo '' . __("Start Date") . ' | '; - echo '' . __("End Date") . ' | '; - echo '
|---|---|---|
| ' . $currentstreak['highstreak'] . ' | '; - $beginstreak_newdate = strtotime($currentstreak['beginstreak']); - echo '' . date($custom_date_format, $beginstreak_newdate) . ' | '; - $endstreak_newdate = strtotime($currentstreak['endstreak']); - echo '' . date($custom_date_format, $endstreak_newdate) . ' | '; - echo '
| ' . __("Current streak (continuous days with QSOs)") . ' | '; - echo '' . __("Start Date") . ' | '; - echo '' . __("End Date") . ' | '; - echo '
|---|---|---|
| ' . $almostcurrentstreak['highstreak'] . ' | '; - $beginstreak_newdate = strtotime($almostcurrentstreak['beginstreak']); - echo '' . date($custom_date_format, $beginstreak_newdate) . ' | '; - $endstreak_newdate = strtotime($almostcurrentstreak['endstreak']); - echo '' . date($custom_date_format, $endstreak_newdate) . ' | '; - echo '