Skip to content

Commit

Permalink
MDL-56835 report_participation: use course timecreated as minlog
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Jul 9, 2019
1 parent d00715e commit 5a9e1bc
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions report/participation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
$PAGE->set_heading(format_string($course->fullname, true, array('context' => $context)));
echo $OUTPUT->header();

$uselegacyreader = false; // Use legacy reader with sql_internal_table_reader to aggregate records.
// Logs will not have been recorded before the course timecreated time.
$minlog = $course->timecreated;
$onlyuselegacyreader = false; // Use only legacy log table to aggregate records.

$logtable = report_participation_get_log_table_name(); // Log table to use for fetaching records.
Expand All @@ -104,31 +105,6 @@

$modinfo = get_fast_modinfo($course);

$minloginternalreader = 0; // Time of first record in sql_internal_table_reader.

if ($onlyuselegacyreader) {
// If no sql_inrenal_reader enabled then get min. time from log table.
$minlog = $DB->get_field_sql('SELECT min(time) FROM {log} WHERE course = ?', array($course->id));
} else {
$uselegacyreader = true;
$minlog = $DB->get_field_sql('SELECT min(time) FROM {log} WHERE course = ?', array($course->id));

// If legacy reader is not logging then get data from new log table.
// Get minimum log time for this course from preferred log reader.
$minloginternalreader = $DB->get_field_sql('SELECT min(timecreated) FROM {' . $logtable . '}
WHERE courseid = ?', array($course->id));
// If new log store has oldest data then don't use old log table.
if (empty($minlog) || ($minloginternalreader <= $minlog)) {
$uselegacyreader = false;
$minlog = $minloginternalreader;
}

// If timefrom is greater then first record in sql_internal_table_reader then get record from sql_internal_table_reader only.
if (!empty($timefrom) && ($minloginternalreader < $timefrom)) {
$uselegacyreader = false;
}
}

// Print first controls.
report_participation_print_filter_form($course, $timefrom, $minlog, $action, $roleid, $instanceid);

Expand Down Expand Up @@ -157,6 +133,7 @@
$currentgroup = $SESSION->activegroup[$course->id][$groupmode][$course->defaultgroupingid];

if (!empty($instanceid) && !empty($roleid)) {
$uselegacyreader = $DB->record_exists('log', ['course' => $course->id]);

// Trigger a report viewed event.
$event = \report_participation\event\report_viewed::create(array('context' => $context,
Expand Down Expand Up @@ -253,11 +230,6 @@
$users = array();
// If using legacy log then get users from old table.
if ($uselegacyreader || $onlyuselegacyreader) {
$limittime = '';
if ($uselegacyreader && !empty($minloginternalreader)) {
$limittime = ' AND time < :tilltime ';
$params['tilltime'] = $minloginternalreader;
}
$sql = "SELECT ra.userid, $usernamefields, u.idnumber, l.actioncount AS count
FROM (SELECT DISTINCT userid FROM {role_assignments} WHERE contextid $relatedctxsql AND roleid = :roleid ) ra
JOIN {user} u ON u.id = ra.userid
Expand All @@ -266,7 +238,7 @@
SELECT userid, COUNT(action) AS actioncount
FROM {log}
WHERE cmid = :instanceid
AND time > :timefrom " . $limittime . $actionsql .
AND time > :timefrom " . $actionsql .
" GROUP BY userid) l ON (l.userid = ra.userid)";
if ($twhere) {
$sql .= ' WHERE '.$twhere; // Initial bar.
Expand Down

0 comments on commit 5a9e1bc

Please sign in to comment.