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

This commit is contained in:
Mihail Geshoski 2019-05-07 13:55:11 +08:00
parent a411b499b9
commit 8ac1820b57
2 changed files with 15 additions and 5 deletions

View File

@ -206,6 +206,7 @@ $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['essayemailmessagesmall'] = '<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';
@ -573,6 +574,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';

View File

@ -292,7 +292,8 @@ class lesson_page_type_essay extends lesson_page {
return true;
}
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) {
global $PAGE;
global $PAGE, $DB;
$formattextdefoptions = new stdClass();
$formattextdefoptions->noclean = true;
$formattextdefoptions->para = false;
@ -300,6 +301,7 @@ class lesson_page_type_essay extends lesson_page {
$answers = $this->get_answers();
$context = context_module::instance($PAGE->cm->id);
foreach ($answers as $answer) {
$hasattempts = $DB->record_exists('lesson_attempts', ['answerid' => $answer->id]);
if ($useranswer != null) {
$essayinfo = self::extract_useranswer($useranswer->useranswer);
$essayinfo->answer = file_rewrite_pluginfile_urls($essayinfo->answer, 'pluginfile.php',
@ -322,7 +324,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 {
@ -333,17 +335,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,