Skip to content

Commit

Permalink
MDL-50516 mod_lesson: fixed issue with grade not using minquestions
Browse files Browse the repository at this point in the history
It's possible to reach the end of the lesson, get your result,
click back until you get to the last question, answer it correctly
and then be awarded a result of 100%. This was because the grade
calculation would only include the questions answered, rather than
all of them in the lesson. However, you can not fix this by always
grading by the amount of questions in the lesson as some lessons
bypass certain questions depending on the answer to previous ones.
The minquestion setting can now successfully be used to prevent this
behaviour by rewording the misleading string and adding logic.
  • Loading branch information
mdjnelson authored and andrewnicols committed Sep 9, 2015
1 parent e7288ea commit ca74203
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 67 deletions.
6 changes: 2 additions & 4 deletions mod/lesson/lang/en/lesson.php
Expand Up @@ -258,9 +258,7 @@
$string['mediawidth'] = 'Popup window width:';
$string['messageprovider:graded_essay'] = 'Essay graded notification';
$string['minimumnumberofquestions'] = 'Minimum number of questions';
$string['minimumnumberofquestions_help'] = 'This setting specifies the minimum number of questions that will be used to calculate a grade for the activity. If the lesson contains one or more content pages, the minimum number of questions should be set to zero.
If set to say 20, it is suggested that the following text is added to the opening page of the lesson: "In this lesson you are expected to attempt at least 20 questions. You can attempt more if you wish. However, if you attempt less than 20 questions, your grade will be calculated as though you attempted 20."';
$string['minimumnumberofquestions_help'] = 'This setting specifies the minimum number of questions that will be used to calculate a grade for the activity.';
$string['missingname'] = 'Please enter a nickname';
$string['modattempts'] = 'Allow student review';
$string['modattempts_help'] = 'If enabled, students can navigate through the lesson again from the start.';
Expand Down Expand Up @@ -316,7 +314,7 @@
$string['numberofpagestoshow'] = 'Number of pages to show';
$string['numberofpagestoshow_help'] = 'This setting specifies the number of pages shown in a lesson. It is only applicable for lessons with pages shown in a random order (when "Action after correct answer" is set to "Show an unseen page" or "Show an unanswered page"). If set to zero, then all pages are shown.';
$string['numberofpagesviewed'] = 'Number of questions answered: {$a}';
$string['numberofpagesviewednotice'] = 'Number of questions answered: {$a->nquestions}; (You should answer at least: {$a->minquestions})';
$string['numberofpagesviewednotice'] = 'Number of questions answered: {$a->nquestions} (You should answer at least {$a->minquestions})';
$string['numerical'] = 'Numerical';
$string['ongoing'] = 'Display ongoing score';
$string['ongoing_help'] = 'If enabled, each page will display the student\'s current points earned out of the total possible thus far.';
Expand Down
149 changes: 86 additions & 63 deletions mod/lesson/view.php
Expand Up @@ -410,84 +410,107 @@
// Used to check to see if the student ran out of time
$outoftime = optional_param('outoftime', '', PARAM_ALPHA);

// We are using level 3 header because the page title is a sub-heading of lesson title (MDL-30911).
$lessoncontent .= $OUTPUT->heading(get_string("congratulations", "lesson"), 3);
$lessoncontent .= $OUTPUT->box_start('generalbox boxaligncenter');
$ntries = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
if (isset($USER->modattempts[$lesson->id])) {
$ntries--; // need to look at the old attempts :)
}

