Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-39546 Lesson module: fixed matching question issues.

  • Loading branch information...
commit a77f19bc47107dca1b7dd52f3ac97a0fac5b6858 1 parent 2bc8f21
@rwijaya rwijaya authored samhemelryk committed
Showing with 17 additions and 16 deletions.
  1. +17 −16 mod/lesson/pagetypes/matching.php
View
33 mod/lesson/pagetypes/matching.php
@@ -72,17 +72,15 @@ protected function make_answer_form($attempt=null) {
foreach ($answers as $answer) {
// get all the response
if ($answer->response != null) {
- $responses[$answer->id] = trim($answer->response);
+ $responses[] = trim($answer->response);
}
}
$responseoptions = array(''=>get_string('choosedots'));
if (!empty($responses)) {
- $shuffleresponses = $responses;
- shuffle($shuffleresponses);
- foreach ($shuffleresponses as $response) {
- $key = array_search($response, $responses);
- $responseoptions[$key] = $response;
+ shuffle($responses);
+ foreach ($responses as $response) {
+ $responseoptions[htmlspecialchars($response)] = $response;
}
}
if (isset($USER->modattempts[$this->lesson->id]) && !empty($attempt->useranswer)) {
@@ -167,12 +165,12 @@ public function check_answer() {
$wrong = array_shift($getanswers);
$answers = array();
- foreach ($getanswers as $key=>$answer) {
+ foreach ($getanswers as $key => $answer) {
if ($answer->answer !== '' or $answer->response !== '') {
$answers[$answer->id] = $answer;
}
- unset($getanswers[$key]);
}
+
// get the user's exact responses for record keeping
$hits = 0;
$userresponse = array();
@@ -181,12 +179,13 @@ public function check_answer() {
$result->noanswer = true;
return $result;
}
- $userresponse[] = $value;
+ $value = htmlspecialchars_decode($value);
+ $userresponse[] = htmlspecialchars_decode($value);
// Make sure the user's answer exists in question's answer
if (array_key_exists($id, $answers)) {
$answer = $answers[$id];
- $result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$answers[$value]->response;
- if ($id == $value) {
+ $result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$value;
+ if (trim($answer->response) == trim($value)) {
$hits++;
}
}
@@ -401,13 +400,13 @@ public function report_answers($answerpage, $answerdata, $useranswer, $pagestats
}
} elseif ($n > 1) {
$data = '<label class="accesshide" for="answer_' . $n . '">' . get_string('answer', 'lesson') . '</label>';
- $data .= "<select id=\"answer_". $n ."\" disabled=\"disabled\"><option selected=\"selected\">".strip_tags(format_string($answer->answer))."</option></select>";
+ $data .= strip_tags(format_string($answer->answer)) . ' ';
if ($useranswer != null) {
$userresponse = explode(",", $useranswer->useranswer);
$data .= '<label class="accesshide" for="stu_answer_response_' . $n . '">' . get_string('matchesanswer', 'lesson') . '</label>';
$data .= "<select id=\"stu_answer_response_" . $n . "\" disabled=\"disabled\"><option selected=\"selected\">";
if (array_key_exists($i, $userresponse)) {
- $data .= strip_tags(format_string($answers[$userresponse[$i]]->response));
+ $data .= $userresponse[$i];
}
$data .= "</option></select>";
} else {
@@ -519,19 +518,21 @@ public function definition() {
$mform->setType('pageid', PARAM_INT);
$i = 0;
+
foreach ($answers as $answer) {
$mform->addElement('html', '<div class="answeroption">');
if ($answer->response != null) {
$responseid = 'response['.$answer->id.']';
if ($hasattempt) {
$responseid = 'response_'.$answer->id;
- $mform->addElement('hidden', 'response['.$answer->id.']', htmlspecialchars(trim($answers[$useranswers[$i]]->response)));
- $mform->setType('response', PARAM_NOTAGS);
+ $mform->addElement('hidden', 'response['.$answer->id.']', htmlspecialchars($useranswers[$i]));
+ // Temporary fixed until MDL-38885 gets integrated
+ $mform->setType('response', PARAM_TEXT);
}
$mform->addElement('select', $responseid, format_text($answer->answer,$answer->answerformat,$options), $responseoptions, $disabled);
$mform->setType($responseid, PARAM_TEXT);
if ($hasattempt) {
- $mform->setDefault($responseid, htmlspecialchars(trim($answers[$useranswers[$i]]->response))); //TODO: this is suspicious
+ $mform->setDefault($responseid, htmlspecialchars(trim($useranswers[$i])));
} else {
$mform->setDefault($responseid, 'answeroption');
}

0 comments on commit a77f19b

Please sign in to comment.
Something went wrong with that request. Please try again.