From e5ebbd53d41615ee38661b8df09223b02aaf7f92 Mon Sep 17 00:00:00 2001 From: pichetp Date: Mon, 18 Aug 2008 18:31:31 +0000 Subject: [PATCH] Improving multichoice display MDL-14763 --- .../multianswer/edit_multianswer_form.php | 21 ++- question/type/multianswer/questiontype.php | 154 +++++++++++++++--- question/type/multichoice/questiontype.php | 3 + 3 files changed, 156 insertions(+), 22 deletions(-) diff --git a/question/type/multianswer/edit_multianswer_form.php b/question/type/multianswer/edit_multianswer_form.php index 6239f1f8e6..77fadcef8a 100644 --- a/question/type/multianswer/edit_multianswer_form.php +++ b/question/type/multianswer/edit_multianswer_form.php @@ -66,8 +66,8 @@ class question_edit_multianswer_form extends question_edit_form { $mform->addElement('static', 'sub_'.$sub."_".'defaultgrade', get_string('defaultgrade', 'quiz')); $mform->setDefault('sub_'.$sub."_".'defaultgrade',$this->questiondisplay->options->questions[$sub]->defaultgrade); - if ($this->questiondisplay->options->questions[$sub]->qtype =='multichoice' ) { - $mform->addElement('checkbox', 'sub_'.$sub."_".'layout', get_string('layout', 'quiz')) ;//, $gradeoptions); + if ($this->questiondisplay->options->questions[$sub]->qtype =='multichoice' ) { + $mform->addElement('static', 'sub_'.$sub."_".'layout', get_string('layout', 'quiz'),array('cols'=>60, 'rows'=>1)) ;//, $gradeoptions); } foreach ($this->questiondisplay->options->questions[$sub]->answer as $key =>$ans) { @@ -151,7 +151,22 @@ class question_edit_multianswer_form extends question_edit_form { $answercount = 0; $maxgrade = false; $maxfraction = -1; - + if ($subquestion->qtype == 'multichoice' ) { + $default_values[$prefix.'layout'] = $subquestion->layout ; + switch ($subquestion->layout) { + case '0': + $default_values[$prefix.'layout']= get_string('selectelement', 'qtype_multianswer'); + break; + case '1': + $default_values[$prefix.'layout']= get_string('verticallayout', 'qtype_multianswer'); + break; + case '2': + $default_values[$prefix.'layout']= get_string('horizontallayout', 'qtype_multianswer'); + break; + default: + $default_values[$prefix.'layout']= get_string('unknownlayout', 'qtype_multianswer'); + } + } foreach ($subquestion->answer as $key=>$answer) { if ( $subquestion->qtype == 'numerical' && $key == 0 ) { $default_values[$prefix.'tolerance['.$key.']'] = $subquestion->tolerance[0] ; diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php index b063519637..75c15ac746 100644 --- a/question/type/multianswer/questiontype.php +++ b/question/type/multianswer/questiontype.php @@ -420,30 +420,127 @@ class embedded_cloze_qtype extends default_questiontype { echo $feedbackimg; break; case 'multichoice': - $outputoptions = ''; // Default empty option - foreach ($answers as $mcanswer) { + // echo "

layout

".$wrapped->options->layout;print_r($wrapped->options);echo "

"; + if ($wrapped->options->layout == 0 ){ + $outputoptions = ''; // Default empty option + foreach ($answers as $mcanswer) { $selected = ''; if ($response == $mcanswer->id) { $selected = ' selected="selected"'; } $outputoptions .= "'; + } + // In the next line, $readonly is invalid HTML, but it works in + // all browsers. $disabled would be valid, but then the JS for + // displaying the feedback does not work. Of course, we should + // not be relying on JS (for accessibility reasons), but that is + // a bigger problem. + // + // The span is used for safari, which does not allow styling of + // selects. + echo "'; + if (!empty($feedback) && !empty($USER->screenreader)) { + echo "pixpath/i/feedback.gif\" alt=\"$feedback\" />"; + } + echo $feedbackimg; + }else if ($wrapped->options->layout == 1 || $wrapped->options->layout == 2){ + // echo "vertical"; + // echo "

answers

";print_r($answers);echo "

"; + $ordernumber=0; + $anss = Array(); + foreach ($answers as $mcanswer) { + $ordernumber++; + $checked = ''; + $chosen = false; + $type = 'type="radio"'; + $name = "name=\"{$inputname}\""; + if ($response == $mcanswer->id) { + $checked = 'checked="checked"'; + $chosen = true; + } + $a = new stdClass; + $a->id = $question->name_prefix . $mcanswer->id; + // echo "aid ".$a->id ; + $a->class = ''; + $a->feedbackimg = ''; + + // Print the control + $a->control = "id\" $name $checked $type value=\"$mcanswer->id\" />"; + if ($options->correct_responses && $mcanswer->fraction > 0) { + $a->class = question_get_feedback_class(1); + } + if (($options->feedback && $chosen) || $options->correct_responses) { + if ($type == ' type="checkbox" ') { + $a->feedbackimg = question_get_feedback_image($mcanswer->fraction > 0 ? 1 : 0, $chosen && $options->feedback); + } else { + $a->feedbackimg = question_get_feedback_image($mcanswer->fraction, $chosen && $options->feedback); } - // In the next line, $readonly is invalid HTML, but it works in - // all browsers. $disabled would be valid, but then the JS for - // displaying the feedback does not work. Of course, we should - // not be relying on JS (for accessibility reasons), but that is - // a bigger problem. - // - // The span is used for safari, which does not allow styling of - // selects. - echo "'; - if (!empty($feedback) && !empty($USER->screenreader)) { - echo "pixpath/i/feedback.gif\" alt=\"$feedback\" />"; + } + + // Print the answer text + $a->text = '' . $ordernumber . '. ' . + format_text($mcanswer->answer, FORMAT_MOODLE, $formatoptions, $cmoptions->course); + + // Print feedback if feedback is on + if (($options->feedback || $options->correct_responses) && ($checked )) { //|| $options->readonly + $a->feedback = format_text($mcanswer->feedback, true, $formatoptions, $cmoptions->course); + } else { + $a->feedback = ''; + } + + $anss[] = clone($a); + } + ?> + options->layout == 1 ){ + ?> + + + + + + + + +
+ control; ?> + + +
+ options->layout == 2 ){ + ?> + + + + + + + + + +
+ control; ?> + + +
+ correctfeedback = ''; $wrapped->partiallycorrectfeedback = ''; $wrapped->incorrectfeedback = ''; + $wrapped->layout = 0; + } else if(!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE_REGULAR])) { + $wrapped->qtype = 'multichoice'; + $wrapped->single = 1; + $wrapped->answernumbering = 0; + $wrapped->correctfeedback = ''; + $wrapped->partiallycorrectfeedback = ''; + $wrapped->incorrectfeedback = ''; + $wrapped->layout = 1; + } else if(!empty($answerregs[ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE_HORIZONTAL])) { + $wrapped->qtype = 'multichoice'; + $wrapped->single = 1; + $wrapped->answernumbering = 0; + $wrapped->correctfeedback = ''; + $wrapped->partiallycorrectfeedback = ''; + $wrapped->incorrectfeedback = ''; + $wrapped->layout = 2; } else { print_error('unknownquestiontype', 'question', '', $answerregs[2]); return false; diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index 4d8f517198..701ba4b481 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -105,6 +105,9 @@ class question_multichoice_qtype extends default_questiontype { } $options->answers = implode(",",$answers); $options->single = $question->single; + if(isset($question->layout)){ + $options->layout = $question->layout; + } $options->answernumbering = $question->answernumbering; $options->shuffleanswers = $question->shuffleanswers; $options->correctfeedback = trim($question->correctfeedback); -- 2.39.5