MDL-79863 qtype_ordering: qtype/ordering cater for missing data about responses when reviewing an attempt at an Ordering question

This commit is contained in:
Gordon Bateson 2015-01-30 14:47:58 +09:00 committed by Mathew May
parent 4864ed8779
commit f44ebd44d4
2 changed files with 55 additions and 44 deletions

View file

@ -83,36 +83,48 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
$result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext')); $result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
$printeditems = false;
if (count($currentresponse)) { if (count($currentresponse)) {
$result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::start_tag('div', array('class' => 'answer'));
$result .= html_writer::start_tag('ul', array('class' => 'sortablelist', 'id' => $sortable_id));
// generate ordering items // generate ordering items
foreach ($currentresponse as $position => $answerid) { foreach ($currentresponse as $position => $answerid) {
if (array_key_exists($answerid, $question->answers)) { if (! array_key_exists($answerid, $question->answers)) {
if ($options->correctness) { continue; // shouldn't happen !!
if ($correctresponse[$position]==$answerid) { }
$class = 'correctposition'; if (! array_key_exists($position, $correctresponse)) {
$img = $this->feedback_image(1); continue; // shouldn't happen !!
} else {
$class = 'wrongposition';
$img = $this->feedback_image(0);
}
$img = "$img ";
} else {
$class = 'sortableitem';
$img = '';
}
// the original "id" revealed the correct order of the answers
// because $answer->fraction holds the correct order number
// $id = 'ordering_item_'.$answerid.'_'.intval($question->answers[$answerid]->fraction);
$answer = $question->answers[$answerid];
$params = array('class' => $class, 'id' => $answer->md5key);
$result .= html_writer::tag('li', $img.$answer->answer, $params);
} }
}
if ($printeditems==false) {
$printeditems = true;
$result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::start_tag('div', array('class' => 'answer'));
$result .= html_writer::start_tag('ul', array('class' => 'sortablelist', 'id' => $sortable_id));
}
if ($options->correctness) {
if ($correctresponse[$position]==$answerid) {
$class = 'correctposition';
$img = $this->feedback_image(1);
} else {
$class = 'wrongposition';
$img = $this->feedback_image(0);
}
$img = "$img ";
} else {
$class = 'sortableitem';
$img = '';
}
// the original "id" revealed the correct order of the answers
// because $answer->fraction holds the correct order number
// $id = 'ordering_item_'.$answerid.'_'.intval($question->answers[$answerid]->fraction);
$answer = $question->answers[$answerid];
$params = array('class' => $class, 'id' => $answer->md5key);
$result .= html_writer::tag('li', $img.$answer->answer, $params);
}
}
if ($printeditems) {
$result .= html_writer::end_tag('ul'); $result .= html_writer::end_tag('ul');
$result .= html_writer::end_tag('div'); // answer $result .= html_writer::end_tag('div'); // answer
$result .= html_writer::end_tag('div'); // ablock $result .= html_writer::end_tag('div'); // ablock
@ -137,28 +149,27 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
$output = ''; $output = '';
$showcorrect = false; $showcorrect = false;
if ($step = $qa->get_last_step()) { $question = $qa->get_question();
switch ($step->get_state()) { if (empty($question->correctresponse)) {
case 'gradedright' : $showcorrect = false; break; $output .= html_writer::tag('p', get_string('noresponsedetails', 'qtype_ordering'));
case 'gradedpartial': $showcorrect = true; break; } else {
case 'gradedwrong' : $showcorrect = true; break; if ($step = $qa->get_last_step()) {
switch ($step->get_state()) {
case 'gradedright' : $showcorrect = false; break;
case 'gradedpartial': $showcorrect = true; break;
case 'gradedwrong' : $showcorrect = true; break;
}
} }
} }
if ($showcorrect) { if ($showcorrect) {
$question = $qa->get_question(); $output .= html_writer::tag('p', get_string('correctorder', 'qtype_ordering'));
if (empty($question->correctresponse)) { $output .= html_writer::start_tag('ol');
$output .= html_writer::tag('p', get_string('noresponsedetails', 'qtype_ordering')); $correctresponse = $question->correctresponse;
} else { foreach ($correctresponse as $position => $answerid) {
$output .= html_writer::tag('p', get_string('correctorder', 'qtype_ordering')); $answer = $question->answers[$answerid];
$output .= html_writer::start_tag('ol'); $output .= html_writer::tag('li', $answer->answer);
$correctresponse = $question->correctresponse;
foreach ($correctresponse as $position => $answerid) {
$answer = $question->answers[$answerid];
$output .= html_writer::tag('li', $answer->answer);
}
$output .= html_writer::end_tag('ol');
} }
$output .= html_writer::end_tag('ol');
} }
return $output; return $output;

View file

@ -30,6 +30,6 @@ defined('MOODLE_INTERNAL') || die();
$plugin->cron = 0; $plugin->cron = 0;
$plugin->component = 'qtype_ordering'; $plugin->component = 'qtype_ordering';
$plugin->maturity = MATURITY_STABLE; // ALPHA=50, BETA=100, RC=150, STABLE=200 $plugin->maturity = MATURITY_STABLE; // ALPHA=50, BETA=100, RC=150, STABLE=200
$plugin->release = '2015-01-24 (17)'; $plugin->release = '2015-01-30 (18)';
$plugin->version = 2015012417; $plugin->version = 2015013018;
$plugin->requires = 2010112400; // Moodle 2.0 $plugin->requires = 2010112400; // Moodle 2.0