Skip to content

Commit

Permalink
Merged bug fix for cloze upgrading and also some formatting from STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Aug 21, 2005
1 parent fb12ecd commit 70a6245
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
10 changes: 3 additions & 7 deletions mod/quiz/questiontypes/multianswer/editquestion.php
Expand Up @@ -40,17 +40,13 @@
} }
$parsableanswerdef .= '}'; $parsableanswerdef .= '}';
// Fix the questiontext fields of old questions // Fix the questiontext fields of old questions
set_field('quiz_questions', 'questiontext', $parsableanswerdef, set_field('quiz_questions', 'questiontext', addslashes($parsableanswerdef), 'id', $wrapped->id);
'id', $wrapped->id);
} else { } else {
$parsableanswerdef = str_replace('&#', '&\#', $parsableanswerdef = str_replace('&#', '&\#', $wrapped->questiontext);
$wrapped->questiontext);
} }
//echo "{#$key}<br />"; //echo "{#$key}<br />";
//echo $parsableanswerdef.'<br />'; //echo $parsableanswerdef.'<br />';
$question->questiontext = str_replace $question->questiontext = str_replace("{#$key}", $parsableanswerdef, $question->questiontext);
("{#$key}", $parsableanswerdef,
$question->questiontext);
} }
} }
print_heading_with_help(get_string('editingmultianswer', 'quiz'), print_heading_with_help(get_string('editingmultianswer', 'quiz'),
Expand Down
27 changes: 10 additions & 17 deletions mod/quiz/questiontypes/multianswer/questiontype.php
Expand Up @@ -20,25 +20,23 @@ function name() {
} }


function get_question_options(&$question) { function get_question_options(&$question) {
global $QUIZ_QTYPES;

// Get relevant data indexed by positionkey from the multianswers table // Get relevant data indexed by positionkey from the multianswers table
if (!$sequence = get_field('quiz_multianswers', 'sequence', 'question', if (!$sequence = get_field('quiz_multianswers', 'sequence', 'question', $question->id)) {
$question->id)) {
notify('Error: Missing question options!'); notify('Error: Missing question options!');
return false; return false;
} }


global $QUIZ_QTYPES;
$wrappedquestions = get_records_list('quiz_questions', 'id', $sequence); $wrappedquestions = get_records_list('quiz_questions', 'id', $sequence);


// We want an array with question ids as index and the positions as values // We want an array with question ids as index and the positions as values
$sequence = array_flip(explode(',', $sequence)); $sequence = array_flip(explode(',', $sequence));
array_walk($sequence, create_function('&$val', '$val++;')); array_walk($sequence, create_function('&$val', '$val++;'));


foreach ($wrappedquestions as $wrapped) { foreach ($wrappedquestions as $wrapped) {
if (!$QUIZ_QTYPES[$wrapped->qtype] if (!$QUIZ_QTYPES[$wrapped->qtype]->get_question_options($wrapped)) {
->get_question_options($wrapped)) { notify("Unable to get options for questiontype {$wrapped->qtype} (id={$wrapped->id})");
notify("Unable to get options for questiontype
{$wrapped->qtype} (id={$wrapped->id})");
} }
$wrapped->maxgrade = $wrapped->defaultgrade; $wrapped->maxgrade = $wrapped->defaultgrade;
$question->options->questions[$sequence[$wrapped->id]] = clone($wrapped); $question->options->questions[$sequence[$wrapped->id]] = clone($wrapped);
Expand All @@ -49,8 +47,7 @@ function get_question_options(&$question) {


function save_question_options($question) { function save_question_options($question) {
global $QUIZ_QTYPES; global $QUIZ_QTYPES;
if (!$oldwrappedids = if (!$oldwrappedids = get_records('quiz_questions', 'parent', $question->id, '', 'id, id')) {
get_records('quiz_questions', 'parent', $question->id, '', 'id, id')) {
// We need to select 'id, id' because the first one is consumed by // We need to select 'id, id' because the first one is consumed by
// get_records. // get_records.
$oldwrappedids = array(); $oldwrappedids = array();
Expand Down Expand Up @@ -96,8 +93,7 @@ function save_question_options($question) {
} }


function save_question($authorizedquestion, $form, $course) { function save_question($authorizedquestion, $form, $course) {
$question = $question = quiz_qtype_multianswer_extract_question ($form->questiontext);
quiz_qtype_multianswer_extract_question ($form->questiontext);
if (isset($authorizedquestion->id)) { if (isset($authorizedquestion->id)) {
$question->id = $authorizedquestion->id; $question->id = $authorizedquestion->id;
$question->version = $form->version = $authorizedquestion->version; $question->version = $form->version = $authorizedquestion->version;
Expand Down Expand Up @@ -167,8 +163,7 @@ function get_correct_responses(&$question, &$state) {
return $responses; return $responses;
} }


function print_question_formulation_and_controls(&$question, &$state, $cmoptions, function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
$options) {
global $QUIZ_QTYPES; global $QUIZ_QTYPES;
$readonly = empty($options->readonly) ? '' : 'readonly="readonly"'; $readonly = empty($options->readonly) ? '' : 'readonly="readonly"';
$nameprefix = $question->name_prefix; $nameprefix = $question->name_prefix;
Expand Down Expand Up @@ -458,8 +453,7 @@ function quiz_qtype_multianswer_extract_question($text) {
$wrapped->answer = array(); $wrapped->answer = array();
$wrapped->fraction = array(); $wrapped->fraction = array();
$wrapped->feedback = array(); $wrapped->feedback = array();
$wrapped->questiontext = addslashes(str_replace('&\#', '&#', $wrapped->questiontext = addslashes(str_replace('&\#', '&#', $answerregs[0]));
$answerregs[0]));
$wrapped->questiontextformat = 0; $wrapped->questiontextformat = 0;


$remainingalts = $answerregs[ANSWER_REGEX_ALTERNATIVES]; $remainingalts = $answerregs[ANSWER_REGEX_ALTERNATIVES];
Expand Down Expand Up @@ -501,8 +495,7 @@ function quiz_qtype_multianswer_extract_question($text) {
$question->questiontext = implode("{#$positionkey}", $question->questiontext = implode("{#$positionkey}",
explode($answerregs[0], $question->questiontext, 2)); explode($answerregs[0], $question->questiontext, 2));
} }
$question->questiontext = addslashes(str_replace('&\#', '&#', $question->questiontext = addslashes(str_replace('&\#', '&#', $question->questiontext));
$question->questiontext));
return $question; return $question;
} }


Expand Down

0 comments on commit 70a6245

Please sign in to comment.