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 @@