shiljo Posted April 4, 2013 Report Posted April 4, 2013 Hi! I wonder is there any way to have total cargo carried under statistics on frontpage..heres the code, pls help <h3>Airline Stats</h3> <div class="box"> <strong>Total Pilots:</strong><?php echo StatsData::PilotCount(); ?><br> <strong>Total Flights: </strong><?php echo StatsData::TotalFlights(); ?><br> <strong>Total Hours Flown: </strong><?php echo StatsData::TotalHours(); ?><br> <strong>Total Schedules: </strong><?php echo StatsData::totalschedules(); ?><br> <strong>Flights Today: </strong><?php echo StatsData::totalflightstoday(); ?><br> <br> <?php $cws = new CodonWebService(); $xml = $cws->get('http://www.vacentral.net/airline/xml/ccg_croatiacargo'); $xml = simplexml_load_string($xml); echo "<div style='text-align: center; font-weight: bold; font-size: 14px; color: #000080'>We are {$xml->rank}. on vaCentral</div>"; ?> Something to add... Quote
TAV1702 Posted April 23, 2013 Report Posted April 23, 2013 I have this working on a site of mine. The issue is now, I don't remember how I fixed it. The problem is, if you have a flight marked as Cargo in the schedule, when the pirep is filed, it is automatically saved in the database as a passenger flight. I do not recall how I fixed it to make mine work. If I figure it out, I will surely let you all know. Quote
Moderators Parkho Posted April 25, 2013 Moderators Report Posted April 25, 2013 Add the following function to your StasData.class.php: public function TotalCargoCarried($airline_code = '') { return self::getTotalForCol(array( 'table' => 'pireps', 'column' => 'load', 'airline_code' => $airline_code, 'where' => array( 'accepted' => PIREP_ACCEPTED, 'flighttype' => 'C', ), 'func' => 'SUM', ) ); } Add the following line to your <div> : <strong>Cargo Carried: </strong><?php echo StatsData::TotalCargoCarried(); ?> lbs<br> Screenshot: Quote
TAV1702 Posted June 25, 2013 Report Posted June 25, 2013 The problem is, when doing a cargo flight and pirep is filed, the database is saving the flight as a passenger flight, not a cargo flight. So all cargo hauled is counting as passengers. I have to manually cahnge all flights in the database that I know were cargo flights to correct it every time. I found a fix for this issue long ago and now I don't recall how to fix it., Quote
TAV1702 Posted June 25, 2013 Report Posted June 25, 2013 actually, I just tried this little ditty of code and it worked. Nice one! Quote
Moderators Parkho Posted June 26, 2013 Moderators Report Posted June 26, 2013 Of course it worked! 1 Quote
OA01 Posted June 27, 2013 Report Posted June 27, 2013 BooHoo, doesn't work for me Returns following error: Total Cargo Carried: Fatal error: Call to undefined method StatsData::getTotalForCol() in /home2/orangea1/public_html/core/common/StatsData.class.php on line 509 Quote
TAV1702 Posted June 28, 2013 Report Posted June 28, 2013 It may be the version of phpVMS too. Parhko can verify that or not. The one I just tried it on was not a standard phpVMS, it was a phpVMS Extended by Simpilot. Quote
Moderators Parkho Posted June 28, 2013 Moderators Report Posted June 28, 2013 Yeah! I just found out that it works in older version of phpvms . there is a missing function in new release. TAV maybe you can provide that function. Quote
TAV1702 Posted June 30, 2013 Report Posted June 30, 2013 Yeah I do not have that version of phpVMS. IS that the new one Nabeel released with security fixes a while back? If so, I do not have it and never used it. If I can dig up any info Ill share it. Quote
Moderators Parkho Posted July 1, 2013 Moderators Report Posted July 1, 2013 Yeah I do not have that version of phpVMS. IS that the new one Nabeel released with security fixes a while back? If so, I do not have it and never used it. If I can dig up any info Ill share it. If it's working on the version you're currently having then I think you should have the missing function. Quote
TAV1702 Posted July 1, 2013 Report Posted July 1, 2013 Ill bust out winmerge and see if I can locate the difference. Quote
OA01 Posted July 4, 2013 Report Posted July 4, 2013 PLEASE find the missing function, my cargo pilots are beating me up over this. Quote
Moderators Parkho Posted July 5, 2013 Moderators Report Posted July 5, 2013 I found it! Add this to your StatsData.class.php at the end before the last bracket closes: public static function getTotalForCol($params) { $params = array_merge(array( 'table' => '', 'column' => '', 'airline_code' => '', // optional 'where' => array(), // optional 'func' => 'COUNT', //optional ), $params ); if($params['table'] == '' || $params['table'] == '') { return false; } if($params['func'] == '') { $params['func'] = 'COUNT'; } if(!is_array($params['where'])) { $params['where'] = array(); } if(!empty($params['airline_code'])) { $params['airline_code'] = strtoupper($params['airline_code']); $params['where']['code'] = $params['airline_code']; } $mixed = substr(md5(implode('', $params)), 0, 8); $key = 'total_'.$mixed; $total = CodonCache::read($key); if($total === false) { $params['column'] = trim($params['column']); if($params['column'] != '*') { $params['column'] = '`'.$params['column'].'`'; } $sql="SELECT ".$params['func']."(".$params['column'].") as `total` " ."FROM ".TABLE_PREFIX.$params['table']; $sql .= DB::build_where($params['where']); $total = DB::get_row($sql); if(!$total) { $total = 0; } else { $total = $total->total; } CodonCache::write($key, $total, '15minute'); } return $total; } 1 Quote
TAV1702 Posted July 15, 2013 Report Posted July 15, 2013 thx for helping him with this one parkho. I got busy with life and slipped away for the last couple few weeks. 2 Quote
Caporrella Posted March 7, 2014 Report Posted March 7, 2014 I used this for StatsData.class.php /** * Return the total number of cargo carried * * @return mixed This is the return value description * */ public static function TotalCargoCarried($airline_code = '') { $key = 'total_cargo_carried'; if($airline_code != '') { $key .= '_'.$airline_code; } $total = CodonCache::read($key); if($total === false) { $params = array( 'table' => TABLE_PREFIX.'pireps', 'fields' => 'SUM(`load`) as `total`', 'where' => array( 'accepted' => PIREP_ACCEPTED, 'flighttype' => 'C' ), ); if(!empty($airline_code)) { $params['where']['code'] = $airline_code; $params['group'] = 'code'; } $sql = DB::build_select($params); $results = DB::get_results($sql); if(!$results) { $total = 0; } else { $total = $results[0]->total; } CodonCache::write($key, $total, '15minute'); } return $total; } My first edit of php code, and it work! 1 Quote
Colin Posted March 12, 2014 Report Posted March 12, 2014 Tried this with last code Parkho in the Stats.Data.Class then added <strong>Cargo Carried: </strong><?php echo StatsData::TotalCargoCarried(); ?> lbs<br> to the frontpage.tpl which is where my stats data is located and got the error Fatal error: Call to undefined method StatsData::TotalCargoCarried() in /customers/2/a/5/dhlvirtualcargo.co.uk/httpd.www/lib/skins/vairline/frontpage_main.tpl on line 165 followed to the letter and for me not being able to Cargo stats to display Quote
Industrialshadow Posted August 23, 2016 Report Posted August 23, 2016 (edited) my problem is solved Code deleted Edited August 23, 2016 by Industrialshadow Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.