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; ?>
Some users of phpVMS often look for a way to add pages within the system without using the pages editor as sometimes it will break php code you are trying to use in the page. It can be done easily by creating a quick module to show the pages.
For this example we will create a module named “Content” to display our custom pages for our phpVMS system.
First create a new folder in your /core/modules folder named Content (case sensitive) and inside of that folder create a blank php file named Content.php
Extend the core codon structure to start the module file,
<?php
class Content extends CodonModule {
}
Next create the index function within the class that the module will default to if there is no method declared in the url call.
function index() {
}
Within the index function create a call to show your custom template (view) for your site.
$this->show('customfile');
Your Custom.php module (controller) file should look similar to this now,
<?php
class Content extends CodonModule {
function index() {
$this->show('customfile');
}
}
Next, create your custom template (view) by creating a file in your skin folder named customfile.tpl . This file should contain everything that you want shown on the page you are creating. This file is the part of your webpage that is contained in between the <body> and the </body> tags. The header and footer as well as all the css and js calls made in your template will also be included within this page, so no need to create new links to any of those items. You can use html or php or a combination of both within this file. An example might be;
<h1>My Custom Content Page</h1> <ul> <li>List Item 1</li> <li>List Item 2</li> <li>List Item 3</li> </ul>
To view this page create a link on your site pointing to the module;
http://www.mysite.com/index.php/content
If you would like to add more pages to the module it can be done by using additional methods within the module(class). For example you could add a page for staff members;
<?php
class Content extends CodonModule {
function index() {
$this->show('customfile');
}
function staff() {
$this->show('staff');
}
}
Then, create a file in your skin folder named staff.tpl and once again include the html and/or php code you want included in the page. To reach this page on your web site, add the method name to the end of the url we used earlier,
http://www.mysite.com/index.php/content/staff
You can pass data in variables from the core system using these methods if it is required and also add access controls if needed.
If your site phpVMS based virtual airline is experiencing issues with timeouts and kACARS disconnects during the unfortunate outage of the phpVMS and VaCentral servers you can disable the functions in the framework that is calling back to the api server(s).
In the /core/local.config.php file change the following code;
Config::Set('VACENTRAL_ENABLED', true);
so it looks like this;
Config::Set('VACENTRAL_ENABLED', false);
and also
Config::Set('CHECK_RELEASE_VERSION', true);
Config::Set('CHECK_BETA_VERSION', true);
to
Config::Set('CHECK_RELEASE_VERSION', false);
Config::Set('CHECK_BETA_VERSION', false);
This should bring your site back to normal except for there will be no data sent to VaCentral. Once the phpVMS sites are back online just change those lines back to the original settings and you should be back up and running.
Also, if you have your VaCentral rank shown on your pages anywhere disable the function until phpVMS is restored.