MDL-46015 lesson: Optimise report - use recordsets

Change-Id: I61f3ed30c6dbd8f88d1dfb1adfe2fc291853e0e1
This commit is contained in:
Eugene Venter 2014-06-18 10:12:40 +12:00 committed by Jean-Michel Vedrine
parent eb1dc9fab9
commit 53339437cd

View File

@ -64,7 +64,8 @@ if (!empty($cm->groupingid)) {
ORDER BY $sort";
}
if (! $students = $DB->get_records_sql($sql, $params)) {
$students = $DB->get_recordset_sql($sql, $params);
if (!$students->valid()) {
$nothingtodisplay = true;
}
@ -83,7 +84,8 @@ if ($action == 'reportoverview') {
$lessonoutput = $PAGE->get_renderer('mod_lesson');
if (! $attempts = $DB->get_records('lesson_attempts', array('lessonid' => $lesson->id), 'timeseen')) {
$attempts = $DB->get_recordset('lesson_attempts', array('lessonid' => $lesson->id), 'timeseen');
if (!$attempts->valid()) {
$nothingtodisplay = true;
}
@ -221,6 +223,7 @@ if ($action === 'delete') {
"userid" => $attempt->userid);
}
}
$attempts->close();
// set all the stats variables
$numofattempts = 0;
$avescore = 0;
@ -306,6 +309,7 @@ if ($action === 'delete') {
$table->data[] = array($studentname, $attempts, $bestgrade."%");
}
}
$students->close();
// print it all out !
if (has_capability('mod/lesson:edit', $context)) {
echo "<form id=\"theform\" method=\"post\" action=\"report.php\">\n
@ -535,7 +539,7 @@ if ($action === 'delete') {
$table->data[] = array(get_string("notcompleted", "lesson"));
} else {
$user = $students[$userid];
$user = $DB->get_record('user', array('id' => $userid));
$gradeinfo = lesson_grade($lesson, $try, $user->id);