diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php index f007c1c55e6..93941c88264 100644 --- a/mod/quiz/report/attemptsreport.php +++ b/mod/quiz/report/attemptsreport.php @@ -149,7 +149,7 @@ abstract class quiz_attempt_report extends quiz_default_report { $fields .= "\n(CASE WHEN $qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,"; } - $fields .= " + $fields .= ' quiza.uniqueid AS usageid, quiza.id AS attempt, u.id AS userid, @@ -164,7 +164,15 @@ abstract class quiz_attempt_report extends quiz_default_report { quiza.sumgrades, quiza.timefinish, quiza.timestart, - quiza.timefinish - quiza.timestart AS duration"; + CASE WHEN qa.timefinish = 0 THEN null + WHEN qa.timefinish > qa.timestart THEN qa.timefinish - qa.timestart + ELSE 0 END AS duration'; + // To explain that last bit, in MySQL, qa.timestart and qa.timefinish + // are unsigned. Since MySQL 5.5.5, when they introduced strict mode, + // subtracting a larger unsigned int from a smaller one gave an error. + // Therefore, we avoid doing that. timefinish can be non-zero and less + // than timestart when you have two load-balanced servers with very + // badly synchronised clocks, and a student does a really quick attempt.'; // This part is the same for all cases - join users and quiz_attempts tables $from = "\n{user} u";