Commit f8534d8b authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Add registration statistics page for institutions



Change-Id: If0cc457fb678d4b013ccffe4e5e4aecf5d01d9cd
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent d25951a3
......@@ -36,7 +36,7 @@ $extradata = json_decode(param_variable('extradata'));
$institution = (isset($extradata->institution) ? $extradata->institution : 'mahara');
$type = param_alpha('type', 'users');
$subpages = array('users', 'views');
$subpages = array('users', 'views', 'registration');
if (!in_array($type, $subpages)) {
$type = 'users';
}
......@@ -44,6 +44,9 @@ if (!in_array($type, $subpages)) {
$institutiondata = institution_statistics($institution, true);
switch ($type) {
case 'registration':
$data = institution_registration_stats_table($limit, $offset, $institutiondata);
break;
case 'views':
$data = institution_view_stats_table($limit, $offset, $institutiondata);
break;
......
......@@ -60,7 +60,7 @@ $institutionselector = pieform(array(
define('TITLE', get_string('institutionstatisticsfor', 'admin', get_field('institution', 'displayname', 'name', $institution)));
$type = param_alpha('type', 'users');
$subpages = array('users', 'views');
$subpages = array('users', 'views', 'registration');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
......@@ -72,6 +72,9 @@ if (!in_array($type, $subpages)) {
$institutiondata = institution_statistics($institution, true);
switch ($type) {
case 'registration':
$data = institution_registration_statistics($limit, $offset, $institutiondata);
break;
case 'views':
$data = institution_view_statistics($limit, $offset, $institutiondata);
break;
......
......@@ -268,12 +268,16 @@ $string['userstatstabletitle'] = 'Daily user statistics';
$string['groupstatstabletitle'] = 'Biggest groups';
$string['viewstatstabletitle'] = 'Most popular pages';
$string['exportstatsascsv'] = 'Export statistics in CSV format';
$string['nostats'] = 'No statistics available';
// Institutional statistics
$string['statistics'] = 'Statistics';
$string['institutionstatisticsfor'] = 'Institution statistics for \'%s\'';
$string['institutioncreated'] = 'Institution created';
// Registration statistics
$string['registrationstatstabletitle'] = 'Registration statistics for the current week';
// Site options
$string['adminsonly'] = 'Administrators only';
$string['adminsandstaffonly'] = 'Administrators and staff only';
......
......@@ -1034,3 +1034,7 @@ $string['betweenxandy'] = 'Between %s and %s';
// Clean URLs
$string['cleanurlallowedcharacters'] = 'Only lowercase letters from a-z, numbers, and - are allowed.';
// Registration statistics
$string['registration'] = 'Registration';
$string['modified'] = 'Modified';
......@@ -1583,6 +1583,115 @@ function institution_view_type_graph(&$institutiondata) {
}
}
function institution_registration_statistics($limit, $offset, &$institutiondata) {
$data = array();
$data['tableheadings'] = array(
array('name' => '#'),
array('name' => get_string('name')),
array('name' => get_string('modified')),
array('name' => get_string('Total'), 'class' => 'center'),
);
$data['table'] = institution_registration_stats_table($limit, $offset, $institutiondata);
$data['tabletitle'] = get_string('registrationstatstabletitle', 'admin');
$data['summary'] = $data['table']['count'] == 0 ? get_string('nostats', 'admin') : 'FIXME: should something go here?';
return $data;
}
function institution_registration_stats_table($limit, $offset, &$institutiondata) {
global $USER;
$dates = get_records_array('institution_registration', 'institution', $institutiondata['name'], 'time DESC', '*', 0, 2);
if ($dates) {
$count = count_records('institution_registration_data', 'registration_id', $dates[0]->id);
}
else {
$count = 0;
}
if ($count > 1) {
// remove one as it is userloggedin, which is a psuedostat
$count --;
}
$pagination = build_pagination(array(
'id' => 'stats_pagination',
'url' => get_config('wwwroot') . 'admin/users/statistics.php?institution=' . $institutiondata['name'] . '&type=registration',
'jsonscript' => 'admin/users/statistics.json.php',
'datatable' => 'statistics_table',
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'extradata' => array('institution' => $institutiondata['name']),
'setlimit' => true,
));
$result = array(
'count' => $count,
'tablerows' => '',
'pagination' => $pagination['html'],
'pagination_js' => $pagination['javascript'],
);
if ($count < 1) {
return $result;
}
$registrationdata = get_records_sql_assoc(
"SELECT
field, value
FROM {institution_registration_data}
WHERE registration_id = ? AND field != ?
ORDER BY field",
array($dates[0]->id, 'usersloggedin'),
$offset,
$limit
);
if (count($dates) > 1) {
$lastweeks = get_records_sql_assoc(
"SELECT
field, value
FROM {institution_registration_data}
WHERE registration_id = ?
ORDER BY field",
array($dates[1]->id)
);
foreach ($registrationdata as &$d) {
$d->modified = $d->value - (isset($lastweeks[$d->field]->value) ? $lastweeks[$d->field]->value : 0);
}
}
else {
foreach ($registrationdata as &$d) {
$d->modified = $d->value;
}
}
if (isset($registrationdata['count_members'])) {
$registrationdata['count_members']->modified = get_field('institution_registration_data', 'value', 'registration_id', $dates[0]->id, 'field', 'usersloggedin');
}
$csvfields = array('field', 'modified', 'value');
$csv = join(',', $csvfields) . "\n";
foreach ($registrationdata as &$d) {
$data = array();
foreach ($csvfields as $f) {
$data[] = str_replace('"', '""', $d->$f);
}
$csv .= '"' . join('","', $data) . '"' . "\n";
}
$USER->set_download_file($csv, 'registrationstatistics.csv', 'text/csv');
$result['csv'] = true;
$smarty = smarty_core();
$smarty->assign('data', $registrationdata);
$smarty->assign('offset', $offset);
$result['tablerows'] = $smarty->fetch('admin/registrationstats.tpl');
return $result;
}
function graph_site_data_weekly() {
......
{foreach from=$data item=item key=key}
<tr class="{cycle values='r0,r1'}">
<td>{$offset + $dwoo.foreach.default.iteration}</td>
<td><a href="statistics.php?{if $institution}institution={$institution}&{/if}type=historical&field={$item->field}">{str tag=$item->field section=statistics}</a></td>
<td>{$item->modified}</td>
<td class="center">{$item->value}</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