From 5622c488a74abdca231b588002b103289a0a43e7 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 9 Sep 2021 18:14:41 +0200 Subject: [PATCH] [CQ Award] Updated code to support station logbooks --- application/controllers/Awards.php | 3 +-- application/models/Dok.php | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index 81851366..f43121a4 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -27,7 +27,6 @@ class Awards extends CI_Controller { public function dok () { - //echo "Needs Developed"; $this->load->model('dok'); $data['doks'] = $this->dok->show_stats(); $data['worked_bands'] = $this->dok->get_worked_bands(); @@ -226,7 +225,7 @@ class Awards extends CI_Controller { $this->load->view('interface_assets/footer'); } - public function cq(){ + public function cq() { $CI =& get_instance(); $CI->load->model('logbooks_model'); $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); diff --git a/application/models/Dok.php b/application/models/Dok.php index 2a9653e5..4ff23211 100644 --- a/application/models/Dok.php +++ b/application/models/Dok.php @@ -31,12 +31,14 @@ class DOK extends CI_Model { function get_worked_bands() { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; // get all worked slots from database $data = $this->db->query( - "SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` WHERE station_id = ".$station_id." AND COL_DARC_DOK IS NOT NULL AND COL_DARC_DOK != '' AND COL_DXCC = 230 " + "SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` WHERE station_id in (" . $location_list . ") AND COL_DARC_DOK IS NOT NULL AND COL_DARC_DOK != '' AND COL_DXCC = 230 " ); $worked_slots = array(); foreach($data->result() as $row){ @@ -49,19 +51,21 @@ class DOK extends CI_Model { foreach(array_keys($this->bandslots) as $slot) { if(in_array($slot, $worked_slots)) { array_push($results, $slot); - } + } } return $results; } - function show_stats(){ + function show_stats() { $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; $data = $this->db->query( "select upper(COL_DARC_DOK) as COL_DARC_DOK, COL_MODE, lcase(COL_BAND) as COL_BAND, count(COL_DARC_DOK) as cnt - from ".$this->config->item('table_name')." WHERE station_id = ".$station_id." AND COL_DARC_DOK IS NOT NULL AND COL_DARC_DOK != '' AND COL_DXCC = 230 + from ".$this->config->item('table_name')." WHERE station_id in (" . $location_list . ") AND COL_DARC_DOK IS NOT NULL AND COL_DARC_DOK != '' AND COL_DXCC = 230 group by COL_DARC_DOK, COL_MODE, COL_BAND" ); @@ -76,14 +80,14 @@ class DOK extends CI_Model { // update stats if (!isset($results[$row->COL_DARC_DOK])) - $results[$row->COL_DARC_DOK] = []; + $results[$row->COL_DARC_DOK] = []; if (!isset($results[$row->COL_DARC_DOK][$row->COL_BAND])) - $results[$row->COL_DARC_DOK][$row->COL_BAND] = 0; + $results[$row->COL_DARC_DOK][$row->COL_BAND] = 0; $results[$row->COL_DARC_DOK][$row->COL_BAND] += $row->cnt; } - + return $results; }