Jump to content

HubStats Class


Tom

Recommended Posts

  • 4 months later...

Hi all,

I have been reading this thread over and over trying to figure out how to get this working. I would like to have a single custom page for each main hub we fly to/from (KIND & KMDW) and pull the data out of the hubstats.class file. However I am at a total loss.

I have placed the hubstats.class file in the core/common folder on the site, a couple things I am not understanding are,

1) Do I need to create a module for both Hubs and placed in the core/modules folder for this?

2) What code needs to go into the module?

Thanks for your time and help and sorry for my ignorance on how to set this up. Still learning

Link to comment
Share on other sites

Hi all,

I have been reading this thread over and over trying to figure out how to get this working. I would like to have a single custom page for each main hub we fly to/from (KIND & KMDW) and pull the data out of the hubstats.class file. However I am at a total loss.

I have placed the hubstats.class file in the core/common folder on the site, a couple things I am not understanding are,

1) Do I need to create a module for both Hubs and placed in the core/modules folder for this?

2) What code needs to go into the module?

Thanks for your time and help and sorry for my ignorance on how to set this up. Still learning

I made a module in core/modules - Folder called Hub and then in Hub.php do something like:

<?php

class Hub extends CodonModule
{

public function index()
{
// Do nothing? Show a list of all hubs perhaps?
}

public function view($hub)
{
if(!$hub){
$this->set('message', 'No hub code specified!');
$this->render('core_error.tpl');
return;
}
$this->set('pilots', PilotData::findPilots(array('p.hub'=>$hub)));
$this->set('hub', OperationsData::retrieveAirportInfo($hub));
$this->render('hub.tpl');

}

}

?>

And then make a template in your skin folder called hub.tpl which you put the codes for HubStats in and so on.

Then you link to site.com/index.php/hub/view/KIND etc

Link to comment
Share on other sites

Hi Tom,

Thanks for the info and so far I got the module made and placed in folder per your specs. Now my trouble begins with the hub.tpl file.

I have tried a couple of different coding ways each giving me different results. Below is the code I have in hub.tpl file. If you look you can see what I am trying to see. Here is the page that is being called too - http://www.ata-virtu...p/hub/view/KMDW, the /../../KIND page looks the same no matter what.


<b>Using ..CountPilots (KMDW) in place of ($icao)etc</b><br>
Pilots: <?php echo HubStats::Pilots(KMDW); ?><br>
Number of Pilots: <?php echo HubStats::CountPilots (KMDW); ?><br>
Number of Flights From: <?php echo HubStats::CountFlightsFrom(KMDW); ?><br>
Number of Flights to: <?php echo HubStats::CountFlightsTo($KMDW); ?><br>
Number of Flights: <?php echo HubStats::CountFlights(KMDW); ?><br>
Last 10 Pireps: <?php echo HubStats::FlightsDetails(KMDW, $limit=10); ?><br>
Number of Miles: <?php echo HubStats::TotalMiles(KMDW); ?><br>
Number of Routes To: <?php echo HubStats::CountRoutesTo(KMDW); ?><br><br>

<b>Using ..CountPilots (KIND) in place of ($icao)etc</b><br>
Pilots: <?php echo HubStats::Pilots(KIND); ?><br>
Number of Pilots: <?php echo HubStats::CountPilots (KIND); ?><br>
Number of Flights From: <?php echo HubStats::CountFlightsFrom(KIND); ?><br>
Number of Flights to: <?php echo HubStats::CountFlightsTo(KIND); ?><br>
Number of Flights: <?php echo HubStats::CountFlights(KIND); ?><br>
Last 10 Pireps: <?php echo HubStats::FlightsDetails(KIND, $limit=10); ?><br>
Number of Miles: <?php echo HubStats::TotalMiles(KIND); ?><br>
Number of Routes To: <?php echo HubStats::CountRoutesTo(KIND); ?><br><br>

<b>Using ..CountPilots($icao)etc</b><br>
Pilots: <?php echo HubStats::Pilots($icao); ?><br>
Number of Pilots: <?php echo HubStats::CountPilots ($icao); ?><br>
Number of Flights From: <?php echo HubStats::CountFlightsFrom($icao); ?><br>
Number of Flights to: <?php echo HubStats::CountFlightsTo($icao); ?><br>
Number of Flights: <?php echo HubStats::CountFlights($icao); ?><br>
Last 10 Pireps: <?php echo HubStats::FlightsDetails($icao, $limit=10); ?><br>
Number of Miles: <?php echo HubStats::TotalMiles($icao); ?><br>
Number of Routes To: <?php echo HubStats::CountRoutesTo($icao); ?><br><br>

I know it looks screwy. but just trying to see how to work this.

Again thanks for your help, it is greatly appreciated.

