replacing fieldsets with divs in small forms
[moodle.git] / question / type / multianswer / edit_multianswer_form.php
CommitLineData
271ffe3f 1<?php
2/**
3 * Defines the editing form for the multianswer question type.
4 *
5 * @copyright &copy; 2007 Jamie Pratt
6 * @author Jamie Pratt me@jamiep.org
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package questions
9 */
10
11/**
12 * multianswer editing form definition.
13 */
14class question_edit_multianswer_form extends question_edit_form {
15
16 // No question-type specific form fields.
17
32db0d42 18 function set_data($question) {
c6fc9988 19 if ($question->questiontext and $question->id and $question->qtype) {
20
21 foreach ($question->options->questions as $key => $wrapped) {
22 // The old way of restoring the definitions is kept to gradually
23 // update all multianswer questions
24 if (empty($wrapped->questiontext)) {
25 $parsableanswerdef = '{' . $wrapped->defaultgrade . ':';
26 switch ($wrapped->qtype) {
27 case 'multichoice':
28 $parsableanswerdef .= 'MULTICHOICE:';
29 break;
30 case 'shortanswer':
31 $parsableanswerdef .= 'SHORTANSWER:';
32 break;
33 case 'numerical':
34 $parsableanswerdef .= 'NUMERICAL:';
35 break;
36 default:
37 error("questiontype $wrapped->qtype not recognized");
38 }
39 $separator= '';
40 foreach ($wrapped->options->answers as $subanswer) {
41 $parsableanswerdef .= $separator
42 . '%' . round(100*$subanswer->fraction) . '%';
43 $parsableanswerdef .= $subanswer->answer;
44 if (!empty($wrapped->options->tolerance)) {
45 // Special for numerical answers:
46 $parsableanswerdef .= ":{$wrapped->options->tolerance}";
47 // We only want tolerance for the first alternative, it will
48 // be applied to all of the alternatives.
49 unset($wrapped->options->tolerance);
50 }
51 if ($subanswer->feedback) {
52 $parsableanswerdef .= "#$subanswer->feedback";
53 }
54 $separator = '~';
55 }
56 $parsableanswerdef .= '}';
57 // Fix the questiontext fields of old questions
58 set_field('question', 'questiontext', addslashes($parsableanswerdef), 'id', $wrapped->id);
59 } else {
60 $parsableanswerdef = str_replace('&#', '&\#', $wrapped->questiontext);
61 }
62 $question->questiontext = str_replace("{#$key}", $parsableanswerdef, $question->questiontext);
63 }
64 }
65 }
271ffe3f 66
67 function qtype() {
68 return 'multianswer';
69 }
70}
71?>