diff --git a/application/models/Accumulate_model.php b/application/models/Accumulate_model.php index 72c1b132..5e659066 100644 --- a/application/models/Accumulate_model.php +++ b/application/models/Accumulate_model.php @@ -10,32 +10,34 @@ class Accumulate_model extends CI_Model } function get_accumulated_data($band, $award, $mode, $period) { - $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI =& get_instance(); + $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)."'"; switch ($award) { - case 'dxcc': $result = $this->get_accumulated_dxcc($band, $mode, $period, $station_id); break; - case 'was': $result = $this->get_accumulated_was($band, $mode, $period, $station_id); break; - case 'iota': $result = $this->get_accumulated_iota($band, $mode, $period, $station_id); break; - case 'waz': $result = $this->get_accumulated_waz($band, $mode, $period, $station_id); break; + case 'dxcc': $result = $this->get_accumulated_dxcc($band, $mode, $period, $location_list); break; + case 'was': $result = $this->get_accumulated_was($band, $mode, $period, $location_list); break; + case 'iota': $result = $this->get_accumulated_iota($band, $mode, $period, $location_list); break; + case 'waz': $result = $this->get_accumulated_waz($band, $mode, $period, $location_list); break; } return $result; } - function get_accumulated_dxcc($band, $mode, $period, $station_id) { + function get_accumulated_dxcc($band, $mode, $period, $location_list) { if ($period == "year") { $sql = "SELECT year(col_time_on) as year, (select count(distinct b.col_dxcc) from " . $this->config->item('table_name') . - " as b where year(col_time_on) <= year and b.station_id = ". $station_id; + " as b where year(col_time_on) <= year and b.station_id in (". $location_list . ")"; } else if ($period == "month") { $sql = "SELECT date_format(col_time_on, '%Y%m') as year, (select count(distinct b.col_dxcc) from " . $this->config->item('table_name') . - " as b where date_format(col_time_on, '%Y%m') <= year and b.station_id = ". $station_id; + " as b where date_format(col_time_on, '%Y%m') <= year and b.station_id in (". $location_list . ")"; } if ($band != 'All') { @@ -48,11 +50,11 @@ class Accumulate_model extends CI_Model } if ($mode != 'All') { - $sql .= " and col_mode ='" . $mode . "'"; + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; } - $sql .=") total from " . $this->config->item('table_name') . " as a - where a.station_id = ". $station_id; + $sql .=" and b.col_dxcc > 0) total from " . $this->config->item('table_name') . " as a + where a.station_id in (". $location_list . ")"; if ($band != 'All') { if ($band == 'SAT') { @@ -64,15 +66,17 @@ class Accumulate_model extends CI_Model } if ($mode != 'All') { - $sql .= " and col_mode ='" . $mode . "'"; + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; } + $sql .= " and col_dxcc > 0"; + if ($period == "year") { - $sql .= " group by year(a.col_time_on) + $sql .= " group by year(a.col_time_on) order by year(a.col_time_on)"; } else if ($period == "month") { - $sql .= " group by date_format(a.col_time_on, '%Y%m') + $sql .= " group by date_format(a.col_time_on, '%Y%m') order by date_format(a.col_time_on, '%Y%m')"; } @@ -81,18 +85,18 @@ class Accumulate_model extends CI_Model return $query->result(); } - function get_accumulated_was($band, $mode, $period, $station_id) { + function get_accumulated_was($band, $mode, $period, $location_list) { if ($period == "year") { $sql = "SELECT year(col_time_on) as year, (select count(distinct b.col_state) from " . $this->config->item('table_name') . - " as b where year(col_time_on) <= year and b.station_id = ". $station_id; + " as b where year(col_time_on) <= year and b.station_id in (". $location_list . ")"; } else if ($period == "month") { $sql = "SELECT date_format(col_time_on, '%Y%m') as year, (select count(distinct b.col_state) from " . $this->config->item('table_name') . - " as b where date_format(col_time_on, '%Y%m') <= year and b.station_id = ". $station_id; + " as b where date_format(col_time_on, '%Y%m') <= year and b.station_id in (". $location_list . ")"; } if ($band != 'All') { @@ -105,14 +109,14 @@ class Accumulate_model extends CI_Model } if ($mode != 'All') { - $sql .= " and col_mode ='" . $mode . "'"; + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; } $sql .= " and COL_DXCC in ('291', '6', '110')"; $sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')"; $sql .=") total from " . $this->config->item('table_name') . " as a - where a.station_id = ". $station_id; + where a.station_id in (". $location_list . ")"; if ($band != 'All') { if ($band == 'SAT') { @@ -124,18 +128,18 @@ class Accumulate_model extends CI_Model } if ($mode != 'All') { - $sql .= " and col_mode ='" . $mode . "'"; + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; } $sql .= " and COL_DXCC in ('291', '6', '110')"; $sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')"; if ($period == "year") { - $sql .= " group by year(a.col_time_on) + $sql .= " group by year(a.col_time_on) order by year(a.col_time_on)"; } else if ($period == "month") { - $sql .= " group by date_format(a.col_time_on, '%Y%m') + $sql .= " group by date_format(a.col_time_on, '%Y%m') order by date_format(a.col_time_on, '%Y%m')"; } @@ -144,18 +148,18 @@ class Accumulate_model extends CI_Model return $query->result(); } - function get_accumulated_iota($band, $mode, $period, $station_id) { + function get_accumulated_iota($band, $mode, $period, $location_list) { if ($period == "year") { $sql = "SELECT year(col_time_on) as year, (select count(distinct b.col_iota) from " . $this->config->item('table_name') . - " as b where year(col_time_on) <= year and b.station_id = ". $station_id; + " as b where year(col_time_on) <= year and b.station_id in (". $location_list . ")"; } else if ($period == "month") { $sql = "SELECT date_format(col_time_on, '%Y%m') as year, (select count(distinct b.col_iota) from " . $this->config->item('table_name') . - " as b where date_format(col_time_on, '%Y%m') <= year and b.station_id = ". $station_id; + " as b where date_format(col_time_on, '%Y%m') <= year and b.station_id in (". $location_list . ")"; } if ($band != 'All') { @@ -168,11 +172,11 @@ class Accumulate_model extends CI_Model } if ($mode != 'All') { - $sql .= " and col_mode ='" . $mode . "'"; + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; } $sql .=") total from " . $this->config->item('table_name') . " as a - where a.station_id = ". $station_id; + where a.station_id in (". $location_list . ")"; if ($band != 'All') { if ($band == 'SAT') { @@ -184,15 +188,15 @@ class Accumulate_model extends CI_Model } if ($mode != 'All') { - $sql .= " and col_mode ='" . $mode . "'"; + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; } if ($period == "year") { - $sql .= " group by year(a.col_time_on) + $sql .= " group by year(a.col_time_on) order by year(a.col_time_on)"; } else if ($period == "month") { - $sql .= " group by date_format(a.col_time_on, '%Y%m') + $sql .= " group by date_format(a.col_time_on, '%Y%m') order by date_format(a.col_time_on, '%Y%m')"; } @@ -201,18 +205,18 @@ class Accumulate_model extends CI_Model return $query->result(); } - function get_accumulated_waz($band, $mode, $period, $station_id) { + function get_accumulated_waz($band, $mode, $period, $location_list) { if ($period == "year") { $sql = "SELECT year(col_time_on) as year, (select count(distinct b.col_cqz) from " . $this->config->item('table_name') . - " as b where year(col_time_on) <= year and b.station_id = ". $station_id; + " as b where year(col_time_on) <= year and b.station_id in (". $location_list . ")"; } else if ($period == "month") { $sql = "SELECT date_format(col_time_on, '%Y%m') as year, (select count(distinct b.col_cqz) from " . $this->config->item('table_name') . - " as b where date_format(col_time_on, '%Y%m') <= year and b.station_id = ". $station_id; + " as b where date_format(col_time_on, '%Y%m') <= year and b.station_id in (". $location_list . ")"; } if ($band != 'All') { @@ -225,11 +229,11 @@ class Accumulate_model extends CI_Model } if ($mode != 'All') { - $sql .= " and col_mode ='" . $mode . "'"; + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; } $sql .=") total from " . $this->config->item('table_name') . " as a - where a.station_id = ". $station_id; + where a.station_id in (". $location_list . ")"; if ($band != 'All') { if ($band == 'SAT') { @@ -241,15 +245,15 @@ class Accumulate_model extends CI_Model } if ($mode != 'All') { - $sql .= " and col_mode ='" . $mode . "'"; + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; } if ($period == "year") { - $sql .= " group by year(a.col_time_on) + $sql .= " group by year(a.col_time_on) order by year(a.col_time_on)"; } else if ($period == "month") { - $sql .= " group by date_format(a.col_time_on, '%Y%m') + $sql .= " group by date_format(a.col_time_on, '%Y%m') order by date_format(a.col_time_on, '%Y%m')"; } @@ -259,12 +263,14 @@ class Accumulate_model extends CI_Model } function get_worked_bands() { - $CI =& get_instance(); - $CI->load->model('Stations'); - $station_id = $CI->Stations->find_active(); + $CI =& get_instance(); + $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 distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `" . $this->config->item('table_name') . "` WHERE station_id = " . $station_id . " AND COL_PROP_MODE != \"SAT\"" + "SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `" . $this->config->item('table_name') . "` WHERE station_id in (" . $location_list . ") AND COL_PROP_MODE != \"SAT\"" ); $worked_slots = array(); foreach ($data->result() as $row) { @@ -272,7 +278,7 @@ class Accumulate_model extends CI_Model } $SAT_data = $this->db->query( - "SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `" . $this->config->item('table_name') . "` WHERE station_id = " . $station_id . " AND COL_PROP_MODE = \"SAT\"" + "SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `" . $this->config->item('table_name') . "` WHERE station_id in (" . $location_list . ") AND COL_PROP_MODE = \"SAT\"" ); foreach ($SAT_data->result() as $row) { @@ -311,4 +317,4 @@ class Accumulate_model extends CI_Model "1.25cm" => 0, "SAT" => 0, ); -} \ No newline at end of file +}