Skip to content
Browse files

Merge branch 'MDL-35370_22' of git://github.com/timhunt/moodle into M…

…OODLE_22_STABLE
  • Loading branch information...
2 parents a028dd0 + f3872e7 commit 73e4647509b86725ab3a1b121bddb5764f9e45fc @danpoltawski danpoltawski committed Oct 2, 2012
View
30 question/type/multianswer/renderer.php
@@ -177,13 +177,18 @@ public function subquestion(question_attempt $qa, question_display_options $opti
if ($subq->qtype->name() == 'shortanswer') {
$matchinganswer = $subq->get_matching_answer(array('answer' => $response));
} else if ($subq->qtype->name() == 'numerical') {
- $matchinganswer = $subq->get_matching_answer($response, 1);
+ list($value, $unit, $multiplier) = $subq->ap->apply_units($response, '');
+ $matchinganswer = $subq->get_matching_answer($value, 1);
} else {
$matchinganswer = $subq->get_matching_answer($response);
}
if (!$matchinganswer) {
- $matchinganswer = new question_answer(0, '', null, '', FORMAT_HTML);
+ if (is_null($response) || $response === '') {
+ $matchinganswer = new question_answer(0, '', null, '', FORMAT_HTML);
+ } else {
+ $matchinganswer = new question_answer(0, '', 0.0, '', FORMAT_HTML);
+ }
}
// Work out a good input field size.
@@ -280,6 +285,9 @@ public function subquestion(question_attempt $qa, question_display_options $opti
$order = $subq->get_order($qa);
$rightanswer = $subq->answers[$order[reset($subq->get_correct_response())]];
+ if (!$matchinganswer) {
+ $matchinganswer = new question_answer(0, '', null, '', FORMAT_HTML);
+ }
$feedbackpopup = $this->feedback_popup($subq, $matchinganswer->fraction,
$subq->format_text($matchinganswer->feedback, $matchinganswer->feedbackformat,
$qa, 'question', 'answerfeedback', $matchinganswer->id),
@@ -365,16 +373,30 @@ public function subquestion(question_attempt $qa, question_display_options $opti
$result .= $this->all_choices_wrapper_end();
+ $feedback = array();
if ($options->feedback && $options->marks >= question_display_options::MARK_AND_MAX &&
$subq->maxmark > 0) {
$a = new stdClass();
$a->mark = format_float($fraction * $subq->maxmark, $options->markdp);
$a->max = format_float($subq->maxmark, $options->markdp);
- $result .= html_writer::tag('div', get_string('markoutofmax', 'question', $a),
- array('class' => 'outcome'));
+ $feedback[] = html_writer::tag('div', get_string('markoutofmax', 'question', $a));
+ }
+
+ if ($options->rightanswer) {
+ foreach ($subq->answers as $ans) {
+ if (question_state::graded_state_for_fraction($ans->fraction) ==
+ question_state::$gradedright) {
+ $feedback[] = get_string('correctansweris', 'qtype_multichoice',
+ $subq->format_text($ans->answer, $ans->answerformat,
+ $qa, 'question', 'answer', $ansid));
+ break;
+ }
+ }
}
+ $result .= html_writer::nonempty_tag('div', implode('<br />', $feedback), array('class' => 'outcome'));
+
return $result;
}
View
12 question/type/numerical/question.php
@@ -182,6 +182,10 @@ public function get_correct_response() {
* @return question_answer the matching answer.
*/
public function get_matching_answer($value, $multiplier) {
+ if (is_null($value) || $value === '') {
+ return null;
+ }
+
if (!is_null($multiplier)) {
$scaledvalue = $value * $multiplier;
} else {
@@ -196,6 +200,7 @@ public function get_matching_answer($value, $multiplier) {
return $answer;
}
}
+
return null;
}
@@ -276,18 +281,17 @@ public function classify_response(array $response) {
public function check_file_access($qa, $options, $component, $filearea, $args,
$forcedownload) {
if ($component == 'question' && $filearea == 'answerfeedback') {
- $question = $qa->get_question();
$currentanswer = $qa->get_last_qt_var('answer');
if ($this->has_separate_unit_field()) {
$selectedunit = $qa->get_last_qt_var('unit');
} else {
$selectedunit = null;
}
- list($value, $unit, $multiplier) = $question->ap->apply_units(
+ list($value, $unit, $multiplier) = $this->ap->apply_units(
$currentanswer, $selectedunit);
- $answer = $question->get_matching_answer($value, $multiplier);
+ $answer = $this->get_matching_answer($value, $multiplier);
$answerid = reset($args); // itemid is answer id.
- return $options->feedback && $answerid == $answer->id;
+ return $options->feedback && $answer && $answerid == $answer->id;
} else if ($component == 'question' && $filearea == 'hint') {
return $this->check_hint_file_access($qa, $options, $args);
View
6 question/type/shortanswer/question.php
@@ -78,6 +78,10 @@ public function get_answers() {
}
public function compare_response_with_answer(array $response, question_answer $answer) {
+ if (!array_key_exists('answer', $response) || is_null($response['answer'])) {
+ return false;
+ }
+
return self::compare_string_with_wildcard(
$response['answer'], $answer->answer, !$this->usecase);
}
@@ -129,7 +133,7 @@ public function check_file_access($qa, $options, $component, $filearea,
$currentanswer = $qa->get_last_qt_var('answer');
$answer = $qa->get_question()->get_matching_answer(array('answer' => $currentanswer));
$answerid = reset($args); // itemid is answer id.
- return $options->feedback && $answerid == $answer->id;
+ return $options->feedback && $answer && $answerid == $answer->id;
} else if ($component == 'question' && $filearea == 'hint') {
return $this->check_hint_file_access($qa, $options, $args);
View
2 question/type/shortanswer/questiontype.php
@@ -117,7 +117,7 @@ public function save_question_options($question) {
$this->save_hints($question);
- // Perform sanity checks on fractional grades
+ // Perform sanity checks on fractional grades.
if ($maxfraction != 1) {
$result->noticeyesno = get_string('fractionsnomax', 'question', $maxfraction * 100);
return $result;

0 comments on commit 73e4647

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