public function statspro::get_stats in Statistics Pro 6
Same name and namespace in other branches
- 6.2 statspro.inc \StatsPro::get_stats()
Get statictics for output.
File
- ./
statspro.inc, line 145 - 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, $start_date, $end_date, $whitelist = NULL, $blacklist = NULL) {
$this->period = $period;
$this->start_date = $start_date;
$this->end_date = $end_date;
$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 = 'SELECT
day, nuser, auser, nnode, cnode, comment, pi,
upi, error, uerror, warning, uwarning
FROM {statspro} 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;
}
}