Users of the phpVMS virtual airline system may want to display individual aircraft stats. An addition to the system follows to add this feature to your site.
Create a file named Airframestatsdata.php in your /core/common/ folder and insert the following code.
<?php
//simpilotgroup addon for phpVMS virtual airline system
//
//simpilotgroup addons are licenced under the following license:
//Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
//To view full license text visit http://creativecommons.org/licenses/by-nc-sa/3.0/
//
//@author David Clark (simpilot)
//@copyright Copyright (c) 2012, David Clark
//@license http://creativecommons.org/licenses/by-nc-sa/3.0/
class Airframestatsdata extends CodonData {
function airframe_stats($id) {
$query = "SELECT aircraft,
COUNT(*) AS total_flights,
SUM(distance) AS total_distance,
SUM(flighttime) AS total_flighttime,
SUM(fuelused) AS total_fuelused,
SUM(revenue) AS total_revenue,
".TABLE_PREFIX."aircraft.*
FROM ".TABLE_PREFIX."pireps
JOIN ".TABLE_PREFIX."aircraft ON ".TABLE_PREFIX."pireps.aircraft = ".TABLE_PREFIX."aircraft.id
WHERE ".TABLE_PREFIX."pireps.aircraft='$id'";
$stats = DB::get_row($query);
if($stats->aircraft != null)
{
$stats->average_distance = round($stats->total_distance/$stats->total_flights);
$stats->average_flighttime = round($stats->total_flighttime/$stats->total_flights, 2);
}
else
{
$stats = null;
}
return $stats;
}
}
Then in the module function that you want to display the stats assign them to a variable ($aircraft_id is the database id of the aircraft you want to show)
function aircraft_view($aircraft_id) {
$this->set('stats', Airframestatsdata::airframe_stats($aircraftid);
$this->show('my_template');
}
In your view (template file) you then have an object named $stats that should include the following information
object(stdClass)[13] public 'aircraft' => string '1' (length=1) public 'total_flights' => string '7' (length=1) public 'total_distance' => string '3895' (length=4) public 'total_flighttime' => string '10.47' (length=5) public 'total_fuelused' => string '68114.6000976563' (length=16) public 'total_revenue' => string '39751.0457420349' (length=16) public 'id' => string '1' (length=1) public 'icao' => string 'B737' (length=4) public 'name' => string 'BOEING 737' (length=10) public 'fullname' => string 'Boeing 737-700' (length=14) public 'registration' => string 'AVEB21' (length=6) public 'downloadlink' => string '' (length=0) public 'imagelink' => string '' (length=0) public 'range' => string '0' (length=1) public 'weight' => string '0' (length=1) public 'cruise' => string '0' (length=1) public 'maxpax' => string '120' (length=3) public 'maxcargo' => string '1000' (length=4) public 'minrank' => string '0' (length=1) public 'ranklevel' => string '0' (length=1) public 'enabled' => string '1' (length=1) public 'average_distance' => float 556 public 'average_flighttime' => float 1.5
You can then display the data however you would like in your template using an echo command
<?php echo $stats->name; ?>






