2020-10-04 19:41:01 +00:00
< ? php
if ( ! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
class Accumulate_model extends CI_Model
{
2020-10-08 09:45:41 +00:00
function get_accumulated_data ( $band , $award , $mode , $period ) {
2021-09-10 20:59:10 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2021-11-14 16:33:24 +00:00
if ( ! $logbooks_locations_array ) {
return array ();
}
2021-09-10 20:59:10 +00:00
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
2020-10-04 19:41:01 +00:00
2020-10-06 19:12:14 +00:00
switch ( $award ) {
2021-09-10 20:59:10 +00:00
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 ;
2020-10-06 19:12:14 +00:00
}
return $result ;
}
2021-09-10 20:59:10 +00:00
function get_accumulated_dxcc ( $band , $mode , $period , $location_list ) {
2020-10-08 09:45:41 +00:00
if ( $period == " year " ) {
2022-09-03 16:01:36 +00:00
$sql = " select year(thcv.col_time_on) year " ;
2020-10-08 09:45:41 +00:00
}
else if ( $period == " month " ) {
2022-09-03 16:01:36 +00:00
$sql = " select date_format(col_time_on, '%Y%m') year " ;
2020-10-08 09:45:41 +00:00
}
2020-10-04 19:41:01 +00:00
2022-09-03 16:01:36 +00:00
$sql .= " , coalesce(y.tot, 0) tot
from " . $this->config ->item('table_name') . " thcv
left outer join (
select count ( col_dxcc ) as tot , year
from ( select distinct " ;
if ( $period == " year " ) {
$sql .= " year(col_time_on) " ;
}
else if ( $period == " month " ) {
$sql .= " date_format(col_time_on, '%Y%m') " ;
}
$sql .= " year, col_dxcc
from " . $this->config ->item('table_name') .
" where col_dxcc > 0 and station_id in ( " . $location_list . " ) " ;
2020-10-04 19:41:01 +00:00
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
2020-10-08 09:45:41 +00:00
if ( $mode != 'All' ) {
2021-09-10 20:59:10 +00:00
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 16:01:36 +00:00
$sql .= " order by year
) x
where not exists ( select 1 from " . $this->config ->item('table_name') . " where " ;
if ( $period == " year " ) {
$sql .= " year(col_time_on) < year " ;;
}
else if ( $period == " month " ) {
$sql .= " date_format(col_time_on, '%Y%m') < year " ;;
}
$sql .= " and col_dxcc = x.col_dxcc " ;
2020-10-06 19:12:14 +00:00
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
2020-10-08 09:45:41 +00:00
if ( $mode != 'All' ) {
2021-09-10 20:59:10 +00:00
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 16:01:36 +00:00
$sql .= " and station_id in ( " . $location_list . " ))
group by year
order by year " ;
2021-09-10 20:59:10 +00:00
2020-10-08 09:45:41 +00:00
if ( $period == " year " ) {
2022-09-03 16:01:36 +00:00
$sql .= " ) y on year(thcv.col_time_on) = y.year " ;
2020-10-08 09:45:41 +00:00
}
else if ( $period == " month " ) {
2022-09-03 16:01:36 +00:00
$sql .= " ) y on date_format(col_time_on, '%Y%m') = y.year " ;
}
$sql .= " where thcv.col_dxcc > 0 " ;
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
if ( $mode != 'All' ) {
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
}
$sql .= " and station_id in ( " . $location_list . " ) " ;
if ( $period == " year " ) {
$sql .= " group by year(thcv.col_time_on), y.tot
order by year ( thcv . col_time_on ) " ;
}
else if ( $period == " month " ) {
$sql .= " group by date_format(col_time_on, '%Y%m'), y.tot
order by date_format ( col_time_on , '%Y%m' ) " ;
2020-10-08 09:45:41 +00:00
}
2020-10-06 19:12:14 +00:00
$query = $this -> db -> query ( $sql );
2022-09-03 16:01:36 +00:00
return $this -> count_and_add_accumulated_total ( $query -> result ());
}
function count_and_add_accumulated_total ( $array ) {
$counter = 0 ;
for ( $i = 0 ; $i < count ( $array ); $i ++ ) {
$array [ $i ] -> total = $array [ $i ] -> tot + $counter ;
$counter = $array [ $i ] -> total ;
}
return $array ;
2020-10-06 19:12:14 +00:00
}
2021-09-10 20:59:10 +00:00
function get_accumulated_was ( $band , $mode , $period , $location_list ) {
2020-10-08 09:45:41 +00:00
if ( $period == " year " ) {
2022-09-03 19:00:54 +00:00
$sql = " select year(thcv.col_time_on) year " ;
2020-10-08 09:45:41 +00:00
}
else if ( $period == " month " ) {
2022-09-03 19:00:54 +00:00
$sql = " select date_format(col_time_on, '%Y%m') year " ;
2020-10-08 09:45:41 +00:00
}
2020-10-06 19:12:14 +00:00
2022-09-03 19:00:54 +00:00
$sql .= " , coalesce(y.tot, 0) tot
from " . $this->config ->item('table_name') . " thcv
left outer join (
select count ( col_state ) as tot , year
from ( select distinct " ;
if ( $period == " year " ) {
$sql .= " year(col_time_on) " ;
}
else if ( $period == " month " ) {
$sql .= " date_format(col_time_on, '%Y%m') " ;
}
$sql .= " year, col_state
from " . $this->config ->item('table_name') .
" where station_id in ( " . $location_list . " ) " ;
2020-10-06 19:12:14 +00:00
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
2020-10-08 09:45:41 +00:00
if ( $mode != 'All' ) {
2021-09-10 20:59:10 +00:00
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
2020-10-08 09:45:41 +00:00
}
2020-10-06 19:12:14 +00:00
$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') " ;
2022-09-03 19:00:54 +00:00
$sql .= " order by year
) x
where not exists ( select 1 from " . $this->config ->item('table_name') . " where " ;
if ( $period == " year " ) {
$sql .= " year(col_time_on) < year " ;;
}
else if ( $period == " month " ) {
$sql .= " date_format(col_time_on, '%Y%m') < year " ;;
}
$sql .= " and col_state = x.col_state " ;
2020-10-06 19:12:14 +00:00
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
2020-10-08 09:45:41 +00:00
if ( $mode != 'All' ) {
2022-09-03 19:00:54 +00:00
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
2020-10-08 09:45:41 +00:00
}
2020-10-06 19:12:14 +00:00
$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') " ;
2022-09-03 19:00:54 +00:00
$sql .= " and station_id in ( " . $location_list . " ))
group by year
order by year " ;
if ( $period == " year " ) {
$sql .= " ) y on year(thcv.col_time_on) = y.year " ;
}
else if ( $period == " month " ) {
$sql .= " ) y on date_format(col_time_on, '%Y%m') = y.year " ;
}
$sql .= " where station_id in ( " . $location_list . " ) " ;
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
if ( $mode != 'All' ) {
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
}
2020-10-08 09:45:41 +00:00
if ( $period == " year " ) {
2022-09-03 19:00:54 +00:00
$sql .= " group by year(thcv.col_time_on), y.tot
order by year ( thcv . col_time_on ) " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 19:00:54 +00:00
2020-10-08 09:45:41 +00:00
else if ( $period == " month " ) {
2022-09-03 19:00:54 +00:00
$sql .= " group by date_format(col_time_on, '%Y%m'), y.tot
order by date_format ( col_time_on , '%Y%m' ) " ;
2020-10-08 09:45:41 +00:00
}
2020-10-06 19:12:14 +00:00
$query = $this -> db -> query ( $sql );
2022-09-03 19:00:54 +00:00
return $this -> count_and_add_accumulated_total ( $query -> result ());
2020-10-06 19:12:14 +00:00
}
2021-09-10 20:59:10 +00:00
function get_accumulated_iota ( $band , $mode , $period , $location_list ) {
2020-10-08 09:45:41 +00:00
if ( $period == " year " ) {
2022-09-03 19:00:54 +00:00
$sql = " select year(thcv.col_time_on) year " ;
}
else if ( $period == " month " ) {
$sql = " select date_format(col_time_on, '%Y%m') year " ;
}
$sql .= " , coalesce(y.tot, 0) tot
from " . $this->config ->item('table_name') . " thcv
left outer join (
select count ( col_iota ) as tot , year
from ( select distinct " ;
if ( $period == " year " ) {
$sql .= " year(col_time_on) " ;
2020-10-08 09:45:41 +00:00
}
else if ( $period == " month " ) {
2022-09-03 19:00:54 +00:00
$sql .= " date_format(col_time_on, '%Y%m') " ;
2020-10-08 09:45:41 +00:00
}
2020-10-06 19:12:14 +00:00
2022-09-03 19:00:54 +00:00
$sql .= " year, col_iota
from " . $this->config ->item('table_name') .
" where station_id in ( " . $location_list . " ) " ;
2020-10-06 19:12:14 +00:00
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
2020-10-08 09:45:41 +00:00
if ( $mode != 'All' ) {
2021-09-10 20:59:10 +00:00
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 19:00:54 +00:00
$sql .= " order by year
) x
where not exists ( select 1 from " . $this->config ->item('table_name') . " where " ;
if ( $period == " year " ) {
$sql .= " year(col_time_on) < year " ;;
}
else if ( $period == " month " ) {
$sql .= " date_format(col_time_on, '%Y%m') < year " ;;
}
$sql .= " and col_iota = x.col_iota " ;
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
if ( $mode != 'All' ) {
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
}
$sql .= " and station_id in ( " . $location_list . " ))
group by year
order by year " ;
if ( $period == " year " ) {
$sql .= " ) y on year(thcv.col_time_on) = y.year " ;
}
else if ( $period == " month " ) {
$sql .= " ) y on date_format(col_time_on, '%Y%m') = y.year " ;
}
$sql .= " where station_id in ( " . $location_list . " ) " ;
2020-10-06 19:12:14 +00:00
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
2020-10-08 09:45:41 +00:00
if ( $mode != 'All' ) {
2021-09-10 20:59:10 +00:00
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 19:00:54 +00:00
2020-10-08 09:45:41 +00:00
if ( $period == " year " ) {
2022-09-03 19:00:54 +00:00
$sql .= " group by year(thcv.col_time_on), y.tot
order by year ( thcv . col_time_on ) " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 19:00:54 +00:00
2020-10-08 09:45:41 +00:00
else if ( $period == " month " ) {
2022-09-03 19:00:54 +00:00
$sql .= " group by date_format(col_time_on, '%Y%m'), y.tot
order by date_format ( col_time_on , '%Y%m' ) " ;
2020-10-08 09:45:41 +00:00
}
2020-10-06 19:12:14 +00:00
$query = $this -> db -> query ( $sql );
2022-09-03 19:00:54 +00:00
return $this -> count_and_add_accumulated_total ( $query -> result ());
2020-10-06 19:12:14 +00:00
}
2021-09-10 20:59:10 +00:00
function get_accumulated_waz ( $band , $mode , $period , $location_list ) {
2020-10-08 09:45:41 +00:00
if ( $period == " year " ) {
2022-09-03 19:00:54 +00:00
$sql = " select year(thcv.col_time_on) year " ;
2020-10-08 09:45:41 +00:00
}
else if ( $period == " month " ) {
2022-09-03 19:00:54 +00:00
$sql = " select date_format(col_time_on, '%Y%m') year " ;
2020-10-08 09:45:41 +00:00
}
2020-10-06 19:12:14 +00:00
2022-09-03 19:00:54 +00:00
$sql .= " , coalesce(y.tot, 0) tot
from " . $this->config ->item('table_name') . " thcv
left outer join (
select count ( col_cqz ) as tot , year
from ( select distinct " ;
if ( $period == " year " ) {
$sql .= " year(col_time_on) " ;
}
else if ( $period == " month " ) {
$sql .= " date_format(col_time_on, '%Y%m') " ;
}
$sql .= " year, col_cqz
from " . $this->config ->item('table_name') .
" where station_id in ( " . $location_list . " ) " ;
2020-10-06 19:12:14 +00:00
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
2020-10-08 09:45:41 +00:00
if ( $mode != 'All' ) {
2021-09-10 20:59:10 +00:00
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 19:00:54 +00:00
$sql .= " order by year
) x
where not exists ( select 1 from " . $this->config ->item('table_name') . " where " ;
if ( $period == " year " ) {
$sql .= " year(col_time_on) < year " ;;
}
else if ( $period == " month " ) {
$sql .= " date_format(col_time_on, '%Y%m') < year " ;;
}
$sql .= " and col_cqz = x.col_cqz " ;
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
if ( $mode != 'All' ) {
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
}
$sql .= " and station_id in ( " . $location_list . " ))
group by year
order by year " ;
if ( $period == " year " ) {
$sql .= " ) y on year(thcv.col_time_on) = y.year " ;
}
else if ( $period == " month " ) {
$sql .= " ) y on date_format(col_time_on, '%Y%m') = y.year " ;
}
$sql .= " where station_id in ( " . $location_list . " ) " ;
2020-10-06 19:12:14 +00:00
if ( $band != 'All' ) {
if ( $band == 'SAT' ) {
$sql .= " and col_prop_mode =' " . $band . " ' " ;
} else {
$sql .= " and col_prop_mode !='SAT' " ;
$sql .= " and col_band =' " . $band . " ' " ;
}
}
2020-10-08 09:45:41 +00:00
if ( $mode != 'All' ) {
2021-09-10 20:59:10 +00:00
$sql .= " and (col_mode =' " . $mode . " ' or col_submode =' " . $mode . " ') " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 19:00:54 +00:00
2020-10-08 09:45:41 +00:00
if ( $period == " year " ) {
2022-09-03 19:00:54 +00:00
$sql .= " group by year(thcv.col_time_on), y.tot
order by year ( thcv . col_time_on ) " ;
2020-10-08 09:45:41 +00:00
}
2022-09-03 19:00:54 +00:00
2020-10-08 09:45:41 +00:00
else if ( $period == " month " ) {
2022-09-03 19:00:54 +00:00
$sql .= " group by date_format(col_time_on, '%Y%m'), y.tot
order by date_format ( col_time_on , '%Y%m' ) " ;
2020-10-08 09:45:41 +00:00
}
2020-10-04 19:41:01 +00:00
$query = $this -> db -> query ( $sql );
2022-09-03 19:00:54 +00:00
return $this -> count_and_add_accumulated_total ( $query -> result ());
2020-10-04 19:41:01 +00:00
}
2021-11-13 14:55:17 +00:00
}