You are here

public function statspro::get_aggregate_stat in Statistics Pro 6

Same name and namespace in other branches
  1. 6.2 statspro.inc \StatsPro::get_aggregate_stat()

File

./statspro.inc, line 89
statspro class for statistics pro module.

Class

statspro
Manages the data saving and retrieval according to the user defined parameters.

Code

public function get_aggregate_stat($mode) {
  $rc = FALSE;
  if (in_array($mode, $this->absolute_amounts)) {
    $rc = array(
      'subject' => strip_tags($this->fields[$mode]),
      'amount' => db_result(db_query("SELECT SUM(%s) FROM {statspro}", $mode)),
    );
  }
  elseif ($mode == 'users') {
    $rc = array(
      'subject' => t('Amount of users'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {users}")),
    );
  }
  elseif ($mode == 'terms') {
    $rc = array(
      'subject' => t('Terms'),
      'amount' => $this
        ->generate_term_stats(),
    );
  }
  elseif ($mode == 'nodes') {
    $rc = array(
      'subject' => t('Amount of nodes'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {node} WHERE status=1")),
    );
  }
  elseif ($mode == 'node_types') {
    $rc = array(
      'subject' => t('Amount of node types'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {node_type}")),
    );
  }
  elseif ($mode == 'comments') {
    $rc = array(
      'subject' => t('Amount of comments'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {comments}")),
    );
  }
  elseif ($mode == 'aliases') {
    $rc = array(
      'subject' => t('Amount of aliases'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {url_alias}")),
    );
  }
  elseif ($mode == 'sessions') {
    $rc = array(
      'subject' => t('Amount of sessions'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {sessions}")),
    );
  }
  elseif ($mode == 'modules') {
    $modules = module_rebuild_cache();
    $amount = 0;
    foreach ($modules as $values) {
      if ($values->status) {
        $amount++;
      }
    }
    $rc = array(
      'subject' => t('Amount of modules'),
      'amount' => $amount,
    );
  }
  return $rc;
}