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,14 +83,25 @@ 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)) {
continue; // shouldn't happen !!
}
if (! array_key_exists($position, $correctresponse)) {
continue; // shouldn't happen !!
}
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 ($options->correctness) {
if ($correctresponse[$position]==$answerid) { if ($correctresponse[$position]==$answerid) {
$class = 'correctposition'; $class = 'correctposition';
@ -113,6 +124,7 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
} }
} }
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,6 +149,10 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
$output = ''; $output = '';
$showcorrect = false; $showcorrect = false;
$question = $qa->get_question();
if (empty($question->correctresponse)) {
$output .= html_writer::tag('p', get_string('noresponsedetails', 'qtype_ordering'));
} else {
if ($step = $qa->get_last_step()) { if ($step = $qa->get_last_step()) {
switch ($step->get_state()) { switch ($step->get_state()) {
case 'gradedright' : $showcorrect = false; break; case 'gradedright' : $showcorrect = false; break;
@ -144,12 +160,8 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
case 'gradedwrong' : $showcorrect = true; break; case 'gradedwrong' : $showcorrect = true; break;
} }
} }
}
if ($showcorrect) { if ($showcorrect) {
$question = $qa->get_question();
if (empty($question->correctresponse)) {
$output .= html_writer::tag('p', get_string('noresponsedetails', 'qtype_ordering'));
} else {
$output .= html_writer::tag('p', get_string('correctorder', 'qtype_ordering')); $output .= html_writer::tag('p', get_string('correctorder', 'qtype_ordering'));
$output .= html_writer::start_tag('ol'); $output .= html_writer::start_tag('ol');
$correctresponse = $question->correctresponse; $correctresponse = $question->correctresponse;
@ -159,7 +171,6 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
} }
$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