Jump to content

HubStats Class


Tom

Recommended Posts

<?php
class HubStats extends Codondata {

public static function Pilots($icao) { //Pilot details
 $query = "SELECT * FROM ".TABLE_PREFIX."pilots WHERE hub = '".$icao."'";
 return DB::get_results($query);
}

public static function CountPilots($icao) { //Number of pilots
 $query = "SELECT COUNT(pilotid) as count FROM ".TABLE_PREFIX."pilots WHERE hub = '".$icao."'";
 $results = DB::get_row($query);
 return $results->count;
}

public static function CountFlights($icao) { //Number of flights total
 $query = "SELECT COUNT(pirepid) as count FROM ".TABLE_PREFIX."pireps WHERE arricao = '".$icao."' OR depicao = '".$icao."'";
 $results = DB::get_row($query);
 return $results->count;
}

public static function CountFlightsFrom($icao) { //Number of flights departing
 $query = "SELECT COUNT(pirepid) as count FROM ".TABLE_PREFIX."pireps WHERE depicao = '".$icao."'";
 $results = DB::get_row($query);
 return $results->count;
}

public static function CountFlightsTo($icao) { //Number of flights arriving
 $query = "SELECT COUNT(pirepid) as count FROM ".TABLE_PREFIX."pireps WHERE arricao = '".$icao."'";
 $results = DB::get_row($query);
 return $results->count;
}

public static function FlightsDetails($icao, $limit=10) { //Details of latest (10) flights
 $query = "SELECT * FROM ".TABLE_PREFIX."pireps WHERE depicao = '".$icao."' OR arricao = '".$icao."' ORDER BY submitdate DESC LIMIT ".intval($limit);
 return DB::get_results($query);
}

public static function CountRoutes($icao) { //Count schedules
 $query = "SELECT COUNT(id) as count FROM ".TABLE_PREFIX."schedules WHERE depicao = '".$icao."' OR arricao = '".$icao."'";
 $results = DB::get_row($query);
 return $results->count;
}

public static function CountRoutesFrom($icao) { //Count schedules departing
 $query = "SELECT COUNT(id) as count FROM ".TABLE_PREFIX."schedules WHERE depicao = '".$icao."'";
 $results = DB::get_row($query);
 return $results->count;
}

public static function CountRoutesTo($icao) { //Count schedules arriving
 $query = "SELECT COUNT(id) as count FROM ".TABLE_PREFIX."schedules WHERE arricao = '".$icao."'";
 $results = DB::get_row($query);
 return $results->count;
}

public static function TotalMiles($icao) { //Count miles flown
 $query = "SELECT SUM(distance) as miles FROM ".TABLE_PREFIX."pireps WHERE depicao = '".$icao."' OR arricao = '".$icao."'";
 $result = DB::get_row($query);
 return $result->miles;
}

public static function TotalMilesFrom($icao) { //Count miles flown departing
 $query = "SELECT SUM(distance) as miles FROM ".TABLE_PREFIX."pireps WHERE depicao = '".$icao."'";
 $result = DB::get_row($query);
 return $result->miles;
}

public static function TotalMilesTo($icao) { //Count miles flown arriving
 $query = "SELECT SUM(distance) as miles FROM ".TABLE_PREFIX."pireps WHERE arricao = '".$icao."'";
 $result = DB::get_row($query);
 return $result->miles;
}

public static function TotalHours($icao) { //Count total hours
 $query = "SELECT SUM(flighttime) as hours FROM ".TABLE_PREFIX."pireps WHERE depicao = '".$icao."' OR arricao = '".$icao."'";
 $result = DB::get_row($query);
 return $result->hours;
}

public static function TotalHoursFrom($icao) { //Count total hours departing
 $query = "SELECT SUM(flighttime) as hours FROM ".TABLE_PREFIX."pireps WHERE depicao = '".$icao."'";
 $result = DB::get_row($query);
 return $result->hours;
}

public static function TotalHoursTo($icao) { //Count total hours arriving
 $query = "SELECT SUM(flighttime) as hours FROM ".TABLE_PREFIX."pireps WHERE arricao = '".$icao."'";
 $result = DB::get_row($query);
 return $result->hours;
}

public static function TotalFuelUsed($icao) { //Count total fuel used arriving
 $query = "SELECT SUM(fuelused) as fuel FROM ".TABLE_PREFIX."pireps WHERE arricao = '".$icao."'";
 $result = DB::get_row($query);
 return $result->fuel;
}
}
?>

TPL

<td>Numero Voli in Arrivo</td>
<td><?php echo HubStats::CountFlightsTo('LIMF'); ?></td>
</tr>

Link to comment
Share on other sites

For some reason, you don't call it correctly. Use the following code and let me know if it works.

<?php echo HubStatsData::CountFlightsTo('LIMF'); ?>

That wouldn't work as the class is "HubStats" not "HubStatsData"

If you run the SQL in phpmyadmin does it return correctly? "SELECT COUNT(pirepid) as count FROM phpvms_pireps WHERE arricao = 'LIMF'"

Link to comment
Share on other sites

no error

Is influent the php version ?

I don't expect it would be because of the PHP version, especially not if only 1 of the functions fails when they're pretty much the same process.

It's difficult to work out what's wrong if your server returns no error without actually looking at it all.

Link to comment
Share on other sites

Only thing I can suggest is that you don't have phpvms_ as your table prefix. Other than that, you could always do

$startdate = date("Y-m-01");
$enddate = date("Y-m-t");
HubStats::TotalHoursBetweenDates('PANC', date("Y-m-01"), date("Y-m-t"));

Shouldn't make a difference but give it shot.

EDIT: You might have to set your timezone:

date_default_timezone_set('Europe/London');

Change as necessary of course.

Have some progress. Its not pulling the monthly stats correctly. It's the 4th of the month now way we have that many hours already.

monthly_hub2.png

HubClass file

public static function TotalCargoBetweenDates($icao, $startdate, $enddate) { //Count total cargo
$query = "SELECT SUM(cargo) as cargo FROM phpvms_pireps WHERE depicao = '$icao' OR arricao = '$icao' AND flighttype = 'C' AND DATE(submitdate) >= '$startdate' AND DATE(submitdate) <= '$enddate' AND accepted = '1'";
$result = DB::get_row($query);
return $result->cargo;
}

php file

<?php echo HubStats::TotalHoursBetweenDates('CYQH', date("Y-m-01"), date("Y-m-t"));?>

Not sure why it showing data now and not before.

Link to comment
Share on other sites

  • 2 years later...

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...