adding flight class functions and removing static flight data
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 8 Apr 2016 14:30:04 +0000 (10:30 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 8 Apr 2016 14:30:04 +0000 (10:30 -0400)
class_flight.php [new file with mode: 0644]
front-page.php

diff --git a/class_flight.php b/class_flight.php
new file mode 100644 (file)
index 0000000..b731dfc
--- /dev/null
@@ -0,0 +1,244 @@
+<?php
+include_once($_SERVER['DOCUMENT_ROOT'].'/wp-config.php' );
+       class glm_flight {
+               /**
+                * toolbox 
+                * 
+                * @var mixed
+                * @access public
+                */
+               public $toolbox;
+               /**
+                * DB 
+                * 
+                * @var mixed
+                * @access public
+                */
+               public $DB;
+               /**
+                * arr_data 
+                * 
+                * @var mixed
+                * @access public
+                */
+               public $arr_data;
+               /**
+                * dep_data 
+                * 
+                * @var mixed
+                * @access public
+                */
+               public $dep_data;
+               /**
+                * airports 
+                * 
+                * @var mixed
+                * @access public
+                */
+               public $airports;
+               /**
+                * time_codes 
+                * 
+                * @var mixed
+                * @access public
+                */
+               public $time_codes;
+               /**
+                * last_updated 
+                * 
+                * @var mixed
+                * @access public
+                */
+               public $last_updated;
+               /**
+                * glm_flight 
+                * 
+                * @param mixed $toolbox 
+                * @access public
+                * @return string
+                */
+               function glm_flight()
+               {
+//                     $this->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'] = '<nobr>Delta Airlines</nobr>';
+                               if ($row['airline'] == "EXPRESS AIRLINES 1, INC.") $this->dep_data[$key]['airline'] = '<nobr>Delta Airlines</nobr>';
+                       }
+                       rsort($update_times);
+                       // get UTC offset for current date/time
+                       $TimeDiff = 4+date("I");
+                       $this->last_updated = '<div id="last-update"><p>&nbsp;</p><p><b>Last updated:</b> '.date("n/j/Y g:i a",$update_times[0]-($TimeDiff*60*60)).'</p></div>';
+                       //echo '<!--<pre>';
+                       //print_r( $update_times );
+                       //echo '</pre>-->';
+               }
+
+               /**
+                * 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 = '
+                               <table class="footable arrival" id="flight-arrivals">';
+                                       $out .= '
+                                       <thead>
+                    <tr>
+                                               <th>From</th>
+                                               <th>Flight</th>
+                                               <th>Time</th>
+                                               <th>Status</th>
+                    </tr>
+                                       </thead>
+                                       ';
+                               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 .= '
+                                       <tr>
+                                               <td>'.$airport_text.'</td>
+                                               <td>'.$row["airline"].' '.$row["flt_numb"].'</td>
+                                               <td>'.$this->format_time( $row["cur_in_time"] ).' '.$this->time_codes[$row["cur_in_time_code"]].'</td>
+                                               <td><nobr>'.$row["remarks"].'</nobr></td>
+                                       </tr>
+                                       ';
+                               }
+                               $out .= '</table>
+                       ';
+                       }
+                       return( $out );
+               }
+
+               /**
+                * build_departures 
+                * 
+                * @access public
+                * @return string
+                */
+               function build_departures()
+               {
+
+                       if( is_array( $this->dep_data ) )
+                       {
+                               $out = '
+                               <table class="footable departure id="flight-departures">';
+                                       $out .= '
+                                       <tr>
+                                               <th>Destination</th>
+                                               <th>Flight</th>
+                                               <th>Time</th>
+                                               <th>Status</th>
+                                       </tr>
+                                       ';
+                               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 .= '
+                                       <tr>
+                                               <td>'.$airport_text.'</td>
+                                               <td>'.$row["airline"].'<br>'.$row["flt_numb"].'</td>
+                                               <td>'.$this->format_time( $row["cur_dep_time"] ).' '.$this->time_codes[$row["cur_dep_time_code"]].'</td>
+                                               <td><nobr>'.$row["remarks"].'</nobr></td>
+                                       </tr>
+                                       ';
+                               }
+                               $out .= '</table>
+                       ';
+                       }
+                       return( $out );
+               }
+       }
+?>
index 4d091af..93efa7a 100644 (file)
@@ -1,4 +1,10 @@
-<?php get_header(); ?>
+<?php 
+include 'class_flight.php';
+get_header(); 
+global $wpdb;
+
+
+?>
 <div class="row">
     <?php get_template_part('parts/slide-show');?>
 </div>
                 </div>
             </div>
         </div>
+       <?php
+//        glm_flight::get_flight_data();
+        $flight = new glm_flight();
+        $flight->get_flight_data();
+         ?>
         <div id="arrival" class="row">
             <div class="small-12 columns">
                 <h1>Arrivals:</h1>
+                <?php echo $flight->build_arrivals(); ?>
+<!--
                 <table class="footable arrival">
                     <thead>
                         <tr>
                             <td><nobr>On Time</nobr></td>
                         </tr>
                 </table>
+-->
             </div>
         </div>
         <div id="depart" class="row">
             <div class="small-12 columns">
                 <h1>Departures:</h1>
+                <?php echo $flight->build_departures(); ?>
+<!--
                 <table class="footable departure">
                     <thead>
                         <tr>
@@ -71,6 +87,8 @@
                             <td><nobr>Departed</nobr></td>
                       </tr>
                 </table>
+-->
+                <?php echo $flight->last_updated; ?>
             </div>
         </div>
     </div>