2023-06-18 22:01:59 +02:00
< ? php
class Gridmap_model extends CI_Model {
2024-05-05 23:10:02 +02:00
function get_band_confirmed ( $band , $mode , $qsl , $lotw , $eqsl , $qrz , $sat , $orbit , $propagation , $logbooks_locations_array = NULL ) {
2024-04-05 15:46:57 +02:00
if ( $logbooks_locations_array == NULL ) {
2024-05-05 23:10:02 +02:00
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2024-04-05 15:46:57 +02:00
}
if ( ! $logbooks_locations_array ) {
return null ;
}
2023-06-18 22:01:59 +02:00
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
2024-10-12 06:01:37 +00:00
$binding = [];
2023-06-18 22:01:59 +02:00
$sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND FROM '
. $this -> config -> item ( 'table_name' )
2024-04-05 15:46:57 +02:00
. ' LEFT JOIN `satellite` on ' . $this -> config -> item ( 'table_name' ) . '.COL_SAT_NAME = satellite.name'
2023-06-18 22:01:59 +02:00
. ' WHERE station_id in ('
. $location_list . ') AND COL_GRIDSQUARE != ""' ;
2024-04-05 15:46:57 +02:00
if ( $band != 'All' ) {
2024-06-14 07:40:50 +00:00
if ( $band == 'SAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $band ;
2024-06-14 07:40:50 +00:00
if ( $sat != 'All' && $sat != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_sat_name = ? " ;
$binding [] = $sat ;
2024-06-14 07:40:50 +00:00
}
} else {
if ( $propagation == 'None' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (trim(col_prop_mode) = '' or col_prop_mode is null) " ;
2024-06-26 09:17:41 +00:00
} elseif ( $propagation == 'NoSAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode != 'SAT' " ;
2024-06-14 07:40:50 +00:00
} elseif ( $propagation != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $propagation ;
2024-06-14 07:40:50 +00:00
}
2024-10-12 06:01:37 +00:00
$sql .= " and col_band = ? " ;
$binding [] = $band ;
2024-06-14 07:40:50 +00:00
}
} else {
if ( $propagation == 'None' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (trim(col_prop_mode) = '' or col_prop_mode is null) " ;
2024-06-26 09:17:41 +00:00
} elseif ( $propagation == 'NoSAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode != 'SAT' " ;
2024-06-14 07:40:50 +00:00
} elseif ( $propagation != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $propagation ;
2024-06-14 07:40:50 +00:00
}
}
if ( $mode != 'All' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (col_mode = ? or col_submode = ?) " ;
$binding [] = $mode ;
$binding [] = $mode ;
2024-06-14 07:40:50 +00:00
}
2023-06-18 22:01:59 +02:00
2024-10-12 06:01:37 +00:00
if ( $orbit != 'All' ) {
$sql .= " AND satellite.orbit = ? " ;
$binding [] = $orbit ;
}
2024-04-05 15:46:57 +02:00
$sql .= $this -> addQslToQuery ( $qsl , $lotw , $eqsl , $qrz );
2023-06-18 22:01:59 +02:00
2024-10-12 06:01:37 +00:00
return $this -> db -> query ( $sql , $binding );
2023-06-18 22:01:59 +02:00
}
2024-05-05 23:10:02 +02:00
function get_band ( $band , $mode , $qsl , $lotw , $eqsl , $qrz , $sat , $orbit , $propagation , $logbooks_locations_array = NULL ) {
2024-04-05 15:46:57 +02:00
if ( $logbooks_locations_array == NULL ) {
2024-06-14 07:40:50 +00:00
2024-05-05 23:10:02 +02:00
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2024-04-05 15:46:57 +02:00
}
2023-06-18 22:01:59 +02:00
2024-04-05 15:46:57 +02:00
if ( ! $logbooks_locations_array ) {
return null ;
}
2023-06-18 22:01:59 +02:00
2024-04-05 15:46:57 +02:00
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
2023-06-18 22:01:59 +02:00
2024-10-12 06:01:37 +00:00
$binding = [];
2024-04-05 15:46:57 +02:00
$sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND FROM '
2023-06-18 22:01:59 +02:00
. $this -> config -> item ( 'table_name' )
2024-04-05 15:46:57 +02:00
. ' LEFT JOIN `satellite` on ' . $this -> config -> item ( 'table_name' ) . '.COL_SAT_NAME = satellite.name'
2023-06-18 22:01:59 +02:00
. ' WHERE station_id in ('
. $location_list . ') AND COL_GRIDSQUARE != ""' ;
2024-04-05 15:46:57 +02:00
if ( $band != 'All' ) {
2024-06-14 07:40:50 +00:00
if ( $band == 'SAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $band ;
2024-06-14 07:40:50 +00:00
if ( $sat != 'All' && $sat != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_sat_name = ? " ;
$binding [] = $sat ;
2024-06-14 07:40:50 +00:00
}
} else {
if ( $propagation == 'None' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (trim(col_prop_mode) = '' or col_prop_mode is null) " ;
2024-06-26 09:17:41 +00:00
} elseif ( $propagation == 'NoSAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode != 'SAT' " ;
2024-06-14 07:40:50 +00:00
} elseif ( $propagation != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $propagation ;
2024-06-14 07:40:50 +00:00
}
2024-10-12 06:01:37 +00:00
$sql .= " and col_band = ? " ;
$binding [] = $band ;
2024-06-14 07:40:50 +00:00
}
} else {
if ( $propagation == 'None' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (trim(col_prop_mode) = '' or col_prop_mode is null) " ;
2024-06-26 09:17:41 +00:00
} elseif ( $propagation == 'NoSAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode != 'SAT' " ;
2024-06-14 07:40:50 +00:00
} elseif ( $propagation != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $propagation ;
2024-06-14 07:40:50 +00:00
}
}
if ( $mode != 'All' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (col_mode = ? or col_submode = ?) " ;
$binding [] = $mode ;
$binding [] = $mode ;
2024-06-14 07:40:50 +00:00
}
2023-06-18 22:01:59 +02:00
2024-10-12 06:01:37 +00:00
if ( $orbit != 'All' ) {
$sql .= " AND satellite.orbit = ? " ;
$binding [] = $orbit ;
}
2024-04-05 15:46:57 +02:00
2024-10-12 06:01:37 +00:00
return $this -> db -> query ( $sql , $binding );
2024-04-05 15:46:57 +02:00
}
2023-06-18 22:01:59 +02:00
2024-05-05 23:10:02 +02:00
function get_band_worked_vucc_squares ( $band , $mode , $qsl , $lotw , $eqsl , $qrz , $sat , $orbit , $propagation , $logbooks_locations_array = NULL ) {
2024-04-05 15:46:57 +02:00
if ( $logbooks_locations_array == NULL ) {
2024-06-14 07:40:50 +00:00
2024-05-05 23:10:02 +02:00
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2024-04-05 15:46:57 +02:00
}
2023-06-18 22:01:59 +02:00
2024-04-05 15:46:57 +02:00
if ( ! $logbooks_locations_array ) {
return null ;
}
2023-06-18 22:01:59 +02:00
2024-04-05 15:46:57 +02:00
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
2023-06-18 22:01:59 +02:00
2024-10-12 06:01:37 +00:00
$binding = [];
2023-06-18 22:01:59 +02:00
$sql = 'SELECT distinct COL_VUCC_GRIDS, COL_BAND FROM '
. $this -> config -> item ( 'table_name' )
2024-04-05 15:46:57 +02:00
. ' LEFT JOIN `satellite` on ' . $this -> config -> item ( 'table_name' ) . '.COL_SAT_NAME = satellite.name'
2023-06-18 22:01:59 +02:00
. ' WHERE station_id in ('
. $location_list . ') AND COL_VUCC_GRIDS != ""' ;
2024-04-05 15:46:57 +02:00
if ( $band != 'All' ) {
2024-06-14 07:40:50 +00:00
if ( $band == 'SAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $band ;
2024-06-14 07:40:50 +00:00
if ( $sat != 'All' && $sat != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_sat_name = ? " ;
$binding [] = $sat ;
2024-06-14 07:40:50 +00:00
}
} else {
if ( $propagation == 'None' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (trim(col_prop_mode) = '' or col_prop_mode is null) " ;
2024-06-26 09:17:41 +00:00
} elseif ( $propagation == 'NoSAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode != 'SAT' " ;
2024-06-14 07:40:50 +00:00
} elseif ( $propagation != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $propagation ;
2024-06-14 07:40:50 +00:00
}
2024-10-12 06:01:37 +00:00
$sql .= " and col_band = ? " ;
$binding [] = $band ;
2024-06-14 07:40:50 +00:00
}
} else {
if ( $propagation == 'None' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (trim(col_prop_mode) = '' or col_prop_mode is null) " ;
2024-06-26 09:17:41 +00:00
} elseif ( $propagation == 'NoSAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode != 'SAT' " ;
2024-06-14 07:40:50 +00:00
} elseif ( $propagation != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $propagation ;
2024-06-14 07:40:50 +00:00
}
}
if ( $mode != 'All' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (col_mode = ? or col_submode = ?) " ;
$binding [] = $mode ;
$binding [] = $mode ;
2024-06-14 07:40:50 +00:00
}
2023-06-18 22:01:59 +02:00
2024-10-12 06:01:37 +00:00
if ( $orbit != 'All' ) {
$sql .= " AND satellite.orbit = ? " ;
$binding [] = $orbit ;
}
2023-06-18 22:01:59 +02:00
2024-10-12 06:01:37 +00:00
return $this -> db -> query ( $sql , $binding );
2024-04-05 15:46:57 +02:00
}
2024-05-05 23:10:02 +02:00
function get_band_confirmed_vucc_squares ( $band , $mode , $qsl , $lotw , $eqsl , $qrz , $sat , $orbit , $propagation , $logbooks_locations_array = NULL ) {
2024-04-05 15:46:57 +02:00
if ( $logbooks_locations_array == NULL ) {
2024-06-14 07:40:50 +00:00
2024-05-05 23:10:02 +02:00
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2024-04-05 15:46:57 +02:00
}
if ( ! $logbooks_locations_array ) {
return null ;
}
2023-06-18 22:01:59 +02:00
2024-01-31 11:59:45 +01:00
2023-06-18 22:01:59 +02:00
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
2024-10-12 06:01:37 +00:00
$binding = [];
2023-06-18 22:01:59 +02:00
$sql = 'SELECT distinct COL_VUCC_GRIDS, COL_BAND FROM '
. $this -> config -> item ( 'table_name' )
2024-04-05 15:46:57 +02:00
. ' LEFT JOIN `satellite` on ' . $this -> config -> item ( 'table_name' ) . '.COL_SAT_NAME = satellite.name'
2023-06-18 22:01:59 +02:00
. ' WHERE station_id in ('
. $location_list . ') AND COL_VUCC_GRIDS != ""' ;
2024-04-05 15:46:57 +02:00
if ( $band != 'All' ) {
2024-06-14 07:40:50 +00:00
if ( $band == 'SAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $band ;
2024-06-14 07:40:50 +00:00
if ( $sat != 'All' && $sat != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_sat_name = ? " ;
$binding [] = $sat ;
2024-06-14 07:40:50 +00:00
}
} else {
if ( $propagation == 'None' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (trim(col_prop_mode) = '' or col_prop_mode is null) " ;
2024-06-26 09:17:41 +00:00
} elseif ( $propagation == 'NoSAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode != 'SAT' " ;
2024-06-14 07:40:50 +00:00
} elseif ( $propagation != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $propagation ;
2024-06-14 07:40:50 +00:00
}
2024-10-12 06:01:37 +00:00
$sql .= " and col_band = ? " ;
$binding [] = $band ;
2024-06-14 07:40:50 +00:00
}
} else {
if ( $propagation == 'None' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (trim(col_prop_mode) = '' or col_prop_mode is null) " ;
2024-06-26 09:17:41 +00:00
} elseif ( $propagation == 'NoSAT' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode != 'SAT' " ;
2024-06-14 07:40:50 +00:00
} elseif ( $propagation != '' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and col_prop_mode = ? " ;
$binding [] = $propagation ;
2024-06-14 07:40:50 +00:00
}
}
if ( $mode != 'All' ) {
2024-10-12 06:01:37 +00:00
$sql .= " and (col_mode = ? or col_submode = ?) " ;
$binding [] = $mode ;
$binding [] = $mode ;
2024-06-14 07:40:50 +00:00
}
2023-06-18 22:01:59 +02:00
2023-12-08 12:23:19 +00:00
$sql .= $this -> addQslToQuery ( $qsl , $lotw , $eqsl , $qrz );
2023-06-18 22:01:59 +02:00
2024-10-12 06:01:37 +00:00
if ( $orbit != 'All' ) {
$sql .= " AND satellite.orbit = ? " ;
$binding [] = $orbit ;
}
2024-04-05 15:46:57 +02:00
2024-10-12 06:01:37 +00:00
return $this -> db -> query ( $sql , $binding );
2023-06-18 22:01:59 +02:00
}
2024-04-05 15:46:57 +02:00
// Adds confirmation to query
function addQslToQuery ( $qsl , $lotw , $eqsl , $qrz ) {
$sql = '' ;
if ( $lotw == " true " ) {
$sql .= " or col_lotw_qsl_rcvd = 'Y' " ;
}
if ( $qsl == " true " ) {
$sql .= " or col_qsl_rcvd = 'Y' " ;
}
if ( $eqsl == " true " ) {
$sql .= " or col_eqsl_qsl_rcvd = 'Y' " ;
}
if ( $qrz == " true " ) {
$sql .= " or col_qrzcom_qso_download_status = 'Y' " ;
}
if ( $sql != '' ) {
$sql = ' and (1=0 ' . $sql . ')' ;
}
if ( $sql == '' ) {
$sql = ' and 1=0' ;
}
return $sql ;
}
2023-06-18 22:01:59 +02:00
/*
* Get ' s the worked modes from the log
*/
function get_worked_modes () {
2024-05-05 23:10:02 +02:00
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2024-04-05 15:46:57 +02:00
if ( ! $logbooks_locations_array ) {
return null ;
}
2023-06-18 22:01:59 +02:00
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
// get all worked modes from database
$data = $this -> db -> query (
" SELECT distinct LOWER(`COL_MODE`) as `COL_MODE` FROM ` " . $this -> config -> item ( 'table_name' ) . " ` WHERE station_id in ( " . $location_list . " ) order by COL_MODE ASC "
);
$results = array ();
foreach ( $data -> result () as $row ) {
array_push ( $results , $row -> COL_MODE );
}
$data = $this -> db -> query (
" SELECT distinct LOWER(`COL_SUBMODE`) as `COL_SUBMODE` FROM ` " . $this -> config -> item ( 'table_name' ) . " ` WHERE station_id in ( " . $location_list . " ) and coalesce(COL_SUBMODE, '') <> '' order by COL_SUBMODE ASC "
);
foreach ( $data -> result () as $row ) {
if ( ! in_array ( $row , $results )) {
array_push ( $results , $row -> COL_SUBMODE );
}
}
2024-04-05 15:46:57 +02:00
asort ( $results );
2023-06-18 22:01:59 +02:00
return $results ;
}
2023-11-28 00:20:47 +01:00
}