Jump to content

Recommended Posts

  • Moderators
Posted

Gents i am having a thought about listing flight hours by type, ie i have pax flights and cargo flights, i am looking at listing the hours separately and creating awards based on hours per types, is there anything out there that anyone else has done yet and how difficult would this be to code?

  • Administrators
Posted

I dont think it would be too big of a job to create this. Best way to me would be to create a new table just to hold pilot hours (always a good idea to leave native tables alone for future updates) and then update it and collect pilot hours out of the PIREPS table and group them by the flight type field that is in that table already. Could even do it without a new table and call the data every time you want it but that could hurt performance some if there is a large number of pilots in a list and you were trying to do this for each pilot on the list.

Not using a new table, maybe something like this;

/core/common/HoursData.class.php

<?php

class HoursData extends CodonModule {

   function hours_bytype($pilotid, $type)    {
       $query = "SELECT SUM(flighttime) as total FROM ".TABLE_PREFIX."pireps
                   WHERE flighttype = '$type'
                   AND pilotid = '$pilotid'";

       $hours = DB::get_row($query);

       return $hours->total;
   }

}

and then in your template use

<?php echo HoursData::hours_bytype('pilotid', 'P'); ?>

replacing pilotid with the variable holding the id and the second parameter could be any of the types out of the config file;

Config::Set(
'FLIGHT_TYPES', array(	
	'P'=>'Passenger',
	'C'=>'Cargo',
	'H'=>'Charter'
)
);

If you are using it on a pilot listing page where it would be called numerous times I would add the cache feature to it so it is not scanning the database everytime the page is called, it would speed it up some.

  • Like 1
Guest lorathon
Posted

I think you should change the query to include the following. It will give you an accurate representation of total hours.

SEC_TO_TIME(SUM(TIME_TO_SEC(p.flighttime_stamp))) as totaltime

Using this

SUM(flighttime) as total

You will not get a real total time. As it does not take into consideration that the field is a time. So it will sum as if a real number.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...