Permalink
Browse files

Merge branch 'MDL-26236' of git://github.com/timhunt/moodle

  • Loading branch information...
2 parents bcbb590 + c991ecb commit b180a11998073ed08ea2b39061affe2fc0194a3f @stronk7 stronk7 committed Feb 15, 2011
@@ -47,9 +47,9 @@ public function recode_state_answer($state) {
$answer = $state->answer;
$result = '';
// randomxx-yy answer format
- if (preg_match('~^random([0-9]+)-(.*)$~', $answer, $matches)) {
+ if (preg_match('~^random([0-9]+)-~', $answer, $matches)) {
$questionid = $matches[1];
- $subanswer = $matches[2];
+ $subanswer = substr($answer, strlen('random' . $questionid . '-'));
$newquestionid = $this->get_mappingid('question', $questionid);
$questionqtype = $DB->get_field('question', 'qtype', array('id' => $newquestionid));
// Delegate subanswer recode to proper qtype, faking one question_states record
@@ -232,7 +232,7 @@ function restore_session_and_responses(&$question, &$state) {
/// the other question types in that it now only needs one response
/// record per question.
global $QTYPES, $DB, $OUTPUT;
- if (!preg_match('~^random([0-9]+)-(.*)$~', $state->responses[''], $answerregs)) {
+ if (!preg_match('~^random([0-9]+)-~', $state->responses[''], $matches)) {
if (empty($state->responses[''])) {
// This is the case if there weren't enough questions available in the category.
$question->questiontext = '<span class="notifyproblem">'.
@@ -250,15 +250,16 @@ function restore_session_and_responses(&$question, &$state) {
echo $OUTPUT->notification("Wrapped state missing");
}
} else {
- if (!$wrappedquestion = $DB->get_record('question', array('id' => $answerregs[1]))) {
+ $questionid = $matches[1];
+ if (!$wrappedquestion = $DB->get_record('question', array('id' => $questionid))) {
// The teacher must have deleted this question by mistake
// Convert it into a description type question with an explanation to the student
$wrappedquestion = clone($question);
- $wrappedquestion->id = $answerregs[1];
+ $wrappedquestion->id = $questionid;
$wrappedquestion->questiontext = get_string('questiondeleted', 'quiz');
$wrappedquestion->qtype = 'missingtype';
}
- $state->responses[''] = (false === $answerregs[2]) ? '' : $answerregs[2];
+ $state->responses[''] = substr($state->responses[''], strlen('random' . $questionid . '-'));
}
if (!$QTYPES[$wrappedquestion->qtype]

0 comments on commit b180a11

Please sign in to comment.