phpvms / phpvms_v2

Virtual Airline Management (not maintained)
http://www.phpvms.net
BSD 3-Clause "New" or "Revised" License
41 stars 46 forks source link

ACARS_LIVE_TIME not calculated on some queries #113

Open Oxymoron290 opened 11 years ago

Oxymoron290 commented 11 years ago

Introduction

I had a scenario where I wanted to look at the scheduled flights and display them up to the point where their PIREPs where filed and the flight completed. At the same time, I wanted to display the status of those flights. In order to accomplish this I used the following:

$lastbids = SchedulesData::GetLatestBids(50); foreach($lastbids as $lastbid){ $flightData = ACARSData::get_flight($lastbid->code, $lastbid->flightnum);

// Simplification for issue discription
if(empty($flightData)){
    $status = "Scheduled";
}else{
    $status = $flightData->phasedetail;
}
....

}

Now as you would expect most of those were just in a "Scheduled" status. But in the case of those currently in flight I wanted to show the status such as Taxiing, Climbing, Cruising, Descending, etc... which this code was able to do. Most of the time

Discovery of Issue

In situations where the flight was at least started but PIREP was never filed I got stuck in a "Level Flight" status. I noticed though that this wasn't an issue for the ACARSMap, and looking at the code, ACARSMap looks at all progressing flights using ACARSData::GetACARSData(); Looking deeper I was able to see that this function is unique to the ACARSData.class.php in where it has a block of code with the following:

if (empty($cutofftime)) { $cutofftime = Config::Get('ACARS_LIVE_TIME'); }

  ....

   if ($cutofftime !== 0) {
        $sql .= 'WHERE DATE_SUB(NOW(), INTERVAL ' . $cutofftime .
            ' MINUTE) <= a.`lastupdate`';
    }

Give or take a few comments.

Issue

Seeing this, I've noticed that ACARSData.class.php is lacking in some functionality of expansion. It does not provide a function to call ACARS Data on a single progressing flight that utilizes the ACARS_LIVE_TIME global.

Proposed Resolutions

I have 2 possible resolutions which could help

Resolution 1

Rename ACARSData::GetACARSData(); to ACARSData::GetAllACARSData(); and create a new method named ACARSData::GetACARSFlightData($code, $flight_num); which will return data similar to that of ACARSData::get_flight(); but incorporate the ACARS_LIVE_TIME global into the sql query.

Resolution 2

Create an optional parameter on ACARSData::get_flight($code, $flight_num); but this is where this one becomes questionable. Should the optional parameter be a boolean which just tells the method to use the default value in ACARS_LIVE_TIME or should it be a value to use as the cutoff time? A mixture of the two? If it's a boolean, how would you change the default value? If it's a value, do you really want it to be the responsibility of the controller (In this framework, refereed to as a module) to figure out the default value of the parameter using ACARS_LIVE_TIME?