$gradelesson = true;
$gradeinfo = lesson_grade($lesson, $ntries);
if ($lesson->custom && !$canmanage) {
// Before we calculate the custom score make sure they answered the minimum
// number of questions. We only need to do this for custom scoring as we can
// not get the miniumum score the user should achieve. If we are not using
// custom scoring (so all questions are valued as 1) then we simply check if
// they answered more than the minimum questions, if not, we mark it out of the
// number specified in the minimum questions setting - which is done in lesson_grade().
// Get the number of answers given.
if ($gradeinfo->nquestions < $lesson->minquestions) {
$gradelesson = false;
$a = new stdClass;
$a->nquestions = $gradeinfo->nquestions;
$a->minquestions = $lesson->minquestions;
$lessoncontent .= $OUTPUT->box_start('generalbox boxaligncenter');
$lesson->add_message(get_string('numberofpagesviewednotice', 'lesson', $a));
}
}
if ($gradelesson) {
// We are using level 3 header because the page title is a sub-heading of lesson title (MDL-30911).
$lessoncontent .= $OUTPUT->heading(get_string("congratulations", "lesson"), 3);
$lessoncontent .= $OUTPUT->box_start('generalbox boxaligncenter');
}
if (!$canmanage) {
// Update the clock / get time information for this user.
$lesson->stop_timer();
$gradeinfo = lesson_grade($lesson, $ntries);

if ($gradeinfo->attempts) {
if (!$lesson->custom) {
$lessoncontent .= $lessonoutput->paragraph(get_string("numberofpagesviewed", "lesson", $gradeinfo->nquestions), 'center');
if ($lesson->minquestions) {
if ($gradeinfo->nquestions < $lesson->minquestions) {
// print a warning and set nviewed to minquestions
$lessoncontent .= $lessonoutput->paragraph(get_string("youshouldview", "lesson", $lesson->minquestions), 'center');
if ($gradelesson) {
// Update the clock / get time information for this user.
$lesson->stop_timer();
$gradeinfo = lesson_grade($lesson, $ntries);

if ($gradeinfo->attempts) {
if (!$lesson->custom) {
$lessoncontent .= $lessonoutput->paragraph(get_string("numberofpagesviewed", "lesson", $gradeinfo->nquestions), 'center');
if ($lesson->minquestions) {
if ($gradeinfo->nquestions < $lesson->minquestions) {
// print a warning and set nviewed to minquestions
$lessoncontent .= $lessonoutput->paragraph(get_string("youshouldview", "lesson", $lesson->minquestions), 'center');
}
}
$lessoncontent .= $lessonoutput->paragraph(get_string("numberofcorrectanswers", "lesson", $gradeinfo->earned), 'center');
}
$lessoncontent .= $lessonoutput->paragraph(get_string("numberofcorrectanswers", "lesson", $gradeinfo->earned), 'center');
}
$a = new stdClass;
$a->score = $gradeinfo->earned;
$a->grade = $gradeinfo->total;
if ($gradeinfo->nmanual) {
$a->tempmaxgrade = $gradeinfo->total - $gradeinfo->manualpoints;
$a->essayquestions = $gradeinfo->nmanual;
$lessoncontent .= $OUTPUT->box(get_string("displayscorewithessays", "lesson", $a), 'center');
} else {
$lessoncontent .= $OUTPUT->box(get_string("displayscorewithoutessays", "lesson", $a), 'center');
}
$a = new stdClass;
$a->grade = number_format($gradeinfo->grade * $lesson->grade / 100, 1);
$a->total = $lesson->grade;
$lessoncontent .= $lessonoutput->paragraph(get_string("yourcurrentgradeisoutof", "lesson", $a), 'center');

$grade = new stdClass();
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = $gradeinfo->grade;
$grade->completed = time();
if (!$lesson->practice) {
if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record
if (!$grades = $DB->get_records("lesson_grades", array("lessonid" => $lesson->id, "userid" => $USER->id), "completed DESC", '*', 0, 1)) {
print_error('cannotfindgrade', 'lesson');
}
$oldgrade = array_shift($grades);
$grade->id = $oldgrade->id;
$DB->update_record("lesson_grades", $grade);
$a = new stdClass;
$a->score = $gradeinfo->earned;
$a->grade = $gradeinfo->total;
if ($gradeinfo->nmanual) {
$a->tempmaxgrade = $gradeinfo->total - $gradeinfo->manualpoints;
$a->essayquestions = $gradeinfo->nmanual;
$lessoncontent .= $OUTPUT->box(get_string("displayscorewithessays", "lesson", $a), 'center');
} else {
$newgradeid = $DB->insert_record("lesson_grades", $grade);
$lessoncontent .= $OUTPUT->box(get_string("displayscorewithoutessays", "lesson", $a), 'center');
}
} else {
$DB->delete_records("lesson_attempts", array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries));
}
} else {
if ($lesson->timed) {
if ($outoftime == 'normal') {
$grade = new stdClass();
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = 0;
$grade->completed = time();
if (!$lesson->practice) {
$a = new stdClass;
$a->grade = number_format($gradeinfo->grade * $lesson->grade / 100, 1);
$a->total = $lesson->grade;
$lessoncontent .= $lessonoutput->paragraph(get_string("yourcurrentgradeisoutof", "lesson", $a), 'center');

$grade = new stdClass();
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = $gradeinfo->grade;
$grade->completed = time();
if (!$lesson->practice) {
if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record
if (!$grades = $DB->get_records("lesson_grades", array("lessonid" => $lesson->id, "userid" => $USER->id), "completed DESC", '*', 0, 1)) {
print_error('cannotfindgrade', 'lesson');
}
$oldgrade = array_shift($grades);
$grade->id = $oldgrade->id;
$DB->update_record("lesson_grades", $grade);
} else {
$newgradeid = $DB->insert_record("lesson_grades", $grade);
}
$lessoncontent .= get_string("eolstudentoutoftimenoanswers", "lesson");
} else {
$DB->delete_records("lesson_attempts", array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries));
}
} else {
$lessoncontent .= get_string("welldone", "lesson");
if ($lesson->timed) {
if ($outoftime == 'normal') {
$grade = new stdClass();
$grade->lessonid = $lesson->id;
$grade->userid = $USER->id;
$grade->grade = 0;
$grade->completed = time();
if (!$lesson->practice) {
$newgradeid = $DB->insert_record("lesson_grades", $grade);
}
$lessoncontent .= get_string("eolstudentoutoftimenoanswers", "lesson");
}
} else {
$lessoncontent .= get_string("welldone", "lesson");
}
}
}

// update central gradebook
lesson_update_grades($lesson, $USER->id);

// update central gradebook
lesson_update_grades($lesson, $USER->id);
}
} else {
// display for teacher
$lessoncontent .= $lessonoutput->paragraph(get_string("displayofgrade", "lesson"), 'center');
Expand Down

0 comments on commit ca74203

Please sign in to comment.