Minor problem with restoring numerical questions.
[moodle.git] / question / type / datasetdependent / datasetdefinitions_form.php
CommitLineData
8fc3e643 1<?php
2class question_dataset_dependent_definitions_form extends moodleform {
3 /**
4 * Question object with options and answers already loaded by get_question_options
5 * Be careful how you use this it is needed sometimes to set up the structure of the
6 * form in definition_inner but data is always loaded into the form with set_defaults.
7 *
8 * @var object
9 */
10 var $question;
11 /**
12 * Reference to question type object
13 *
14 * @var question_dataset_dependent_questiontype
15 */
16 var $qtypeobj;
17 /**
18 * Add question-type specific form fields.
19 *
20 * @param MoodleQuickForm $mform the form being built.
21 */
22 function question_dataset_dependent_definitions_form($submiturl, $question){
23 global $QTYPES;
24 $this->question = $question;
25 $this->qtypeobj =& $QTYPES[$this->question->qtype];
26 parent::moodleform($submiturl);
27 }
28 function definition() {
29 $mform =& $this->_form;
30
31 $possibledatasets = $this->qtypeobj->find_dataset_names($this->question->questiontext);
32 $mandatorydatasets = array();
33 foreach ($this->question->answers as $answer) {
34 $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
35 }
36 $key = 0;
37 $datasetmenus = array();
38 foreach ($mandatorydatasets as $datasetname) {
39 if (!isset($datasetmenus[$datasetname])) {
40 list($options, $selected) =
41 $this->qtypeobj->dataset_options($this->question, $datasetname);
42 unset($options['0']); // Mandatory...
43 $label = get_string("wildcard", "quiz"). " <strong>$datasetname</strong> ". get_string("substitutedby", "quiz");
44 $mform->addElement('select', "dataset[$key]", $label, $options);
45 $mform->setDefault("dataset[$key]", $selected);
46 $datasetmenus[$datasetname]='';
47 $key++;
48 }
49 }
50 foreach ($possibledatasets as $datasetname) {
51 if (!isset($datasetmenus[$datasetname])) {
52 list($options, $selected) =
53 $this->qtypeobj->dataset_options($this->question, $datasetname);
54 $label = get_string("wildcard", "quiz"). " <strong>$datasetname</strong> ". get_string("substitutedby", "quiz");
55 $mform->addElement('select', "dataset[$key]", $label, $options);
56 $mform->setDefault("dataset[$key]", $selected);
57 $datasetmenus[$datasetname]='';
58 $key++;
59 }
60 }
61 //hidden elements
62 $mform->addElement('hidden', 'wizardpage', 'datasetdefinitions');
63 $mform->setType('wizardpage', PARAM_ALPHA);
64 $this->add_action_buttons(true, get_string('nextpage', 'qtype_calculated'));
65 }
66
67}
68?>