2024-02-29 19:13:37 +01:00
< ? php
class Satellite_model extends CI_Model {
function get_all_satellites () {
2024-12-07 17:52:38 +01:00
$sql = " select satellite.id, satellite.name as satname, group_concat(distinct satellitemode.name separator ', ') as modename, satellite.displayname, satellite.orbit, satellite.lotw as lotw, tle.updated
2024-03-07 20:33:17 +01:00
from satellite
2024-03-08 12:35:57 +01:00
left outer join satellitemode on satellite . id = satellitemode . satelliteid
2024-12-07 17:52:38 +01:00
left outer join tle on satellite . id = tle . satelliteid
2024-12-07 21:36:45 +01:00
group by satellite . name , satellite . displayname , satellite . orbit , satellite . id , tle . updated " ;
2024-02-29 19:13:37 +01:00
return $this -> db -> query ( $sql ) -> result ();
}
2024-05-01 08:59:22 +02:00
function get_all_satellites_with_tle () {
$sql = " select satellite.id, satellite.name as satname, tle.tle
from satellite
join tle on satellite . id = tle . satelliteid
2024-05-01 23:58:04 +02:00
order by satellite . name
2024-05-01 08:59:22 +02:00
" ;
return $this -> db -> query ( $sql ) -> result ();
}
2024-03-07 20:33:17 +01:00
function delete ( $id ) {
// Clean ID
$clean_id = $this -> security -> xss_clean ( $id );
2024-03-09 14:06:09 +01:00
// Delete Satellite
2024-03-07 20:33:17 +01:00
$this -> db -> delete ( 'satellite' , array ( 'id' => $clean_id ));
}
2024-03-09 14:06:09 +01:00
function deleteSatMode ( $id ) {
// Clean ID
$clean_id = $this -> security -> xss_clean ( $id );
// Delete Satellite
$this -> db -> delete ( 'satellitemode' , array ( 'id' => $clean_id ));
}
2024-03-07 20:33:17 +01:00
function saveupdatedsatellite ( $id , $satellite ) {
2024-11-11 17:48:54 +01:00
$this -> db -> where ( 'satellite.id' , $id );
$this -> db -> update ( 'satellite' , $satellite );
return true ;
2024-03-07 20:33:17 +01:00
}
2024-03-09 14:06:09 +01:00
function saveSatelliteMode ( $id , $satmode ) {
$this -> db -> where ( 'satellitemode.id' , $id );
2024-11-11 17:48:54 +01:00
$this -> db -> update ( 'satellitemode' , $satmode );
return true ;
2024-03-09 14:06:09 +01:00
}
2024-03-07 20:33:17 +01:00
function add () {
$data = array (
2024-03-08 12:35:57 +01:00
'name' => xss_clean ( $this -> input -> post ( 'name' , true )),
2024-12-01 23:49:51 +01:00
'displayname' => xss_clean ( $this -> input -> post ( 'displayname' , true )),
2024-03-08 12:35:57 +01:00
'orbit' => xss_clean ( $this -> input -> post ( 'orbit' , true )),
2024-03-07 20:33:17 +01:00
);
2024-11-11 17:48:54 +01:00
if ( xss_clean ( $this -> input -> post ( 'lotw' , true )) == 'Y' ) {
$data [ 'lotw' ] = 'Y' ;
} else {
$data [ 'lotw' ] = 'N' ;
}
2024-03-07 20:33:17 +01:00
$this -> db -> where ( 'name' , xss_clean ( $this -> input -> post ( 'name' , true )));
$result = $this -> db -> get ( 'satellite' );
if ( $result -> num_rows () == 0 ) {
2024-03-09 14:06:09 +01:00
$this -> db -> insert ( 'satellite' , $data );
$insert_id = $this -> db -> insert_id ();
2024-03-08 12:35:57 +01:00
2024-03-09 14:06:09 +01:00
$data = array (
2024-03-10 15:38:43 +01:00
'name' => xss_clean ( $this -> input -> post ( 'modename' , true )),
2024-03-08 12:35:57 +01:00
'satelliteid' => $insert_id ,
2024-03-09 22:21:31 +01:00
'uplink_mode' => xss_clean ( $this -> input -> post ( 'uplinkmode' , true )),
'uplink_freq' => xss_clean ( $this -> input -> post ( 'uplinkfrequency' , true )),
'downlink_mode' => xss_clean ( $this -> input -> post ( 'downlinkmode' , true )),
'downlink_freq' => xss_clean ( $this -> input -> post ( 'downlinkfrequency' , true )),
2024-03-08 12:35:57 +01:00
);
2024-03-09 22:21:31 +01:00
$this -> db -> insert ( 'satellitemode' , $data );
2024-03-07 20:33:17 +01:00
}
}
function getsatellite ( $id ) {
$this -> db -> where ( 'id' , $id );
2024-03-08 19:23:51 +01:00
return $this -> db -> get ( 'satellite' );
2024-03-07 20:33:17 +01:00
}
2024-03-08 21:50:14 +01:00
function getsatmodes ( $id ) {
$this -> db -> where ( 'satelliteid' , $id );
return $this -> db -> get ( 'satellitemode' );
}
2024-03-09 18:24:45 +01:00
function insertSatelliteMode () {
$data = array (
'name' => xss_clean ( $this -> input -> post ( 'name' , true )),
'satelliteid' => xss_clean ( $this -> input -> post ( 'id' , true )),
2024-03-09 22:21:31 +01:00
'uplink_mode' => xss_clean ( $this -> input -> post ( 'uplink_mode' , true )),
'uplink_freq' => xss_clean ( $this -> input -> post ( 'uplink_freq' , true )),
'downlink_mode' => xss_clean ( $this -> input -> post ( 'downlink_mode' , true )),
'downlink_freq' => xss_clean ( $this -> input -> post ( 'downlink_freq' , true )),
2024-03-09 18:24:45 +01:00
);
$this -> db -> insert ( 'satellitemode' , $data );
2024-03-10 07:49:39 +01:00
$insert_id = $this -> db -> insert_id ();
2024-03-11 09:57:24 +01:00
return $insert_id ;
}
2024-03-10 07:49:39 +01:00
2024-03-11 09:57:24 +01:00
function satellite_data () {
$this -> db -> select ( 'satellite.name AS satellite, satellitemode.name AS satmode, satellitemode.uplink_mode AS Uplink_Mode, satellitemode.uplink_freq AS Uplink_Freq, satellitemode.downlink_mode AS Downlink_Mode, satellitemode.downlink_freq AS Downlink_Freq' );
$this -> db -> join ( 'satellitemode' , 'satellite.id = satellitemode.satelliteid' , 'LEFT OUTER' );
$query = $this -> db -> get ( 'satellite' );
return $query -> result ();
2024-03-09 18:24:45 +01:00
}
2024-05-01 08:59:22 +02:00
function array_group_by ( $flds , $arr ) {
$groups = array ();
foreach ( $arr as $rec ) {
$keys = array_map ( function ( $f ) use ( $rec ) { return $rec [ $f ]; }, $flds );
$k = implode ( '@' , $keys );
if ( isset ( $groups [ $k ])) {
$groups [ $k ][] = $rec ;
} else {
$groups [ $k ] = array ( $rec );
}
}
return $groups ;
}
function get_tle ( $sat ) {
$this -> db -> select ( 'satellite.name AS satellite, tle.tle' );
$this -> db -> join ( 'tle' , 'satellite.id = tle.satelliteid' );
$this -> db -> where ( 'name' , $sat );
$query = $this -> db -> get ( 'satellite' );
return $query -> row ();
}
2024-03-11 09:57:24 +01:00
2024-02-29 19:13:37 +01:00
}
?>