Commit ffde8526 authored by Robert Lyon's avatar Robert Lyon Committed by Kristina Hoeppner
Browse files

Bug 1720883 - Show earliest time data exists for the report



To make choosing 'from' date more realistic

behatnotneeded

Change-Id: Idd11d28e4115989f23cca8046567a72720fe553b
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 5958125c
......@@ -256,7 +256,7 @@ if ($type == 'information' && (empty($subtype) || $subtype == 'information')) {
}
else {
list($subpages, $subpagedata) = display_statistics($institution, $type, $extraparams);
$subpagination = !empty($subpagedata['table']) ? $subpagedata['table']['pagination_js'] : false;
$subpagination = (!empty($subpagedata['table']) && !empty($subpagedata['table']['pagination_js'])) ? $subpagedata['table']['pagination_js'] : false;
$institutiondata = false;
if ($subpagination) {
$js .= <<<JS
......
......@@ -68,6 +68,16 @@ $formarray = report_config_form($extraparams, $institutionelement);
$form = $formarray ? pieform($formarray) : '';
$reportinfo = get_string('reportdesc' . $subtype, 'statistics');
$reportdatestr = '<div class="alert alert-warning">';
if ($date = report_earliest_date($subtype, $institution)) {
$reportdatestr .= get_string('earliestdate', 'statistics', $date);
}
else {
$reportdatestr .= get_string('noearliestdate', 'statistics');
}
$reportdatestr .= '</div>';
$reportinfo .= $reportdatestr;
$tableheaders = '';
$function = $subtype . '_statistics_headers';
if (function_exists($function)) {
......
......@@ -382,3 +382,5 @@ $string['usersinfo'] = 'Users overview';
$string['viewsinfo'] = 'Pages overview';
$string['usersbyinstitution'] = 'Users by institution';
$string['groupsbytype'] = 'Groups by type';
$string['earliestdate'] = 'Data for this report is only available from %s onwards.';
$string['noearliestdate'] = 'There is no data recorded for this report.';
......@@ -4038,3 +4038,86 @@ function userhasaccess($institution, $report) {
$smarty->display('admin/users/noinstitutionsstats.tpl');
exit;
}
function report_earliest_date($subtype, $institution = 'mahara') {
// A quick way to find possible earliest dates for things
// This check accepts the fact that 'mahara' institution must exist first
// therefore the earliest for 'mahara' must be the earliest for 'all'
$institution = ($institution == 'all') ? 'mahara' : $institution;
switch ($subtype) {
case "content":
$date = get_field_sql("SELECT MIN(i.time) FROM {institution_registration} i WHERE i.institution = ?", array($institution));
break;
case "groups":
$date = get_field_sql("SELECT MIN(ctime) FROM {group}");
break;
case "logins":
$date = get_field_sql("SELECT MIN(ctime) FROM {usr_login_data}");
break;
case "collaboration":
if ($institution != 'mahara') {
// base it on when first member joined institution
$date = get_field_sql("SELECT MIN(ctime) FROM {usr_institution} WHERE institution = ?", array($institution));
}
else {
$date = get_field_sql("SELECT MIN(ctime) FROM {view_access}");
}
break;
case "masquerading":
if ($institution != 'mahara') {
$date = get_field_sql("SELECT MIN(el.ctime) FROM {event_log} el
JOIN {usr_institution} ui ON ui.usr = el.realusr
WHERE el.event = 'loginas' AND ui.institution = ?", array($institution));
}
else {
$date = get_field_sql("SELECT MIN(el.ctime) FROM {event_log} el
WHERE el.event = 'loginas' AND el.realusr NOT IN (
SELECT usr FROM {usr_institution}
)");
}
break;
case "useractivity":
if ($institution != 'mahara') {
$date = get_field_sql("SELECT MIN(el.ctime) FROM {event_log} el
JOIN {usr_institution} ui ON ui.usr = el.usr
WHERE el.event != 'loginas' AND ui.institution = ?", array($institution));
}
else {
$date = get_field_sql("SELECT MIN(el.ctime) FROM {event_log} el
WHERE el.event != 'loginas' AND el.usr NOT IN (
SELECT usr FROM {usr_institution}
)");
}
break;
case "pageactivity":
case "accesslist":
if ($institution != 'mahara') {
$date = get_field_sql("SELECT MIN(v.ctime) FROM {view} v
JOIN {usr_institution} ui ON ui.usr = v.owner
WHERE ui.institution = ?", array($institution));
}
else {
$date = get_field_sql("SELECT MIN(v.ctime) FROM {view} v");
}
break;
case "users":
$date = get_field_sql("SELECT MIN(ctime) FROM {institution_data}
WHERE institution = ?", array($institution));
break;
case "userdetails":
case "comparisons":
default:
if ($institution != 'mahara') {
$date = get_field_sql("SELECT MIN(ctime) FROM {usr_institution} WHERE institution = ?", array($institution));
}
else {
$date = get_field_sql("SELECT MIN(ctime) FROM {usr}");
}
break;
}
if (!$date) {
return false;
}
return format_date(strtotime($date), 'strftimedate');
}
......@@ -47,6 +47,9 @@
update_report_config();
}
});
$('#reportconfigform_institution').on('change', function() {
update_report_config();
});
$('#reportconfigform_typesubtype').on('change', function() {
update_report_config();
});
......
......@@ -47,6 +47,9 @@
update_report_config();
}
});
$('#reportconfigform_institution').on('change', function() {
update_report_config();
});
$('#reportconfigform_typesubtype').on('change', function() {
update_report_config();
});
......
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