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

Add user stats summary to user stats tab


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 5c23a7a3
......@@ -54,7 +54,7 @@ case 'views':
break;
case 'users':
default:
$data = user_statistics($limit, $offset);
$data = user_statistics($limit, $offset, $sitedata);
}
$js = <<< EOF
......
......@@ -161,6 +161,11 @@ $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';
$string['youraverageuser'] = 'Your Average User...';
$string['statsmaxfriends'] = 'Has %1.1f friends (most is <a href="%s">%s</a> with %d)';
$string['statsmaxviews'] = 'Has made %1.1f views (most is <a href="%s">%s</a> with %d)';
$string['statsmaxgroups'] = 'Is in %1.1f groups (most is <a href="%s">%s</a> with %d)';
$string['statsmaxquotaused'] = 'Has used about %s of disk quota (most is <a href="%s">%s</a> with %s)';
// Site options
$string['adminsonly'] = 'Administrators only';
......
......@@ -230,12 +230,14 @@ function site_statistics($full=false) {
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("
$data['groupmemberaverage'] = $memberships/$data['users'];
$data['strgroupmemberaverage'] = get_string('groupmemberaverage', 'admin', $data['groupmemberaverage']);
$data['viewsperuser'] = get_field_sql("
SELECT (0.0 + COUNT(id)) / COUNT(DISTINCT owner)
FROM {view}
WHERE NOT owner IS NULL AND owner > 0
"));
");
$data['strviewsperuser'] = get_string('viewsperuser', 'admin', $data['viewsperuser']);
}
$data['name'] = get_config('sitename');
......@@ -249,7 +251,7 @@ function site_statistics($full=false) {
return($data);
}
function user_statistics($limit, $offset) {
function user_statistics($limit, $offset, &$sitedata) {
$data = array();
$data['tableheadings'] = array(
get_string('date'),
......@@ -259,7 +261,7 @@ function user_statistics($limit, $offset) {
);
$data['table'] = user_stats_table($limit, $offset);
$maxfriends = get_records_sql_array("
SELECT u.id, SUM(f.friends) AS friends
SELECT u.id, u.firstname, u.lastname, u.preferredname, SUM(f.friends) AS friends
FROM {usr} u INNER JOIN (
SELECT DISTINCT(usr1) AS id, COUNT(usr1) AS friends
FROM {usr_friend}
......@@ -268,10 +270,71 @@ function user_statistics($limit, $offset) {
FROM {usr_friend}
GROUP BY usr2
) f ON u.id = f.id
GROUP BY u.id
GROUP BY u.id, u.firstname, u.lastname, u.preferredname
ORDER BY friends DESC
LIMIT 1", array());
$data['maxfriends'] = $maxfriends[0];
$maxfriends = $maxfriends[0];
$meanfriends = 2 * count_records('usr_friend') / $sitedata['users'];
$data['strmaxfriends'] = get_string(
'statsmaxfriends',
'admin',
$meanfriends,
get_config('wwwroot') . 'user/view.php?id=' . $maxfriends->id,
display_name($maxfriends, null, true),
$maxfriends->friends
);
$maxviews = get_records_sql_array("
SELECT u.id, u.firstname, u.lastname, u.preferredname, COUNT(v.*) AS views
FROM {usr} u JOIN {view} v ON u.id = v.owner
WHERE owner <> 0
GROUP BY u.id, u.firstname, u.lastname, u.preferredname
ORDER BY views DESC
LIMIT 1", array());
$maxviews = $maxviews[0];
$data['strmaxviews'] = get_string(
'statsmaxviews',
'admin',
$sitedata['viewsperuser'],
get_config('wwwroot') . 'user/view.php?id=' . $maxviews->id,
display_name($maxviews, null, true),
$maxviews->views
);
$maxgroups = get_records_sql_array("
SELECT u.id, u.firstname, u.lastname, u.preferredname, COUNT(m.group) AS groups
FROM {usr} u JOIN {group_member} m ON u.id = m.member JOIN {group} g ON m.group = g.id
WHERE g.deleted = 0
GROUP BY u.id, u.firstname, u.lastname, u.preferredname
ORDER BY groups DESC
LIMIT 1", array());
$maxgroups = $maxgroups[0];
$data['strmaxgroups'] = get_string(
'statsmaxgroups',
'admin',
$sitedata['groupmemberaverage'],
get_config('wwwroot') . 'user/view.php?id=' . $maxgroups->id,
display_name($maxgroups, null, true),
$maxgroups->groups
);
$maxquotaused = get_records_sql_array("
SELECT id, firstname, lastname, preferredname, quotaused
FROM {usr}
WHERE deleted = 0 AND id > 0
ORDER BY quotaused DESC
LIMIT 1", array());
$maxquotaused = $maxquotaused[0];
$data['strmaxquotaused'] = get_string(
'statsmaxquotaused',
'admin',
display_size(get_field('usr', 'AVG(quotaused)', 'deleted', 0)),
get_config('wwwroot') . 'user/view.php?id=' . $maxquotaused->id,
display_name($maxquotaused, null, true),
display_size($maxquotaused->quotaused)
);
$smarty = smarty_core();
$smarty->assign('data', $data);
$data['summary'] = $smarty->fetch('admin/userstatssummary.tpl');
return $data;
}
......
......@@ -172,6 +172,9 @@ input#register_register {
#site-stats-graph {
margin: 0 .3em 1em;
}
.statistics-subpage-column {
width: 49%;
}
.admin-home-column {
width: 49%;
......
......@@ -12,12 +12,15 @@
</ul>
<div class="subpage rel">
<div id="statistics_table_container">
<table id="statistics_table" class="fullwidth listing">
<div class="statistics-subpage-column fl">
{$subpagedata.summary}
</div>
<div id="statistics_table_container" class="statistics-subpage-column fr">
<table id="statistics_table" class="fullwidth">
<thead>
<tr>
{foreach from=$subpagedata.tableheadings item=heading}
<th>{$heading}</th>
<th>{$heading|escape}</th>
{/foreach}
<tr>
</thead>
......@@ -25,8 +28,9 @@
{$subpagedata.table.tablerows}
</tbody>
</table>
</div>
{$subpagedata.table.pagination}
</div>
<div class="cb"></div>
</div>
{/if}
......
......@@ -16,11 +16,11 @@ addLoadEvent(function () {literal}{{/literal}
{/if}
{if $sitedata.groups}
<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>&nbsp;{$sitedata.strgroupmemberaverage}</p>
{/if}
{if $sitedata.views}
<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>&nbsp;{$sitedata.strviewsperuser}</p>
{/if}
<p><strong>{str tag=databasesize section=admin}:</strong> {$sitedata.dbsize|display_size}</p>
{if $sitedata.diskusage}
......
<h3>{str tag=youraverageuser section=admin}</h3>
<ul>
<li>{$data.strmaxfriends}</li>
<li>{$data.strmaxviews}</li>
<li>{$data.strmaxgroups}</li>
<li>{$data.strmaxquotaused}</li>
</ul>
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