public function StatsPro::get_stats in Statistics Pro 6.2
Same name and namespace in other branches
- 6 statspro.inc \statspro::get_stats()
Get statistics for output.
File
- ./
statspro.inc, line 183 - statspro class for Statistics Pro module.
Class
- StatsPro
- Manages the data saving and retrieval according to the user defined parameters.
Code
public function get_stats($period, $whitelist = NULL, $blacklist = NULL) {
$this->period = $period;
$with_data = FALSE;
// build field list
$fields = $this
->get_calc_fields($whitelist, $blacklist);
// initialize values
$data = array();
foreach ($fields as $field => $desc) {
$data[$field] = 0;
}
// get values
$sql_fields = 'day, nuser, auser, nnode, cnode, comment';
if (module_exists('statistics')) {
$sql_fields .= ', pi, upi';
}
$sql_fields .= ', error, uerror,
warning, uwarning, emergency, uemergency, alert, ualert, critical,
ucritical';
$sql = "\n SELECT\n {$sql_fields}\n FROM {statspro}\n WHERE " . $this
->get_period();
$result = db_query($sql);
while ($row = db_fetch_array($result)) {
foreach ($fields as $field => $desc) {
$data[$field] += $row[$field];
if (!$with_data && $row[$field] > 0) {
$with_data = TRUE;
}
}
}
if ($with_data) {
// prepare return array
$rows = array();
foreach ($fields as $field => $desc) {
$rows[] = array(
$desc,
$data[$field],
);
}
return $rows;
}
}