$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) {
$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] ;
echo $feedbackimg;
break;
case 'multichoice':
- $outputoptions = '<option></option>'; // Default empty option
- foreach ($answers as $mcanswer) {
+ // echo "<p>layout <pre>".$wrapped->options->layout;print_r($wrapped->options);echo "</pre><p>";
+ if ($wrapped->options->layout == 0 ){
+ $outputoptions = '<option></option>'; // Default empty option
+ foreach ($answers as $mcanswer) {
$selected = '';
if ($response == $mcanswer->id) {
$selected = ' selected="selected"';
}
$outputoptions .= "<option value=\"$mcanswer->id\"$selected>" .
s($mcanswer->answer) . '</option>';
+ }
+ // 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 "<span $style><select $popup $readonly $style name=\"$inputname\">";
+ echo $outputoptions;
+ echo '</select></span>';
+ if (!empty($feedback) && !empty($USER->screenreader)) {
+ echo "<img src=\"$CFG->pixpath/i/feedback.gif\" alt=\"$feedback\" />";
+ }
+ echo $feedbackimg;
+ }else if ($wrapped->options->layout == 1 || $wrapped->options->layout == 2){
+ // echo "vertical";
+ // echo "<p>answers <pre>";print_r($answers);echo "</pre><p>";
+ $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 = "<input $readonly id=\"$a->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 "<span $style><select $popup $readonly $style name=\"$inputname\">";
- echo $outputoptions;
- echo '</select></span>';
- if (!empty($feedback) && !empty($USER->screenreader)) {
- echo "<img src=\"$CFG->pixpath/i/feedback.gif\" alt=\"$feedback\" />";
+ }
+
+ // Print the answer text
+ $a->text = '<span class="anun">' . $ordernumber . '<span class="anumsep">.</span></span> ' .
+ 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);
+ }
+ ?>
+ <?php if ($wrapped->options->layout == 1 ){
+ ?>
+ <table class="answer">
+ <?php $row = 1; foreach ($anss as $answer) { ?>
+ <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
+ <td class="c0 control">
+ <?php echo $answer->control; ?>
+ </td>
+ <td class="c1 text <?php echo $answer->class ?>">
+ <label for="<?php echo $answer->id ?>">
+ <?php echo $answer->text; ?>
+ <?php echo $answer->feedbackimg; ?>
+ </label>
+ </td>
+ <td class="c0 feedback">
+ <?php echo $answer->feedback; ?>
+ </td>
+ </tr>
+ <?php } ?>
+ </table>
+ <?php }else if ($wrapped->options->layout == 2 ){
+ ?>
+
+ <table class="answer">
+ <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
+ <?php $row = 1; foreach ($anss as $answer) { ?>
+ <td class="c0 control">
+ <?php echo $answer->control; ?>
+ </td>
+ <td class="c1 text <?php echo $answer->class ?>">
+ <label for="<?php echo $answer->id ?>">
+ <?php echo $answer->text; ?>
+ <?php echo $answer->feedbackimg; ?>
+ </label>
+ </td>
+ <td class="c0 feedback">
+ <?php echo $answer->feedback; ?>
+ </td>
+ <?php } ?>
+ </tr>
+ </table>
+ <?php }
+
+ }else {
+ echo "no valid layout";
}
- echo $feedbackimg;
+
break;
default:
$a = new stdClass;
// Remaining ANSWER regexes
define("ANSWER_TYPE_DEF_REGEX",
- '(NUMERICAL|NM)|(MULTICHOICE|MC)|(SHORTANSWER|SA|MW)');
+ '(NUMERICAL|NM)|(MULTICHOICE|MC)|(MULTICHOICE_V|MCV)|(MULTICHOICE_H|MCH)|(SHORTANSWER|SA|MW)');
define("ANSWER_START_REGEX",
'\{([0-9]*):(' . ANSWER_TYPE_DEF_REGEX . '):');
define("ANSWER_REGEX_NORM", 1);
define("ANSWER_REGEX_ANSWER_TYPE_NUMERICAL", 3);
define("ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE", 4);
-define("ANSWER_REGEX_ANSWER_TYPE_SHORTANSWER", 5);
-define("ANSWER_REGEX_ALTERNATIVES", 6);
+define("ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE_REGULAR", 5);
+define("ANSWER_REGEX_ANSWER_TYPE_MULTICHOICE_HORIZONTAL", 6);
+define("ANSWER_REGEX_ANSWER_TYPE_SHORTANSWER", 7);
+define("ANSWER_REGEX_ALTERNATIVES", 8);
function qtype_multianswer_extract_question($text) {
$question = new stdClass;
$wrapped->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;