Jump to content

Total cargo carried on statistics help


shiljo

Recommended Posts

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

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

  • Moderators

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:

stas.jpg

Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

Link to comment
Share on other sites

  • Moderators

I found it! :D

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;
   }

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 7 months later...

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! :D

  • Like 1
Link to comment
Share on other sites

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 :wacko:

Link to comment
Share on other sites

  • 3 weeks later...
  • 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...