MDL-20636 Bug 11406 Opaque gives radio groups name _rg by default, which QE cannot handle.

As a work around, we specifically look for this variable, and if it is present, include it in the sumbitted data.
This commit is contained in:
Tim Hunt 2011-01-24 14:54:21 +00:00
parent 1c2ed7c501
commit d4d64ee3f1
2 changed files with 815 additions and 800 deletions

View file

@ -105,12 +105,9 @@ class qbehaviour_opaque extends question_behaviour {
} else if ($step->has_behaviour_var('comment')) { } else if ($step->has_behaviour_var('comment')) {
return $this->summarise_manual_comment($step); return $this->summarise_manual_comment($step);
} else { } else {
$data = $step->get_qt_data(); $data = qtype_opaque_get_submitted_data($step);
$formatteddata = array(); $formatteddata = array();
foreach ($data as $name => $value) { foreach ($data as $name => $value) {
if (substr($name, 0, 1) == '_') {
continue;
}
$formatteddata[] = $name . ' => ' . s($value); $formatteddata[] = $name . ' => ' . s($value);
} }
if ($formatteddata) { if ($formatteddata) {

View file

@ -377,6 +377,23 @@ function qtype_opaque_get_step($seq, question_attempt $qa, $pendingstep) {
throw new Exception('Sequence number ' . $seq . ' out of range.'); throw new Exception('Sequence number ' . $seq . ' out of range.');
} }
/**
* Wrapper round $step->get_submitted_data() to work around an incompatibility
* between OpenMark and the Moodle question engine.
* @param question_attempt_step $step a step.
* @return array approximately $step->get_submitted_data().
*/
function qtype_opaque_get_submitted_data(question_attempt_step $step) {
// By default, OpenMark radio buttons get the name '_rg', whcih breaks
// one of the assumptions of the qutesion engine, so we have to manually
// include it when doing get_submitted_data.
$response = $step->get_submitted_data();
if ($step->has_qt_var('_rg')) {
$response['_rg'] = $step->get_qt_var('_rg');
}
return $response;
}
/** /**
* Update the $SESSION->cached_opaque_state to show the current status of $question for state * Update the $SESSION->cached_opaque_state to show the current status of $question for state
* $state. * $state.
@ -460,7 +477,8 @@ function qtype_opaque_update_state(question_attempt $qa, question_attempt_step $
while ($opaquestate->sequencenumber < $targetseq) { while ($opaquestate->sequencenumber < $targetseq) {
$step = qtype_opaque_get_step($opaquestate->sequencenumber + 1, $qa, $pendingstep); $step = qtype_opaque_get_step($opaquestate->sequencenumber + 1, $qa, $pendingstep);
$processreturn = qtype_opaque_process($opaquestate->engine, $opaquestate->questionsessionid, $step->get_submitted_data()); $processreturn = qtype_opaque_process($opaquestate->engine, $opaquestate->questionsessionid,
qtype_opaque_get_submitted_data($step));
if (is_string($processreturn)) { if (is_string($processreturn)) {
unset($SESSION->cached_opaque_state); unset($SESSION->cached_opaque_state);
return $processreturn; return $processreturn;