Link to comment
Share on other sites

Hi Tom,

Thanks for your help and your patience with me on this but still not doing anything here. Here is the code: If you notice Section 1 is using the $hub->KMDW, Section 2 is using just plain (KIND) as before and Section 3 is using $hub->ICAO. Section 2 is only pulling info out of the database but not everything that it should get, whereas Sections 1 & 3 aren't pulling anything. I know about creating a table/row for the pilot info I just put the code in there as stated above just as a place holder.

<b>Using ..CountPilots ($hub->KMDW) in place of($icao) etc</b><br>
<table>
<tr>$pilots = HubStats::Pilots($hub->KMDW);
foreach($pilots as $pilot){
    // Do a table row or something?</tr></table>
}<br>
Number of Pilots: <?php echo HubStats::CountPilots ($hub->KMDW) ; ?><br>
Number of Flights From: <?php echo HubStats::CountFlightsFrom ($hub->KMDW); ?><br>
Number of Flights to: <?php echo HubStats::CountFlightsTo ($hub->KMDW); ?><br>
Number of Flights: <?php echo HubStats::CountFlights ($hub->KMDW) ?><br>
Last 10 Pireps: <?php echo HubStats::FlightsDetails($hub->KMDW, $limit=10); ?><br>
Number of Miles: <?php echo HubStats::TotalMiles($hub->KMDW); ?><br>
Number of Routes To: <?php echo HubStats::CountRoutesTo($hub->KMDW); ?><br><br>


<b>Using ..CountPilots (KIND) in place of ($icao)etc</b><br>
$pilots = HubStats::Pilots($hub->KIND);
foreach($pilots as $pilot){
    // Do a table row or something?
}<br>
Number of Pilots: <?php echo HubStats::CountPilots (KIND); ?><br>
Number of Flights From: <?php echo HubStats::CountFlightsFrom(KIND); ?><br>
Number of Flights to: <?php echo HubStats::CountFlightsTo(KIND); ?><br>
Number of Flights: <?php echo HubStats::CountFlights(KIND); ?><br>
Last 10 Pireps: <?php echo HubStats::FlightsDetails(KIND, $limit=10); ?><br>
Number of Miles: <?php echo HubStats::TotalMiles(KIND); ?><br>
Number of Routes To: <?php echo HubStats::CountRoutesTo(KIND); ?><br><br>

<b>Using ..CountPilots($hub->ICAO) etc</b><br>
Pilots: <?php echo HubStats::Pilots($hub->ICAO); ?><br>
Number of Pilots: <?php echo HubStats::CountPilots ($hub->ICAO); ?><br>
Number of Flights From: <?php echo HubStats::CountFlightsFrom($hub->ICAO); ?><br>
Number of Flights to: <?php echo HubStats::CountFlightsTo($hub->ICAO); ?><br>
Number of Flights: <?php echo HubStats::CountFlights($hub->ICAO); ?><br>
Last 10 Pireps: <?php echo HubStats::FlightsDetails($hub->ICAO, $limit=10); ?><br>
Number of Miles: <?php echo HubStats::TotalMiles($hub->ICAO); ?><br>
Number of Routes To: <?php echo HubStats::CountRoutesTo($hub->ICAO); ?><br><br>

Again thank you for your help and your patience on this, very much appreciated.

Link to comment
Share on other sites

  • 1 month later...

How do I even get this to show data?

I've tried

<?php
print_r(HubStats::getHubStats('KSFO'));
?>

in a .tpl file i;ve created and i just get an error

Fatal error: Call to undefined method HubStats::getHubStats()

How would i fix this. Do i have to tell it to read the HubStats.class.php or something? Also how would you do such a thing?

Link to comment
Share on other sites

  • 1 year later...

Taran, you can modify the SQL for the TotalHours function to create another to specify a date range:

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

(Not tested)

Link to comment
Share on other sites

Taran, you can modify the SQL for the TotalHours function to create another to specify a date range:

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

(Not tested)

I figured out to put that in HubStats.class.php but what is the exact code to pull that data on my website?

Link to comment
Share on other sites

  • 2 weeks later...

Taran, you can modify the SQL for the TotalHours function to create another to specify a date range:

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

(Not tested)

For the folks back home who are wanting this as well, here's the corrected code that will be placed in the HubStats.class.php:

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

Link to comment
Share on other sites

The SQL DATE function is needed.

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

That should be it now ;)

Link to comment
Share on other sites

Still not working on my end :/ If i'm supposed to put something else somewhere please help! Here's what i have:

This code is in the HubStats.class.php

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

This is the code i'm using to get the data displayed

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

Link to comment
Share on other sites

Oops, it was something very minor ^_^

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

Link to comment
Share on other sites

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