From df4e748e6cd454a91f1813a45a7e33f752abc84d Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Fri, 8 Apr 2016 10:30:04 -0400 Subject: [PATCH] adding flight class functions and removing static flight data --- class_flight.php | 244 +++++++++++++++++++++++++++++++++++++++++++++++ front-page.php | 20 +++- 2 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 class_flight.php diff --git a/class_flight.php b/class_flight.php new file mode 100644 index 0000000..b731dfc --- /dev/null +++ b/class_flight.php @@ -0,0 +1,244 @@ +toolbox = &$toolbox; +// $this->DB =& $toolbox->DB; + $this->airports = array('DTW'=>'Detroit Metro','PLN'=>'Pellston'); + $this->time_codes = array('A'=>'Actual','E'=>'Estimated','D'=>'Descision','S'=>'Scheduled','R'=>'In-range'); + } + + function get_airports( $code ) + { global $wpdb; + $return = false; + $query = "select * from glm_airport where code = '$code'"; + if( $data = $wpdb->get_results( $query, ARRAY_A ) ) + { + $return = array( + 'city'=>$data[0]['city'], + 'state'=>$data[0]['state'], + 'name'=>$data[0]['name'] + ); + } + return( $return ); + } + /** + * get_flight_data + * + * @access public + * @return string + */ + function get_flight_data() + { + $this->get_arr_flight_data(); + $this->get_dep_flight_data(); + + foreach( $this->arr_data as $key=>$value ) + { + $update_times[] = strtotime($value['msg_dtm']); + if ($row['name'] == "EXPRESS AIRLINES 1, INC.") $this->arr_data[$key]['name'] = 'Delta Airlines'; + if ($row['airline'] == "EXPRESS AIRLINES 1, INC.") $this->arr_data[$key]['airline'] = 'Delta Airlines'; + } + foreach( $this->dep_data as $key) + { + $update_times[] = strtotime($row['msg_dtm']); + if ($row['name'] == "EXPRESS AIRLINES 1, INC.") $this->dep_data[$key]['name'] = 'Delta Airlines'; + if ($row['airline'] == "EXPRESS AIRLINES 1, INC.") $this->dep_data[$key]['airline'] = 'Delta Airlines'; + } + rsort($update_times); + // get UTC offset for current date/time + $TimeDiff = 4+date("I"); + $this->last_updated = '

 

Last updated: '.date("n/j/Y g:i a",$update_times[0]-($TimeDiff*60*60)).'

'; + //echo ''; + } + + /** + * get_arr_flight_data + * + * @access public + * @return string + */ + function get_arr_flight_data() + { + global $wpdb; + $query = "select *, name AS airline from glm_flight, glm_airlines where flt_orig_date = current_date and flt_leg_dest = 'PLN' and glm_airlines.code = flt_airline order by cur_in_time;"; + + if( $data = $wpdb->get_results( $query, ARRAY_A ) ) + { + $this->arr_data = $data; + } + } + + /** + * get_dep_flight_data + * + * @access public + * @return string + */ + function get_dep_flight_data() + { + global $wpdb; + $query = "select *, name AS airline from glm_flight, glm_airlines where flt_orig_date = current_date and flt_leg_orig = 'PLN' and glm_airlines.code = flt_airline order by cur_dep_time;"; + if( $data = $wpdb->get_results( $query, ARRAY_A ) ) + { + $this->dep_data = $data; + } + } + + /** + * format_time + * + * @param mixed $time + * @access public + * @return string + */ + function format_time( $time ) + { + $timestamp = strtotime( 'now '.$time ); + $newtime = date('g:i A',$timestamp); + return( $newtime ); + } + + /** + * build_arrivals + * + * @access public + * @return string + */ + function build_arrivals() + { + if( is_array( $this->arr_data ) ) + { + $out = ' + '; + $out .= ' + + + + + + + + + '; + foreach( $this->arr_data as $row ) + { + $airport = $this->get_airports( $row["flt_leg_orig"] ); + $airport_text = $airport["name"].' '.$airport["city"]; + $airport_text .= ( $airport["state"] ) ? ','.$airport["state"]:''; + $out .= ' + + + + + + + '; + } + $out .= '
FromFlightTimeStatus
'.$airport_text.''.$row["airline"].' '.$row["flt_numb"].''.$this->format_time( $row["cur_in_time"] ).' '.$this->time_codes[$row["cur_in_time_code"]].''.$row["remarks"].'
+ '; + } + return( $out ); + } + + /** + * build_departures + * + * @access public + * @return string + */ + function build_departures() + { + + if( is_array( $this->dep_data ) ) + { + $out = ' + '; + $out .= ' + + + + + + + '; + foreach( $this->dep_data as $row ) + { + $airport = $this->get_airports( $row["flt_leg_dest"] ); + $airport_text = $airport["name"].' '.$airport["city"]; + $airport_text .= ( $airport["state"] ) ? ','.$airport["state"]:''; + $out .= ' + + + + + + + '; + } + $out .= '
DestinationFlightTimeStatus
'.$airport_text.''.$row["airline"].'
'.$row["flt_numb"].'
'.$this->format_time( $row["cur_dep_time"] ).' '.$this->time_codes[$row["cur_dep_time_code"]].''.$row["remarks"].'
+ '; + } + return( $out ); + } + } +?> diff --git a/front-page.php b/front-page.php index 4d091af..93efa7a 100644 --- a/front-page.php +++ b/front-page.php @@ -1,4 +1,10 @@ - +
@@ -25,9 +31,16 @@ + get_flight_data(); + ?>

Arrivals:

+ build_arrivals(); ?> +

Departures:

+ build_departures(); ?> + + last_updated; ?>
-- 2.17.1