Commit 241af784 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Show secondary stats for users, groups, views


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent e26f8d05
......@@ -151,6 +151,10 @@ $string['siteinstalled'] = 'Site Installed';
$string['databasesize'] = 'Database Size';
$string['diskusage'] = 'Disk Usage';
$string['maharaversion'] = 'Mahara version';
$string['activeusers'] = 'Active users';
$string['loggedinsince'] = '%s today, %s since %s, %s all time';
$string['groupmemberaverage'] = 'On average, each user is in %1.1f groups';
$string['viewsperuser'] = 'Users who make views have about %1.1f views each';
// Site options
$string['adminsonly'] = 'Administrators only';
......
......@@ -212,6 +212,34 @@ function site_statistics() {
$data['dbsize'] = db_total_size();
$data['diskusage'] = get_field('site_data', 'value', 'type', 'disk-usage');
if (is_postgres()) {
$weekago = "CURRENT_DATE - INTERVAL '1 week'";
$thisweeksql = "(lastaccess > $weekago)::int";
$todaysql = '(lastaccess > CURRENT_DATE)::int';
$eversql = "(NOT lastaccess IS NULL)::int";
}
else {
$weekago = 'CURRENT_DATE - INTERVAL 1 WEEK';
$thisweeksql = "lastaccess > $weekago";
$todaysql = 'lastaccess > CURRENT_DATE';
$eversql = "NOT lastaccess IS NULL";
}
$sql = "SELECT SUM($todaysql) AS today, SUM($thisweeksql) AS thisweek, $weekago AS weekago, SUM($eversql) AS ever FROM {usr}";
$active = get_record_sql($sql);
$data['usersloggedin'] = get_string('loggedinsince', 'admin', $active->today, $active->thisweek, format_date(strtotime($active->weekago), 'strftimedateshort'), $active->ever);
$memberships = count_records_sql("
SELECT COUNT(*)
FROM {group_member} m JOIN {group} g ON g.id = m.group
WHERE g.deleted = 0
");
$data['groupmemberaverage'] = get_string('groupmemberaverage', 'admin', $memberships/$data['users']);
$data['viewsperuser'] = get_string('viewsperuser', 'admin', get_field_sql("
SELECT (0.0 + COUNT(id)) / COUNT(DISTINCT owner)
FROM {view}
WHERE NOT owner IS NULL AND owner > 0
"));
return($data);
}
......
......@@ -11,8 +11,11 @@ addLoadEvent(function () {literal}{{/literal}
<h3>{$sitedata.name}: {str tag=sitestatistics section=admin}</h3>
<p><strong>{str tag=siteinstalled section=admin}:</strong> {$sitedata.installdate}</p>
<p><strong>{str tag=users}:</strong> {$sitedata.users}{if $sitedata.rank.users} ({str tag=Rank section=admin}: $sitedata.rank.users}){/if}</p>
<p>&nbsp;{str tag=activeusers section=admin}: {$sitedata.usersloggedin}</p>
<p><strong>{str tag=groups}:</strong> {$sitedata.groups}{if $sitedata.rank.groups} ({str tag=Rank section=admin}: $sitedata.rank.groups}){/if}</p>
<p>&nbsp;{$sitedata.groupmemberaverage}</p>
<p><strong>{str tag=views}:</strong> {$sitedata.views}{if $sitedata.rank.views} ({str tag=Rank section=admin}: $sitedata.rank.views}){/if}</p>
<p>&nbsp;{$sitedata.viewsperuser}</p>
<p><strong>{str tag=databasesize section=admin}:</strong> {$sitedata.dbsize|display_size}</p>
<p><strong>{str tag=diskusage section=admin}:</strong> {$sitedata.diskusage|display_size}</p>
<p><strong>{str tag=maharaversion section=admin}:</strong> {$sitedata.release}</p>
......
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