Skip to content

Commit

Permalink
MDL-37250 mod_lesson: All actual attempts on the lesson are displayed.
Browse files Browse the repository at this point in the history
The lesson overview report now shows all attempts made including hitting
the page and immediately navigating away.
  • Loading branch information
abgreeve committed Jul 11, 2016
1 parent 0324fef commit c77ade8
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions mod/lesson/report.php
Expand Up @@ -123,16 +123,22 @@
// Only load students if there attempts for this lesson.
$attempts = $DB->record_exists('lesson_attempts', array('lessonid' => $lesson->id));
$branches = $DB->record_exists('lesson_branch', array('lessonid' => $lesson->id));
if ($attempts or $branches) {
$timer = $DB->record_exists('lesson_timer', array('lessonid' => $lesson->id));
if ($attempts or $branches or $timer) {
list($esql, $params) = get_enrolled_sql($context, '', $currentgroup, true);
list($sort, $sortparams) = users_order_by_sql('u');

$params['lessonid'] = $lesson->id;
$ufields = user_picture::fields('u');
$sql = "SELECT DISTINCT $ufields
FROM {user} u
JOIN (SELECT userid, lessonid FROM {lesson_attempts} a1 UNION
SELECT userid, lessonid FROM {lesson_branch} b1) a ON u.id = a.userid
JOIN (
SELECT userid, lessonid FROM {lesson_attempts} a1
UNION
SELECT userid, lessonid FROM {lesson_branch} b1
UNION
SELECT userid, lessonid FROM {lesson_timer} c1
) a ON u.id = a.userid
JOIN ($esql) ue ON ue.id = a.userid
WHERE a.lessonid = :lessonid
ORDER BY $sort";
Expand Down Expand Up @@ -271,6 +277,43 @@
}
$branches->close();

// Need the same thing for timed entries that were not completed.
foreach ($times as $time) {
$endoflesson = $time->completed;
// If the time start is the same with another record then we shouldn't be adding another item to this array.
if (isset($studentdata[$time->userid])) {
$foundmatch = false;
$n = 0;
foreach ($studentdata[$time->userid] as $key => $value) {
if ($value['timestart'] == $time->starttime) {
// Don't add this to the array.
$foundmatch = true;
break;
}
}
$n = count($studentdata[$time->userid]) + 1;
if (!$foundmatch) {
// Add a record.
$studentdata[$time->userid][] = array(
"timestart" => $time->starttime,
"timeend" => $time->lessontime,
"grade" => null,
"end" => $endoflesson,
"try" => $n,
"userid" => $time->userid
);
}
} else {
$studentdata[$time->userid][] = array(
"timestart" => $time->starttime,
"timeend" => $time->lessontime,
"grade" => null,
"end" => $endoflesson,
"try" => 0,
"userid" => $time->userid
);
}
}
// Determine if lesson should have a score.
if ($branchcount > 0 AND $questioncount == 0) {
// This lesson only contains content pages and is not graded.
Expand Down

0 comments on commit c77ade8

Please sign in to comment.