Skip to content

Commit

Permalink
Merge branch 'MDL-28241_21' of git://github.com/timhunt/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_21_STABLE
  • Loading branch information
stronk7 committed Aug 22, 2011
2 parents 8db14e3 + 60854b6 commit 94aa0fb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
12 changes: 11 additions & 1 deletion question/type/multianswer/edit_multianswer_form.php
Expand Up @@ -284,7 +284,11 @@ public function set_data($question) {
foreach ($wrapped->options->answers as $subanswer) {
$parsableanswerdef .= $separator
. '%' . round(100*$subanswer->fraction) . '%';
$parsableanswerdef .= $subanswer->answer;
if (is_array($subanswer->answer)) {
$parsableanswerdef .= $subanswer->answer['text'];
} else {
$parsableanswerdef .= $subanswer->answer;
}
if (!empty($wrapped->options->tolerance)) {
// Special for numerical answers:
$parsableanswerdef .= ":{$wrapped->options->tolerance}";
Expand Down Expand Up @@ -361,6 +365,9 @@ public function set_data($question) {
$default_values[$prefix.'tolerance['.$key.']'] =
$subquestion->tolerance[0];
}
if (is_array($answer)) {
$answer = $answer['text'];
}
$trimmedanswer = trim($answer);
if ($trimmedanswer !== '') {
$answercount++;
Expand Down Expand Up @@ -438,6 +445,9 @@ public function validation($data, $files) {
$this->savedquestiondisplay->options->questions[$sub]->qtype);
}
foreach ($subquestion->answer as $key => $answer) {
if (is_array($answer)) {
$answer = $answer['text'];
}
$trimmedanswer = trim($answer);
if ($trimmedanswer !== '') {
$answercount++;
Expand Down
39 changes: 22 additions & 17 deletions question/type/multianswer/questiontype.php
Expand Up @@ -284,7 +284,7 @@ function qtype_multianswer_extract_question($text) {
$question->qtype = 'multianswer';
$question->questiontext = $text;
$question->generalfeedback['text'] = '';
$question->generalfeedback['format'] = '1';
$question->generalfeedback['format'] = FORMAT_HTML;
$question->generalfeedback['itemid'] = '';

$question->options->questions = array();
Expand All @@ -295,7 +295,7 @@ function qtype_multianswer_extract_question($text) {
++$positionkey) {
$wrapped = new stdClass();
$wrapped->generalfeedback['text'] = '';
$wrapped->generalfeedback['format'] = '1';
$wrapped->generalfeedback['format'] = FORMAT_HTML;
$wrapped->generalfeedback['itemid'] = '';
if (isset($answerregs[ANSWER_REGEX_NORM])&& $answerregs[ANSWER_REGEX_NORM]!== '') {
$wrapped->defaultmark = $answerregs[ANSWER_REGEX_NORM];
Expand All @@ -307,7 +307,7 @@ function qtype_multianswer_extract_question($text) {
$wrapped->multiplier = array();
$wrapped->units = array();
$wrapped->instructions['text'] = '';
$wrapped->instructions['format'] = '1';
$wrapped->instructions['format'] = FORMAT_HTML;
$wrapped->instructions['itemid'] = '';
} else if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_SHORTANSWER])) {
$wrapped->qtype = 'shortanswer';
Expand All @@ -321,13 +321,13 @@ function qtype_multianswer_extract_question($text) {
$wrapped->shuffleanswers = 1;
$wrapped->answernumbering = 0;
$wrapped->correctfeedback['text'] = '';
$wrapped->correctfeedback['format'] = '1';
$wrapped->correctfeedback['format'] = FORMAT_HTML;
$wrapped->correctfeedback['itemid'] = '';
$wrapped->partiallycorrectfeedback['text'] = '';
$wrapped->partiallycorrectfeedback['format'] = '1';
$wrapped->partiallycorrectfeedback['format'] = FORMAT_HTML;
$wrapped->partiallycorrectfeedback['itemid'] = '';
$wrapped->incorrectfeedback['text'] = '';
$wrapped->incorrectfeedback['format'] = '1';
$wrapped->incorrectfeedback['format'] = FORMAT_HTML;
$wrapped->incorrectfeedback['itemid'] = '';
$wrapped->layout = qtype_multichoice_base::LAYOUT_DROPDOWN;
} else if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE_REGULAR])) {
Expand All @@ -336,13 +336,13 @@ function qtype_multianswer_extract_question($text) {
$wrapped->shuffleanswers = 0;
$wrapped->answernumbering = 0;
$wrapped->correctfeedback['text'] = '';
$wrapped->correctfeedback['format'] = '1';
$wrapped->correctfeedback['format'] = FORMAT_HTML;
$wrapped->correctfeedback['itemid'] = '';
$wrapped->partiallycorrectfeedback['text'] = '';
$wrapped->partiallycorrectfeedback['format'] = '1';
$wrapped->partiallycorrectfeedback['format'] = FORMAT_HTML;
$wrapped->partiallycorrectfeedback['itemid'] = '';
$wrapped->incorrectfeedback['text'] = '';
$wrapped->incorrectfeedback['format'] = '1';
$wrapped->incorrectfeedback['format'] = FORMAT_HTML;
$wrapped->incorrectfeedback['itemid'] = '';
$wrapped->layout = qtype_multichoice_base::LAYOUT_VERTICAL;
} else if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE_HORIZONTAL])) {
Expand All @@ -351,13 +351,13 @@ function qtype_multianswer_extract_question($text) {
$wrapped->shuffleanswers = 0;
$wrapped->answernumbering = 0;
$wrapped->correctfeedback['text'] = '';
$wrapped->correctfeedback['format'] = '1';
$wrapped->correctfeedback['format'] = FORMAT_HTML;
$wrapped->correctfeedback['itemid'] = '';
$wrapped->partiallycorrectfeedback['text'] = '';
$wrapped->partiallycorrectfeedback['format'] = '1';
$wrapped->partiallycorrectfeedback['format'] = FORMAT_HTML;
$wrapped->partiallycorrectfeedback['itemid'] = '';
$wrapped->incorrectfeedback['text'] = '';
$wrapped->incorrectfeedback['format'] = '1';
$wrapped->incorrectfeedback['format'] = FORMAT_HTML;
$wrapped->incorrectfeedback['itemid'] = '';
$wrapped->layout = qtype_multichoice_base::LAYOUT_HORIZONTAL;
} else {
Expand All @@ -372,7 +372,7 @@ function qtype_multianswer_extract_question($text) {
$wrapped->fraction = array();
$wrapped->feedback = array();
$wrapped->questiontext['text'] = $answerregs[0];
$wrapped->questiontext['format'] = 0;
$wrapped->questiontext['format'] = FORMAT_HTML;
$wrapped->questiontext['itemid'] = '';
$answerindex = 0;

Expand All @@ -390,12 +390,12 @@ function qtype_multianswer_extract_question($text) {
$altregs[ANSWER_ALTERNATIVE_REGEX_FEEDBACK], ENT_QUOTES, 'UTF-8');
$feedback = str_replace('\}', '}', $feedback);
$wrapped->feedback["$answerindex"]['text'] = str_replace('\#', '#', $feedback);
$wrapped->feedback["$answerindex"]['format'] = '1';
$wrapped->feedback["$answerindex"]['format'] = FORMAT_HTML;
$wrapped->feedback["$answerindex"]['itemid'] = '';
} else {
$wrapped->feedback["$answerindex"]['text'] = '';
$wrapped->feedback["$answerindex"]['format'] = '1';
$wrapped->feedback["$answerindex"]['itemid'] = '1';
$wrapped->feedback["$answerindex"]['format'] = FORMAT_HTML;
$wrapped->feedback["$answerindex"]['itemid'] = '';

}
if (!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_NUMERICAL])
Expand All @@ -414,6 +414,12 @@ function qtype_multianswer_extract_question($text) {
$altregs[ANSWER_ALTERNATIVE_REGEX_ANSWER], ENT_QUOTES, 'UTF-8');
$answer = str_replace('\}', '}', $answer);
$wrapped->answer["$answerindex"] = str_replace('\#', '#', $answer);
if ($wrapped->qtype == 'multichoice') {
$wrapped->answer["$answerindex"] = array(
'text' => $wrapped->answer["$answerindex"],
'format' => FORMAT_HTML,
'itemid' => '');
}
}
$tmp = explode($altregs[0], $remainingalts, 2);
$remainingalts = $tmp[1];
Expand All @@ -425,6 +431,5 @@ function qtype_multianswer_extract_question($text) {
$question->questiontext['text'] = implode("{#$positionkey}",
explode($answerregs[0], $question->questiontext['text'], 2));
}
$question->questiontext = $question->questiontext;
return $question;
}

0 comments on commit 94aa0fb

Please sign in to comment.