From 5ddac4b5b9d102f5682d554dcf30cf9275f095b5 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Tue, 7 May 2019 13:55:11 +0800 Subject: [PATCH] MDL-35396 lesson: Fix detailed statistics display for essay questions --- mod/lesson/lang/en/lesson.php | 2 ++ mod/lesson/pagetypes/essay.php | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/mod/lesson/lang/en/lesson.php b/mod/lesson/lang/en/lesson.php index 380ea431f77..be1126294c3 100644 --- a/mod/lesson/lang/en/lesson.php +++ b/mod/lesson/lang/en/lesson.php @@ -202,6 +202,7 @@ $string['eolstudentoutoftimenoanswers'] = 'You did not answer any questions. Yo $string['essay'] = 'Essay'; $string['essayemailmessage2'] = '

Essay prompt: {$a->question}

Your response: {$a->response}

Grader\'s comments: {$a->comment}

You have received {$a->earned} out of {$a->outof} for this essay question.

Your grade for the {$a->lesson} lesson has been changed to {$a->newgrade}%.

'; $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'; diff --git a/mod/lesson/pagetypes/essay.php b/mod/lesson/pagetypes/essay.php index 992200d4754..c1ad68cb03f 100644 --- a/mod/lesson/pagetypes/essay.php +++ b/mod/lesson/pagetypes/essay.php @@ -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,