2021-03-20 11:24:13 +01:00
< ? php
class Sig extends CI_Model {
2026-06-24 22:29:00 +01:00
private function normalize_location_list ( $location_list ) {
if ( is_array ( $location_list )) {
return implode ( ',' , array_map ( 'intval' , $location_list ));
}
$parts = explode ( ',' , ( string ) $location_list );
$ids = array ();
foreach ( $parts as $part ) {
$trimmed = trim ( $part , " \t \n \r \0 \x0B ' \" " );
if ( is_numeric ( $trimmed )) {
$ids [] = ( int ) $trimmed ;
}
}
return implode ( ',' , array_values ( array_unique ( $ids )));
}
2021-03-20 11:24:13 +01:00
2026-01-21 17:15:01 +00:00
function get_all ( $type , $filters = array ()) {
2021-03-20 11:24:13 +01:00
$CI =& get_instance ();
2021-09-09 22:29:59 +02:00
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2021-03-20 11:24:13 +01:00
2021-11-14 17:11:59 +01:00
if ( ! $logbooks_locations_array ) {
return null ;
}
2022-09-07 09:19:18 +02:00
$this -> load -> model ( 'bands' );
$bandslots = $this -> bands -> get_worked_bands ( 'sig' );
2021-09-09 22:29:59 +02:00
$this -> db -> where_in ( " station_id " , $logbooks_locations_array );
2022-09-07 09:19:18 +02:00
$this -> db -> where_in ( " col_band " , $bandslots );
2026-01-21 17:15:01 +00:00
$this -> db -> order_by ( " COL_TIME_ON " , " DESC " );
2021-03-20 11:24:13 +01:00
$this -> db -> where ( 'COL_SIG =' , $type );
2021-09-09 22:29:59 +02:00
2026-01-21 17:15:01 +00:00
// Apply band/mode filters if provided
if ( ! empty ( $filters [ 'band' ]) && strtolower ( $filters [ 'band' ]) !== 'all' ) {
$this -> db -> where ( " LOWER(COL_BAND) = " , strtolower ( $filters [ 'band' ]));
}
if ( ! empty ( $filters [ 'mode' ]) && strtolower ( $filters [ 'mode' ]) !== 'all' ) {
$this -> db -> where ( " LOWER(COL_MODE) = " , strtolower ( $filters [ 'mode' ]));
}
// Apply confirmation filter
if ( ! empty ( $filters [ 'confirmed_only' ]) && ( $filters [ 'confirmed_only' ] === true || $filters [ 'confirmed_only' ] === 'true' || $filters [ 'confirmed_only' ] === 1 || $filters [ 'confirmed_only' ] === '1' )) {
$this -> db -> where ( " (COL_QSL_RCVD = 'Y' OR COL_EQSL_QSL_RCVD = 'Y' OR COL_LOTW_QSL_RCVD = 'Y') " );
}
2021-03-20 11:24:13 +01:00
return $this -> db -> get ( $this -> config -> item ( 'table_name' ));
}
2026-01-21 17:15:01 +00:00
function get_all_sig_types ( $filters = array ()) {
2021-09-09 22:29:59 +02: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 17:11:59 +01:00
if ( ! $logbooks_locations_array ) {
return null ;
}
2026-06-24 22:29:00 +01:00
$location_list = $this -> normalize_location_list ( $logbooks_locations_array );
2021-03-20 11:24:13 +01:00
2022-09-07 09:19:18 +02:00
$this -> load -> model ( 'bands' );
$bandslots = $this -> bands -> get_worked_bands ( 'sig' );
2026-06-24 22:29:00 +01:00
$bandslots_list = " ' " . implode ( " ',' " , array_map ( array ( $this -> db , 'escape_str' ), $bandslots )) . " ' " ;
2022-09-07 09:19:18 +02:00
2026-01-21 17:15:01 +00:00
// Build dynamic WHERE clause for filters
$where_clause = " where col_sig <> '' and station_id in ( " . $location_list . " ) and col_band in ( " . $bandslots_list . " ) " ;
if ( ! empty ( $filters [ 'band' ]) && strtolower ( $filters [ 'band' ]) !== 'all' ) {
2026-06-24 22:29:00 +01:00
$where_clause .= " and LOWER(col_band) = ' " . $this -> db -> escape_str ( strtolower ( $filters [ 'band' ])) . " ' " ;
2026-01-21 17:15:01 +00:00
}
if ( ! empty ( $filters [ 'mode' ]) && strtolower ( $filters [ 'mode' ]) !== 'all' ) {
2026-06-24 22:29:00 +01:00
$where_clause .= " and LOWER(col_mode) = ' " . $this -> db -> escape_str ( strtolower ( $filters [ 'mode' ])) . " ' " ;
2026-01-21 17:15:01 +00:00
}
if ( ! empty ( $filters [ 'confirmed_only' ]) && ( $filters [ 'confirmed_only' ] === true || $filters [ 'confirmed_only' ] === 'true' || $filters [ 'confirmed_only' ] === 1 || $filters [ 'confirmed_only' ] === '1' )) {
$where_clause .= " and (COL_QSL_RCVD = 'Y' OR COL_EQSL_QSL_RCVD = 'Y' OR COL_LOTW_QSL_RCVD = 'Y') " ;
}
$sql = " select col_sig, count(*) qsos, count(distinct col_sig_info) refs from " . $this -> config -> item ( 'table_name' ) . $where_clause . " group by col_sig order by col_sig ASC " ;
2021-03-20 11:24:13 +01:00
$query = $this -> db -> query ( $sql );
return $query -> result ();
}
2026-01-21 17:15:01 +00:00
/**
* Get confirmed SIG references for a specific SIG type with optional filters
*/
function get_confirmed_sig_refs ( $type , $filters = array ()) {
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2021-03-20 11:24:13 +01:00
2026-01-21 17:15:01 +00:00
if ( ! $logbooks_locations_array ) {
return 0 ;
}
2026-06-24 22:29:00 +01:00
$location_list = $this -> normalize_location_list ( $logbooks_locations_array );
2026-01-21 17:15:01 +00:00
$this -> load -> model ( 'bands' );
$bandslots = $this -> bands -> get_worked_bands ( 'sig' );
2026-06-24 22:29:00 +01:00
$bandslots_list = " ' " . implode ( " ',' " , array_map ( array ( $this -> db , 'escape_str' ), $bandslots )) . " ' " ;
2026-01-21 17:15:01 +00:00
$where_clause = " where col_sig = ' " . $this -> db -> escape_str ( $type ) . " ' and station_id in ( " . $location_list . " ) and col_band in ( " . $bandslots_list . " ) " ;
$where_clause .= " and (COL_QSL_RCVD = 'Y' OR COL_EQSL_QSL_RCVD = 'Y' OR COL_LOTW_QSL_RCVD = 'Y') " ;
if ( ! empty ( $filters [ 'band' ]) && strtolower ( $filters [ 'band' ]) !== 'all' ) {
2026-06-24 22:29:00 +01:00
$where_clause .= " and LOWER(col_band) = ' " . $this -> db -> escape_str ( strtolower ( $filters [ 'band' ])) . " ' " ;
2026-01-21 17:15:01 +00:00
}
if ( ! empty ( $filters [ 'mode' ]) && strtolower ( $filters [ 'mode' ]) !== 'all' ) {
2026-06-24 22:29:00 +01:00
$where_clause .= " and LOWER(col_mode) = ' " . $this -> db -> escape_str ( strtolower ( $filters [ 'mode' ])) . " ' " ;
2026-01-21 17:15:01 +00:00
}
$sql = " select count(distinct col_sig_info) as confirmed_refs from " . $this -> config -> item ( 'table_name' ) . $where_clause ;
$query = $this -> db -> query ( $sql );
$result = $query -> row ();
return $result ? $result -> confirmed_refs : 0 ;
}
/**
* Get worked SIG references for a specific SIG type with optional filters
*/
function get_worked_sig_refs ( $type , $filters = array ()) {
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2021-03-20 11:24:13 +01:00
2026-01-21 17:15:01 +00:00
if ( ! $logbooks_locations_array ) {
return 0 ;
}
2026-06-24 22:29:00 +01:00
$location_list = $this -> normalize_location_list ( $logbooks_locations_array );
2026-01-21 17:15:01 +00:00
$this -> load -> model ( 'bands' );
$bandslots = $this -> bands -> get_worked_bands ( 'sig' );
2026-06-24 22:29:00 +01:00
$bandslots_list = " ' " . implode ( " ',' " , array_map ( array ( $this -> db , 'escape_str' ), $bandslots )) . " ' " ;
2026-01-21 17:15:01 +00:00
$where_clause = " where col_sig = ' " . $this -> db -> escape_str ( $type ) . " ' and station_id in ( " . $location_list . " ) and col_band in ( " . $bandslots_list . " ) " ;
if ( ! empty ( $filters [ 'band' ]) && strtolower ( $filters [ 'band' ]) !== 'all' ) {
2026-06-24 22:29:00 +01:00
$where_clause .= " and LOWER(col_band) = ' " . $this -> db -> escape_str ( strtolower ( $filters [ 'band' ])) . " ' " ;
2026-01-21 17:15:01 +00:00
}
if ( ! empty ( $filters [ 'mode' ]) && strtolower ( $filters [ 'mode' ]) !== 'all' ) {
2026-06-24 22:29:00 +01:00
$where_clause .= " and LOWER(col_mode) = ' " . $this -> db -> escape_str ( strtolower ( $filters [ 'mode' ])) . " ' " ;
2026-01-21 17:15:01 +00:00
}
$sql = " select count(distinct col_sig_info) as worked_refs from " . $this -> config -> item ( 'table_name' ) . $where_clause ;
$query = $this -> db -> query ( $sql );
$result = $query -> row ();
return $result ? $result -> worked_refs : 0 ;
}
/**
* Get distinct worked modes for SIG QSOs
*/
function get_worked_modes () {
$CI =& get_instance ();
$CI -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $CI -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
if ( ! $logbooks_locations_array ) {
return array ();
}
2026-06-24 22:29:00 +01:00
$location_list = $this -> normalize_location_list ( $logbooks_locations_array );
2026-01-21 17:15:01 +00:00
// Get distinct modes from SIG QSOs
$sql = " SELECT DISTINCT UPPER(COL_MODE) as COL_MODE FROM " . $this -> config -> item ( 'table_name' ) .
" WHERE col_sig <> '' AND station_id in ( " . $location_list . " ) " .
" ORDER BY COL_MODE ASC " ;
$query = $this -> db -> query ( $sql );
$modes = array ();
foreach ( $query -> result () as $row ) {
$modes [] = $row -> COL_MODE ;
}
return $modes ;
}
}