2020-08-13 16:24:07 +00:00
< ? php
class LotwCert extends CI_Model {
2020-08-13 16:28:22 +00:00
/*
|--------------------------------------------------------------------------
| Function : lotw_certs
|--------------------------------------------------------------------------
|
| Returns all lotw_certs for a selected user via the $user_id parameter
|
*/
2020-08-13 16:24:07 +00:00
function lotw_certs ( $user_id ) {
2020-09-03 22:05:38 +00:00
2023-04-26 20:39:09 +00:00
$this -> db -> select ( 'lotw_certs.lotw_cert_id as lotw_cert_id, lotw_certs.callsign as callsign, dxcc_entities.name as cert_dxcc, dxcc_entities.end as cert_dxcc_end, lotw_certs.qso_start_date as qso_start_date, lotw_certs.qso_end_date as qso_end_date, lotw_certs.date_created as date_created, lotw_certs.date_expires as date_expires, lotw_certs.last_upload as last_upload' );
2020-08-13 16:24:07 +00:00
$this -> db -> where ( 'user_id' , $user_id );
2023-04-19 13:32:32 +00:00
$this -> db -> join ( 'dxcc_entities' , 'lotw_certs.cert_dxcc_id = dxcc_entities.adif' , 'left' );
2020-08-17 16:02:54 +00:00
$this -> db -> order_by ( 'cert_dxcc' , 'ASC' );
2020-08-13 16:24:07 +00:00
$query = $this -> db -> get ( 'lotw_certs' );
return $query ;
}
2020-08-17 16:02:54 +00:00
2020-12-26 12:08:43 +00:00
function lotw_cert_details ( $callsign , $dxcc ) {
2023-04-19 20:06:32 +00:00
$this -> db -> where ( 'cert_dxcc_id' , $dxcc );
2020-08-22 21:26:04 +00:00
$this -> db -> where ( 'callsign' , $callsign );
$query = $this -> db -> get ( 'lotw_certs' );
return $query -> row ();
}
2020-12-28 13:42:26 +00:00
function find_cert ( $callsign , $dxcc , $user_id ) {
2020-08-17 16:02:54 +00:00
$this -> db -> where ( 'user_id' , $user_id );
2023-04-19 13:32:32 +00:00
$this -> db -> where ( 'cert_dxcc_id' , $dxcc );
2020-08-17 16:02:54 +00:00
$this -> db -> where ( 'callsign' , $callsign );
$query = $this -> db -> get ( 'lotw_certs' );
return $query -> num_rows ();
}
2022-08-26 14:24:28 +00:00
function store_certificate ( $user_id , $callsign , $dxcc , $date_created , $date_expires , $qso_start_date , $qso_end_date , $cert_key , $general_cert ) {
2020-08-17 16:02:54 +00:00
$data = array (
'user_id' => $user_id ,
'callsign' => $callsign ,
2023-04-19 13:32:32 +00:00
'cert_dxcc_id' => $dxcc ,
2020-08-17 16:02:54 +00:00
'date_created' => $date_created ,
'date_expires' => $date_expires ,
2022-08-24 10:16:41 +00:00
'qso_start_date' => $qso_start_date ,
'qso_end_date' => $qso_end_date ,
2020-08-17 16:02:54 +00:00
'cert_key' => $cert_key ,
2020-08-26 15:31:35 +00:00
'cert' => $general_cert ,
2020-08-17 16:02:54 +00:00
);
$this -> db -> insert ( 'lotw_certs' , $data );
}
2023-03-30 10:33:09 +00:00
function update_certificate ( $user_id , $callsign , $dxcc , $date_created , $date_expires , $cert_key , $general_cert ) {
2020-08-17 16:02:54 +00:00
$data = array (
2023-04-19 13:32:32 +00:00
'cert_dxcc_id' => $dxcc ,
2020-08-17 16:02:54 +00:00
'date_created' => $date_created ,
'date_expires' => $date_expires ,
'cert_key' => $cert_key ,
2020-08-26 15:31:35 +00:00
'cert' => $general_cert
2020-08-17 16:02:54 +00:00
);
$this -> db -> where ( 'user_id' , $user_id );
$this -> db -> where ( 'callsign' , $callsign );
2023-04-19 13:32:32 +00:00
$this -> db -> where ( 'cert_dxcc_id' , $dxcc );
2020-08-17 16:02:54 +00:00
$this -> db -> update ( 'lotw_certs' , $data );
}
2023-03-30 10:33:09 +00:00
function delete_certificate ( $user_id , $lotw_cert_id ) {
2020-08-17 16:02:54 +00:00
$this -> db -> where ( 'lotw_cert_id' , $lotw_cert_id );
$this -> db -> where ( 'user_id' , $user_id );
$this -> db -> delete ( 'lotw_certs' );
}
2020-08-26 20:20:58 +00:00
function last_upload ( $certID ) {
$data = array (
'last_upload' => date ( " Y-m-d H:i:s " ),
);
$this -> db -> where ( 'lotw_cert_id' , $certID );
$this -> db -> update ( 'lotw_certs' , $data );
return " Updated " ;
}
2020-08-13 16:24:07 +00:00
function empty_table ( $table ) {
$this -> db -> empty_table ( $table );
}
2022-12-23 13:49:03 +00:00
function lotw_cert_expired ( $user_id , $date ) {
$array = array ( 'user_id' => $user_id , 'date_expires <' => $date );
$this -> db -> where ( $array );
$query = $this -> db -> get ( 'lotw_certs' );
if ( $query -> num_rows () > 0 ) {
return true ;
} else {
return false ;
}
}
function lotw_cert_expiring ( $user_id , $date ) {
$array = array ( 'user_id' => $user_id , 'DATE_SUB(date_expires, INTERVAL 30 DAY) <' => $date , 'date_expires >' => $date );
$this -> db -> where ( $array );
$query = $this -> db -> get ( 'lotw_certs' );
if ( $query -> num_rows () > 0 ) {
return true ;
} else {
return false ;
}
}
2020-08-13 16:24:07 +00:00
}
2022-08-24 10:16:41 +00:00
?>