Commit b5161d80 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Graph historical user/group/view counts on admin home page


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 4d0f782b
......@@ -78,7 +78,7 @@ if (empty($upgrades)) {
$sitedata = site_statistics();
if (!empty($sitedata['weekly'])) {
$jsfiles = array('js/PlotKit/excanvas.js', 'js/PlotKit/PlotKit.js');
$sitedata['dataarray'] = json_encode($sitedata['weekly']);
$sitedata['dataarray'] = json_encode(array($sitedata['weekly']['view-count'], $sitedata['weekly']['user-count'], $sitedata['weekly']['group-count']));
}
}
......
......@@ -2209,21 +2209,24 @@ function cron_send_registration_data() {
* Cronjob to save weekly site data locally
*/
function cron_site_data_weekly() {
require_once(get_config('libroot') . 'registration.php');
$current = site_data_current();
$time = db_format_timestamp(time());
insert_record('site_data', (object) array(
'ctime' => $time,
'type' => 'user-count',
'value' => count_records_select('usr', 'id > 0 AND deleted = 0'),
'value' => $current['users'],
));
insert_record('site_data', (object) array(
'ctime' => $time,
'type' => 'group-count',
'value' => count_records('group', 'deleted', 0),
'value' => $current['groups'],
));
insert_record('site_data', (object) array(
'ctime' => $time,
'type' => 'view-count',
'value' => count_records_select('view', 'owner <> 0'),
'value' => $current['views'],
));
}
......
......@@ -179,7 +179,7 @@ function registration_data() {
return $data_to_send;
}
function site_statistics() {
function site_data_current() {
return array(
'name' => get_config('sitename'),
'users' => count_records_select('usr', 'id > 0 AND deleted = 0'),
......@@ -188,4 +188,25 @@ function site_statistics() {
);
}
function site_statistics() {
$data = site_data_current();
$lastyear = db_format_timestamp(time() - 60*60*12*365);
$values = array($lastyear, 'view-count', 'user-count', 'group-count');
$weekly = get_records_sql_array('
SELECT ctime, type, value, ' . db_format_tsfield('ctime', 'ts') . '
FROM {site_data}
WHERE ctime >= ? AND type IN (?,?,?)
ORDER BY ctime, type', $values);
if ($weekly && count($weekly) > count($values) - 1) {
$data['weekly'] = array('user-count' => array(), 'group-count' => array(), 'view-count' => array());
$keys = array('user-count' => 0, 'group-count' => 0, 'view-count' => 0);
foreach ($weekly as &$r) {
$data['weekly'][$r->type][$keys[$r->type]++] = array($keys[$r->type], $r->value);
}
}
return($data);
}
?>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment