public function display_answers(html_table $table) { $answers = $this->get_answers(); $options = new stdClass(); $options->noclean = true; $options->para = false; $i = 1; $n = 0; foreach ($answers as $answer) { $answer = parent::rewrite_answers_urls($answer); if ($n < 2) { if ($answer->answer != null) { $cells = array(); if ($n == 0) { $cells[] = "<span class=\"label\">" . get_string("correctresponse", "lesson") . '</span>'; } else { $cells[] = "<span class=\"label\">" . get_string("wrongresponse", "lesson") . '</span>'; } $cells[] = format_text($answer->answer, $answer->answerformat, $options); $table->data[] = new html_table_row($cells); } if ($n == 0) { $cells = array(); $cells[] = '<span class="label">' . get_string("correctanswerscore", "lesson") . "</span>: "; $cells[] = $answer->score; $table->data[] = new html_table_row($cells); $cells = array(); $cells[] = '<span class="label">' . get_string("correctanswerjump", "lesson") . "</span>: "; $cells[] = $this->get_jump_name($answer->jumpto); $table->data[] = new html_table_row($cells); } elseif ($n == 1) { $cells = array(); $cells[] = '<span class="label">' . get_string("wronganswerscore", "lesson") . "</span>: "; $cells[] = $answer->score; $table->data[] = new html_table_row($cells); $cells = array(); $cells[] = '<span class="label">' . get_string("wronganswerjump", "lesson") . "</span>: "; $cells[] = $this->get_jump_name($answer->jumpto); $table->data[] = new html_table_row($cells); } if ($n === 0) { $table->data[count($table->data) - 1]->cells[0]->style = 'width:20%;'; } $n++; $i--; } else { $cells = array(); if ($this->lesson->custom && $answer->score > 0) { // if the score is > 0, then it is correct $cells[] = '<span class="labelcorrect">' . get_string("answer", "lesson") . " {$i}</span>: \n"; } else { if ($this->lesson->custom) { $cells[] = '<span class="label">' . get_string("answer", "lesson") . " {$i}</span>: \n"; } else { if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) { $cells[] = '<span class="labelcorrect">' . get_string("answer", "lesson") . " {$i}</span>: \n"; } else { $cells[] = '<span class="label">' . get_string("answer", "lesson") . " {$i}</span>: \n"; } } } $cells[] = format_text($answer->answer, $answer->answerformat, $options); $table->data[] = new html_table_row($cells); $cells = array(); $cells[] = '<span class="label">' . get_string("matchesanswer", "lesson") . " {$i}</span>: "; $cells[] = format_text($answer->response, $answer->responseformat, $options); $table->data[] = new html_table_row($cells); } $i++; } return $table; }
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) { global $PAGE; $answers = $this->get_answers(); $formattextdefoptions = new stdClass(); $formattextdefoptions->para = false; //I'll use it widely in this page foreach ($answers as $answer) { $answer = parent::rewrite_answers_urls($answer, false); if ($useranswer == null && $i == 0) { // I have the $i == 0 because it is easier to blast through it all at once. if (isset($pagestats[$this->properties->id])) { $stats = $pagestats[$this->properties->id]; $total = $stats["total"]; unset($stats["total"]); foreach ($stats as $valentered => $ntimes) { $data = '<input type="text" size="50" disabled="disabled" readonly="readonly" value="' . s($valentered) . '" />'; $percent = $ntimes / $total * 100; $percent = round($percent, 2); $percent .= "% " . get_string("enteredthis", "lesson"); $answerdata->answers[] = array($data, $percent); } } else { $answerdata->answers[] = array(get_string("nooneansweredthisquestion", "lesson"), " "); } $i++; } else { if ($useranswer != null && ($answer->id == $useranswer->answerid || $answer == end($answers))) { // get in here when what the user entered is not one of the answers $data = '<input type="text" size="50" disabled="disabled" readonly="readonly" value="' . s($useranswer->useranswer) . '">'; if (isset($pagestats[$this->properties->id][$useranswer->useranswer])) { $percent = $pagestats[$this->properties->id][$useranswer->useranswer] / $pagestats[$this->properties->id]["total"] * 100; $percent = round($percent, 2); $percent .= "% " . get_string("enteredthis", "lesson"); } else { $percent = get_string("nooneenteredthis", "lesson"); } $answerdata->answers[] = array($data, $percent); if ($answer->id == $useranswer->answerid) { if ($answer->response == null) { if ($useranswer->correct) { $answerdata->response = get_string("thatsthecorrectanswer", "lesson"); } else { $answerdata->response = get_string("thatsthewronganswer", "lesson"); } } else { $answerdata->response = $answer->response; } if ($this->lesson->custom) { $answerdata->score = get_string("pointsearned", "lesson") . ": " . $answer->score; } elseif ($useranswer->correct) { $answerdata->score = get_string("receivedcredit", "lesson"); } else { $answerdata->score = get_string("didnotreceivecredit", "lesson"); } // We have found the correct answer, do not process any more answers. $answerpage->answerdata = $answerdata; break; } else { $answerdata->response = get_string("thatsthewronganswer", "lesson"); if ($this->lesson->custom) { $answerdata->score = get_string("pointsearned", "lesson") . ": 0"; } else { $answerdata->score = get_string("didnotreceivecredit", "lesson"); } } } } $answerpage->answerdata = $answerdata; } return $answerpage; }
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) { $answers = $this->get_answers(); $formattextdefoptions = new stdClass(); //I'll use it widely in this page $formattextdefoptions->para = false; $formattextdefoptions->noclean = true; $formattextdefoptions->context = $answerpage->context; foreach ($answers as $answer) { $answer = parent::rewrite_answers_urls($answer); if ($this->properties->qoption) { if ($useranswer == null) { $userresponse = array(); } else { $userresponse = explode(",", $useranswer->useranswer); } if (in_array($answer->id, $userresponse)) { // make checked $data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[{$i}]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />"; if (!isset($answerdata->response)) { if ($answer->response == null) { if ($useranswer->correct) { $answerdata->response = get_string("thatsthecorrectanswer", "lesson"); } else { $answerdata->response = get_string("thatsthewronganswer", "lesson"); } } else { $answerdata->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions); } } if (!isset($answerdata->score)) { if ($this->lesson->custom) { $answerdata->score = get_string("pointsearned", "lesson") . ": " . $answer->score; } elseif ($useranswer->correct) { $answerdata->score = get_string("receivedcredit", "lesson"); } else { $answerdata->score = get_string("didnotreceivecredit", "lesson"); } } } else { // unchecked $data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[{$i}]\" value=\"0\" disabled=\"disabled\" />"; } if ($answer->score > 0 && $this->lesson->custom || $this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) && !$this->lesson->custom) { $data .= "<div class=highlight>" . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . "</div>"; } else { $data .= format_text($answer->answer, $answer->answerformat, $formattextdefoptions); } } else { if ($useranswer != null and $answer->id == $useranswer->answerid) { // make checked $data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[{$i}]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />"; if ($answer->response == null) { if ($useranswer->correct) { $answerdata->response = get_string("thatsthecorrectanswer", "lesson"); } else { $answerdata->response = get_string("thatsthewronganswer", "lesson"); } } else { $answerdata->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions); } if ($this->lesson->custom) { $answerdata->score = get_string("pointsearned", "lesson") . ": " . $answer->score; } elseif ($useranswer->correct) { $answerdata->score = get_string("receivedcredit", "lesson"); } else { $answerdata->score = get_string("didnotreceivecredit", "lesson"); } } else { // unchecked $data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[{$i}]\" value=\"0\" disabled=\"disabled\" />"; } if ($answer->score > 0 && $this->lesson->custom || $this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) && !$this->lesson->custom) { $data .= "<div class=\"highlight\">" . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . "</div>"; } else { $data .= format_text($answer->answer, $answer->answerformat, $formattextdefoptions); } } if (isset($pagestats[$this->properties->id][$answer->id])) { $percent = $pagestats[$this->properties->id][$answer->id] / $pagestats[$this->properties->id]["total"] * 100; $percent = round($percent, 2); $percent .= "% " . get_string("checkedthisone", "lesson"); } else { $percent = get_string("noonecheckedthis", "lesson"); } $answerdata->answers[] = array($data, $percent); $answerpage->answerdata = $answerdata; } return $answerpage; }