diff --git a/report/participation/index.php b/report/participation/index.php index 9df2fa23399..3bb24c4236f 100644 --- a/report/participation/index.php +++ b/report/participation/index.php @@ -83,7 +83,8 @@ $PAGE->set_title(format_string($course->shortname, true, array('context' => $con $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. @@ -104,31 +105,6 @@ if (!$onlyuselegacyreader && empty($logtable)) { $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); @@ -157,6 +133,7 @@ $groupmode = groups_get_course_groupmode($course); $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, @@ -253,11 +230,6 @@ if (!empty($instanceid) && !empty($roleid)) { $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 @@ -266,7 +238,7 @@ if (!empty($instanceid) && !empty($roleid)) { 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.