Jump to content

Pilots Stats


greeham

Recommended Posts

Hello,

I am trying top have a stat on the front page showing all pilots that are active. The problem is that retired pilots are also classed as active, giving a misleading figure.

In my thinking I need to count the pilots that have a status of not retired but am unsure what query to use?

Thanks in advance,

Greeham

Link to comment
Share on other sites

I am just using the standard frontpage_main.tpl file with some scripting:-

<?php echo StatsData::PilotCount(); ?> Obviously gives the full count and <?php echo count(PilotGroups::getUsersInGroup('2')); ?> gives me a full list of those in the 'Active' Pilot group, but the numbers are misleading.

Many thanks,

Greeham

Link to comment
Share on other sites

  • Moderators

Open your core/common/StatsData.class.php file and find this:

public static function PilotCount($airline_code='')
{
 $key = 'pilot_count';
 if($airline_code != '')
 {
  $key .= '_'.$airline_code;
 }

 $total = CodonCache::read($key);

 if($total === false)
 {
  $params = array(
   'table' => TABLE_PREFIX.'pilots',
   'fields' => 'COUNT(*) as `total`',
  );

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

after this, paste the following part of code:

public static function ActivePilotCount($airline_code='')
{
 $key = 'active_pilot_count';
 if($airline_code != '')
 {
  $key .= '_'.$airline_code;
 }

 $total = CodonCache::read($key);

 if($total === false)
 {
  $params = array(
   'table' => TABLE_PREFIX.'pilots',
   'fields' => 'COUNT(*) as `total`',
  );

  if(!empty($airline_code))
  {
   $params['where']['code'] = $airline_code;
   $params['group'] = 'code';
  }
  $params['where']['retired'] = 0;
  $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;
}

After that, you will be able to show the number of the current active pilots of your virtual airline using this:

<?php echo StatsData::ActivePilotCount(); ?>

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