Merge branch 'MDL-26236' of git://github.com/timhunt/moodle
This commit is contained in:
@@ -47,9 +47,9 @@ class restore_qtype_random_plugin extends restore_qtype_plugin {
|
||||
$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 @@ class random_qtype extends default_questiontype {
|
||||
/// 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 @@ class random_qtype extends default_questiontype {
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user