MDL-35396 lesson: Fix detailed statistics display for essay questions

This commit is contained in:
Mihail Geshoski
2019-05-07 14:00:58 +08:00
parent 6e311854b7
commit 5ddac4b5b9
2 changed files with 15 additions and 4 deletions
+2
View File
@@ -202,6 +202,7 @@ $string['eolstudentoutoftimenoanswers'] = 'You did not answer any questions. Yo
$string['essay'] = 'Essay';
$string['essayemailmessage2'] = '<p>Essay prompt: {$a->question}</p><p>Your response: <em>{$a->response}</em></p><p>Grader\'s comments: <em>{$a->comment}</em></p><p>You have received {$a->earned} out of {$a->outof} for this essay question.</p><p>Your grade for the {$a->lesson} lesson has been changed to {$a->newgrade}&#37;.</p>';
$string['essayemailsubject'] = 'Grade available for lesson question';
$string['essaynotgradedyet'] = 'This essay has not been graded yet';
$string['essayresponses'] = 'Essay responses';
$string['essays'] = 'Essays';
$string['essayscore'] = 'Essay score';
@@ -568,6 +569,7 @@ $string['usepassword_help'] = 'If enabled, a password is required in order to ac
$string['useroverrides'] = 'User overrides';
$string['useroverridesdeleted'] = 'User overrides deleted';
$string['usersnone'] = 'No students have access to this lesson';
$string['viewessayanswers'] = 'View essay answers';
$string['viewgrades'] = 'View grades';
$string['viewreports'] = 'View {$a->attempts} completed {$a->student} attempts';
$string['viewreports2'] = 'View {$a} completed attempts';
+13 -4
View File
@@ -213,6 +213,8 @@ class lesson_page_type_essay extends lesson_page {
return true;
}
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) {
global $PAGE, $DB;
$formattextdefoptions = new stdClass();
$formattextdefoptions->noclean = true;
$formattextdefoptions->para = false;
@@ -220,6 +222,7 @@ class lesson_page_type_essay extends lesson_page {
$answers = $this->get_answers();
foreach ($answers as $answer) {
$hasattempts = $DB->record_exists('lesson_attempts', ['answerid' => $answer->id]);
if ($useranswer != null) {
$essayinfo = self::extract_useranswer($useranswer->useranswer);
if ($essayinfo->response == null) {
@@ -239,7 +242,7 @@ class lesson_page_type_essay extends lesson_page {
}
if ($essayinfo->graded) {
if ($this->lesson->custom) {
$answerdata->score = get_string("pointsearned", "lesson").": ".$essayinfo->score;
$answerdata->score = get_string("pointsearned", "lesson").": " . $essayinfo->score;
} elseif ($essayinfo->score) {
$answerdata->score = get_string("receivedcredit", "lesson");
} else {
@@ -250,17 +253,23 @@ class lesson_page_type_essay extends lesson_page {
}
} else {
$essayinfo = new stdClass();
$essayinfo->answer = get_string("didnotanswerquestion", "lesson");
if ($hasattempts && has_capability('mod/lesson:grade', $answerpage->context)) {
$essayinfo->answer = html_writer::link(new moodle_url("/mod/lesson/essay.php",
['id' => $PAGE->cm->id]), get_string("viewessayanswers", "lesson"));
} else {
$essayinfo->answer = "";
}
$essayinfo->answerformat = null;
}
// The essay question has been graded.
if (isset($pagestats[$this->properties->id])) {
$avescore = $pagestats[$this->properties->id]->totalscore / $pagestats[$this->properties->id]->total;
$avescore = round($avescore, 2);
$avescore = get_string("averagescore", "lesson").": ". $avescore ;
} else {
// dont think this should ever be reached....
$avescore = get_string("nooneansweredthisquestion", "lesson");
$avescore = $hasattempts ? get_string("essaynotgradedyet", "lesson") :
get_string("nooneansweredthisquestion", "lesson");
}
// This is the student's answer so it should be cleaned.
$answerdata->answers[] = array(format_text($essayinfo->answer, $essayinfo->answerformat,