You are here

public function StatsPro::get_aggregate_stat in Statistics Pro 6.2

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

File

./statspro.inc, line 120
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, $period = NULL) {
  $rc = FALSE;
  $where_sql = $period === NULL ? '' : 'WHERE ' . $this
    ->get_period('timestamp', TRUE);
  if (in_array($mode, $this->absolute_amounts)) {
    $where_sql = $period === NULL ? '' : 'WHERE ' . $this
      ->get_period();
    $rc = array(
      'subject' => strip_tags($this->fields[$mode]),
      'amount' => db_result(db_query("SELECT SUM(%s) FROM {statspro} " . $where_sql, $mode)),
    );
  }
  elseif ($mode == 'users') {
    $where_sql = $period === NULL ? '' : 'WHERE ' . $this
      ->get_period('created', TRUE);
    $rc = array(
      'subject' => t('Amount of users'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {users} " . $where_sql)),
    );
  }
  elseif ($mode == 'terms') {
    $rc = array(
      'subject' => t('Terms'),
      'amount' => $this
        ->generate_term_stats(),
    );
  }
  elseif ($mode == 'nodes') {
    $where_sql = $period === NULL ? '' : $this
      ->get_period('created', TRUE) . ' AND ';
    $where_sql = 'WHERE ' . $where_sql . ' status = 1';
    $rc = array(
      'subject' => t('Amount of nodes'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {node} " . $where_sql)),
    );
  }
  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') {
    $where_sql = $period === NULL ? '' : 'WHERE ' . $this
      ->get_period('timestamp', TRUE);
    $rc = array(
      'subject' => t('Amount of comments'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {comments} " . $where_sql)),
    );
  }
  elseif ($mode == 'aliases') {
    $rc = array(
      'subject' => t('Amount of aliases'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {url_alias}")),
    );
  }
  elseif ($mode == 'sessions') {
    $where_sql = $period === NULL ? '' : 'WHERE ' . $this
      ->get_period('timestamp', TRUE);
    $rc = array(
      'subject' => t('Amount of sessions'),
      'amount' => db_result(db_query("SELECT COUNT(*) FROM {sessions} " . $where_sql)),
    );
  }
  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;
}