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

Add table of detailed daily user statistics


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent f44d4f98
......@@ -34,26 +34,31 @@ require(get_config('libroot') . 'registration.php');
define('TITLE', get_string('sitestatistics', 'admin'));
$sitedata = site_statistics(true);
if (!empty($sitedata['weekly'])) {
$jsfiles = array('js/PlotKit/excanvas.js', 'js/PlotKit/PlotKit.js');
$sitedata['dataarray'] = json_encode(array($sitedata['weekly']['view-count'], $sitedata['weekly']['user-count'], $sitedata['weekly']['group-count']));
}
$type = param_alpha('type', 'users');
$subpages = array('users', 'groups', 'views');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
if (!in_array($type, $subpages)) {
$type = 'users';
}
$smarty = smarty($jsfiles);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$sitedata = site_statistics(true);
if (isset($sitedata)) {
$smarty->assign('sitedata', $sitedata);
$smarty->assign('type', $type);
$smarty->assign('subpages', $subpages);
switch ($type) {
case 'users':
default:
$data = user_statistics($limit, $offset);
}
$smarty = smarty(array('js/PlotKit/excanvas.js', 'js/PlotKit/PlotKit.js'));
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->assign('sitedata', $sitedata);
$smarty->assign('type', $type);
$smarty->assign('subpages', $subpages);
$smarty->assign('subpagedata', $data);
$smarty->display('admin/statistics.tpl');
?>
......@@ -160,6 +160,7 @@ $string['viewsperuser'] = 'Users who make views have about %1.1f views each';
$string['Cron'] = 'Cron';
$string['runningnormally'] = 'Running normally';
$string['cronnotrunning'] = 'Cron is not running.<br>See the <a href="http://wiki.mahara.org/System_Administrator\'s_Guide/Installing_Mahara">installation guide</a> for instructions on how to set it up.';
$string['Loggedin'] = 'Logged in';
// Site options
$string['adminsonly'] = 'Administrators only';
......
......@@ -866,6 +866,8 @@ $string['back'] = 'Back';
$string['backto'] = 'Back to %s';
$string['alphabet'] = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
$string['formatpostbbcode'] = 'You can format your post using BBCode. %sLearn more%s';
$string['Created'] = 'Created';
$string['Total'] = 'Total';
// import related strings (maybe separated later)
$string['importedfrom'] = 'Imported from %s';
......
......@@ -205,6 +205,8 @@ function site_statistics($full=false) {
foreach ($weekly as &$r) {
$data['weekly'][$r->type][$keys[$r->type]++] = array($keys[$r->type], $r->value);
}
// Plotkit Stuff -- to be removed.
$data['dataarray'] = json_encode(array($data['weekly']['view-count'], $data['weekly']['user-count'], $data['weekly']['group-count']));
}
if (is_postgres()) {
......@@ -236,7 +238,7 @@ function site_statistics($full=false) {
"));
}
$data['name'] = get_config('sitename');
$data['name'] = get_config('sitename');
$data['release'] = get_config('release');
$data['version'] = get_config('version');
$data['installdate'] = format_date(strtotime(get_config('installation_time')), 'strftimedate');
......@@ -247,4 +249,109 @@ function site_statistics($full=false) {
return($data);
}
function user_statistics($limit, $offset) {
$data = array();
$data['tableheadings'] = array(
get_string('date'),
get_string('Loggedin', 'admin'),
get_string('Created'),
get_string('Total'),
);
$data['table'] = user_stats_table($limit, $offset);
return $data;
}
function user_stats_table($limit, $offset) {
$count = count_records('site_data', 'type', 'user-count-daily');
$pagination = build_pagination(array(
'id' => 'stats_pagination',
'url' => get_config('wwwroot') . 'admin/statistics.php?type=users',
// @todo: 'jsonscript' => 'admin/statistics.json.php?type=users',
// @todo: 'datatable' => 'statistics_table',
'count' => $count,
'limit' => $limit,
'offset' => $offset,
));
$result = array(
'tablerows' => '',
'pagination' => $pagination['html'],
'pagination_js' => $pagination['javascript'],
);
if ($count < 1) {
return $result;
}
$day = is_postgres() ? "to_date(t.ctime, 'YYYY-MM-DD')" : 'DATE(t.ctime)';
$daterange = get_record_sql(
"SELECT
MIN($day) AS mindate,
MAX($day) AS maxdate
FROM (
SELECT ctime
FROM {site_data}
WHERE type = ?
ORDER BY ctime DESC
LIMIT $limit
OFFSET $offset
) t",
array('user-count-daily')
);
$dayinterval = is_postgres() ? "'1 day'" : '1 day';
$day = is_postgres() ? "to_date(ctime, 'YYYY-MM-DD')" : 'DATE(ctime)';
$userdata = get_records_sql_array(
"SELECT ctime, type, value, $day AS date
FROM {site_data}
WHERE type IN (?,?) AND ctime >= ? AND ctime < (date(?) + (INTERVAL $dayinterval))
ORDER BY type = ? DESC, ctime DESC",
array('user-count-daily', 'loggedin-users-daily', $daterange->mindate, $daterange->maxdate, 'user-count-daily')
);
$userscreated = get_records_sql_array(
"SELECT $day AS date, COUNT(id) AS users
FROM {usr}
WHERE NOT ctime IS NULL
GROUP BY date
ORDER BY date",
array(),
$offset,
$limit
);
$data = array();
if ($userdata) {
foreach ($userdata as &$r) {
if ($r->type == 'user-count-daily') {
$data[$r->date] = array(
'date' => $r->date,
'total' => $r->value,
);
}
else if ($r->type == 'loggedin-users-daily' && isset($data[$r->date])) {
$data[$r->date]['loggedin'] = $r->value;
}
}
if ($userscreated) {
foreach ($userscreated as &$r) {
if (isset($data[$r->date])) {
$data[$r->date]['created'] = $r->users;
}
}
}
}
$smarty = smarty_core();
$smarty->assign('data', $data);
$result['tablerows'] = $smarty->fetch('admin/userstats.tpl');
return $result;
}
?>
\ No newline at end of file
......@@ -12,7 +12,21 @@
</ul>
<div class="subpage rel">
<div id="statistics_table_container">
<table id="statistics_table" class="fullwidth listing">
<thead>
<tr>
{foreach from=$subpagedata.tableheadings item=heading}
<th>{$heading}</th>
{/foreach}
<tr>
</thead>
<tbody>
{$subpagedata.table.tablerows}
</tbody>
</table>
</div>
{$subpagedata.table.pagination}
</div>
{/if}
......
{foreach from=$data item=item}
<tr class="{cycle values='r0,r1'}">
<td>{$item.date}</td>
<td>{$item.loggedin}</td>
<td>{$item.created}</td>
<td>{$item.total}</td>
</tr>
{/foreach}
Markdown is supported
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