Skip to content

Commit

Permalink
Added sanity check before calculating grade.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingdon committed Feb 17, 2004
1 parent 7a38bf2 commit 9aba486
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 22 deletions.
1 change: 1 addition & 0 deletions mod/lesson/lesson.php
Expand Up @@ -5,6 +5,7 @@
addpage addpage
confirmdelete confirmdelete
continue
delete delete
editpage editpage
insertpage insertpage
Expand Down
89 changes: 67 additions & 22 deletions mod/lesson/view.php
Expand Up @@ -175,28 +175,73 @@
print_simple_box_start("center"); print_simple_box_start("center");
$ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
if (isstudent($course->id)) { if (isstudent($course->id)) {
$ncorrect = count_records_select("lesson_attempts", "lessonid = $lesson->id AND // do a sanity check on the user's path through the lesson
userid = $USER->id AND retry = $ntries AND correct = 1"); if ($attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND
$nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, userid = $USER->id AND retry = $ntries", "timeseen ASC")) {
"retry", $ntries); $check = true;
if ($nviewed) { if (!$thispageid = get_field("lesson_pages", "id", "lessonid", $lesson->id,
$thegrade = intval(100 * $ncorrect / $nviewed); "prevpageid", 0)) {
error("Navigation Check: first page not found");
}
foreach ($attempts as $attempt) {
// skip any page without answers
while (!$answers = get_records("lesson_answers", "pageid", $thispageid)) {
if (!$thispageid = get_field("lesson_pages", "nextpageid", "id", $thispageid)) {
error("Navigation Check: nextpageid not found");
}
}
if ($attempt->pageid != $thispageid) {
// something odd
// echo "<p>\$thispageid: $thispageid; \$attempt->pageid: $attempt->pageid</p>\n";
$check = false;
break;
}
if (!$answer = get_record("lesson_answers", "id", $attempt->answerid)) {
error("Navigation Check: answer not found");
}
if ($answer->jumpto) {
if ($answer->jumpto == NEXTPAGE) {
if (!$thispageid = get_field("lesson_pages", "nextpageid", "id",
$thispageid)) {
$thispageid = EOL; // end of foreach loop should have been reached
}
} else {
$thispageid = $answer->jumpto;
}
}
}
if ($check) {
$ncorrect = count_records_select("lesson_attempts", "lessonid = $lesson->id AND
userid = $USER->id AND retry = $ntries AND correct = 1");
$nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid",
$USER->id, "retry", $ntries);
if ($nviewed) {
$thegrade = intval(100 * $ncorrect / $nviewed);
} else {
$thegrade = 0;
}
echo "<p align=\"center\">".get_string("numberofpagesviewed", "lesson", $nviewed).
"</p>\n";
echo "<p align=\"center\">".get_string("numberofcorrectanswers", "lesson", $ncorrect).
"</p>\n";
echo "<p align=\"center\">".get_string("gradeis", "lesson",
number_format($thegrade * $lesson->grade / 100, 1)).
" (".get_string("outof", "lesson", $lesson->grade).")</p>\n";
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = $thegrade;
$grade->completed = time();
if (!$newgradeid = insert_record("lesson_grades", $grade)) {
error("Navigation: grade not inserted");
}
} else {
print_string("sanitycheckfailed", "lesson");
delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id,
"retry", $ntries);
}
} else { } else {
$thegrade = 0; print_string("noattemptrecordsfound", "lesson");
} }
echo "<p align=\"center\">".get_string("numberofpagesviewed", "lesson", $nviewed)."</p>\n";
echo "<p align=\"center\">".get_string("numberofcorrectanswers", "lesson", $ncorrect).
"</p>\n";
echo "<p align=\"center\">".get_string("gradeis", "lesson",
number_format($thegrade * $lesson->grade / 100, 1)).
" (".get_string("outof", "lesson", $lesson->grade).")</p>\n";
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = $thegrade;
$grade->completed = time();
if (!$newgradeid = insert_record("lesson_grades", $grade)) {
error("Navigation: grade not inserted");
}
} else { } else {
// display for teacher // display for teacher
echo "<p align=\"center\">".get_string("displayofgrade", "lesson")."</p>\n"; echo "<p align=\"center\">".get_string("displayofgrade", "lesson")."</p>\n";
Expand Down Expand Up @@ -272,7 +317,7 @@
} else { } else {
// print the pages // print the pages
echo "<center><table cellpadding=\"5\" border=\"0\" width=\"80%\">\n"; echo "<center><table cellpadding=\"5\" border=\"0\" width=\"80%\">\n";
if (isteacheredit($course>id)) { if (isteacheredit($course->id)) {
echo "<tr><td align=\"right\"><a href=\"lesson.php?id=$cm->id&action=addpage&pageid=0\"><small>". echo "<tr><td align=\"right\"><a href=\"lesson.php?id=$cm->id&action=addpage&pageid=0\"><small>".
get_string("addpagehere", "lesson")."</small></a></td></tr>\n"; get_string("addpagehere", "lesson")."</small></a></td></tr>\n";
} }
Expand Down

0 comments on commit 9aba486

Please sign in to comment.