Skip to content

Commit

Permalink
MDL-35396 lesson: Fix detailed statistics display for essay questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Geshoski committed May 7, 2019
1 parent 0442f44 commit 29924b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions mod/lesson/lang/en/lesson.php
Expand Up @@ -202,6 +202,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['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';
Expand Down Expand Up @@ -568,6 +569,7 @@
$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';
Expand Down
17 changes: 13 additions & 4 deletions mod/lesson/pagetypes/essay.php
Expand Up @@ -213,13 +213,16 @@ public function stats(array &$pagestats, $tries) {
return true;
}
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) {
global $PAGE, $DB;

$formattextdefoptions = new stdClass();
$formattextdefoptions->noclean = true;
$formattextdefoptions->para = false;
$formattextdefoptions->context = $answerpage->context;
$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) {
Expand All @@ -239,7 +242,7 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
}
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 {
Expand All @@ -250,17 +253,23 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
}
} 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,
Expand Down

0 comments on commit 29924b6

Please sign in to comment.