Automatic installer.php lang files by installer_builder (20070310)
[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() {
60b5ecd3 29 global $SESSION;
8fc3e643 30 $mform =& $this->_form;
31
32 $possibledatasets = $this->qtypeobj->find_dataset_names($this->question->questiontext);
33 $mandatorydatasets = array();
60b5ecd3 34 if (isset($this->question->options->answers)){
35 foreach ($this->question->options->answers as $answer) {
36 $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer->answer);
37 }
38 }else{
39 foreach ($SESSION->datasetdependent->questionform->answers as $answer){
40 $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
41 }
8fc3e643 42 }
60b5ecd3 43
8fc3e643 44 $key = 0;
45 $datasetmenus = array();
46 foreach ($mandatorydatasets as $datasetname) {
47 if (!isset($datasetmenus[$datasetname])) {
48 list($options, $selected) =
49 $this->qtypeobj->dataset_options($this->question, $datasetname);
50 unset($options['0']); // Mandatory...
51 $label = get_string("wildcard", "quiz"). " <strong>$datasetname</strong> ". get_string("substitutedby", "quiz");
52 $mform->addElement('select', "dataset[$key]", $label, $options);
53 $mform->setDefault("dataset[$key]", $selected);
54 $datasetmenus[$datasetname]='';
55 $key++;
56 }
57 }
58 foreach ($possibledatasets as $datasetname) {
59 if (!isset($datasetmenus[$datasetname])) {
60 list($options, $selected) =
61 $this->qtypeobj->dataset_options($this->question, $datasetname);
62 $label = get_string("wildcard", "quiz"). " <strong>$datasetname</strong> ". get_string("substitutedby", "quiz");
63 $mform->addElement('select', "dataset[$key]", $label, $options);
64 $mform->setDefault("dataset[$key]", $selected);
65 $datasetmenus[$datasetname]='';
66 $key++;
67 }
68 }
a8d2a373 69 $this->add_action_buttons(false, get_string('nextpage', 'qtype_calculated'));
60b5ecd3 70
71
72 //hidden elements
73 $mform->addElement('hidden', 'returnurl');
74 $mform->setType('returnurl', PARAM_URL);
75 $mform->addElement('hidden', 'qtype');
76 $mform->setType('qtype', PARAM_ALPHA);
77 $mform->addElement('hidden', 'category');
78 $mform->setType('category', PARAM_INT);
79 $mform->addElement('hidden', 'id');
80 $mform->setType('id', PARAM_INT);
81 $mform->addElement('hidden', 'wizard', 'datasetitems');
82 $mform->setType('wizard', PARAM_ALPHA);
8fc3e643 83 }
84
85}
86?>