more work on the calculated and datasetdependent qtype
[moodle.git] / question / type / datasetdependent / datasetitems_form.php
CommitLineData
8fc3e643 1<?php
2class question_dataset_dependent_items_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_items_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 $repeated = array();
32 $repeatedoptions = array();
33 $repeated[] =& $mform->createElement('header', 'itemhdr', get_string('itemno', 'qtype_datasetdependent', '{no}'));
34 $params = array('a', 'b', 'c');
35 foreach ($params as $paramno => $param){
36 $idx = $paramno +1;
37 $repeated[] =& $mform->createElement('text', "number[$idx]", get_string('param', 'qtype_datasetdependent', $param));
38 $repeated[] =& $mform->createElement('hidden', "itemid[$idx]");
39 $repeated[] =& $mform->createElement('hidden', "definition[$idx]");
40
41 $repeatedoptions["number[$idx]"]['type'] = PARAM_NUMBER;
42 //$repeatedoptions["number[$idx]"]['rule'] = 'numeric';
43 $repeatedoptions["itemid[$idx]"]['type'] = PARAM_INT;
44 $repeatedoptions["definition[$idx]"]['type'] = PARAM_NOTAGS;
45 }
46
47 /*if (isset($this->question->options)){
48 $countanswers = count($this->question->options->answers);
49 } else {
50 $countanswers = 0;
51 }
52 $repeatsatstart = (QUESTION_NUMANS_START > ($countanswers + QUESTION_NUMANS_ADD))?
53 QUESTION_NUMANS_START : ($countanswers + QUESTION_NUMANS_ADD);
54 */
55 $repeatsatstart = 3;
56 $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'itemsno', 'itemsadd', 1, get_string('additem', 'qtype_datasetdependent'));
57
58
59 if ($this->qtypeobj->supports_dataset_item_generation()){
60 $radiogrp = array();
61 $radiogrp[] =& $mform->createElement('radio', "forceregeneration", 0, get_string('reuseifpossible', 'quiz'));
62 $radiogrp[] =& $mform->createElement('radio', "forceregeneration", 1, get_string('forceregeneration', 'quiz'));
63 $mform->addGroup($radiogrp, 'forceregenerationgrp', '', null, false);
64 }
65
66 $mform->addElement('header', 'additemhdr', get_string('itemtoadd', 'qtype_datasetdependent'));
67 foreach ($params as $paramno => $param){
68 $idx = $paramno +1;
69 $mform->addElement('text', "numbertoadd[$idx]", get_string('param', 'qtype_datasetdependent', $param));
70
71 $minmaxgrp = array();
72 $minmaxgrp[] =& $mform->createElement('text', "calcmin[$idx]", get_string('calcmin', 'qtype_datasetdependent'), 'size="3"');
73 $minmaxgrp[] =& $mform->createElement('text', "calcmax[$idx]", get_string('calcmax', 'qtype_datasetdependent'), 'size="3"');
74 $mform->addGroup($minmaxgrp, 'minmaxgrp', get_string('minmax', 'qtype_datasetdependent'), ' - ', false);
75
76 $precisionoptions = range(0, 10);
77 $mform->addElement('select', "calclength[$idx]", get_string('calclength', 'qtype_datasetdependent'), $precisionoptions);
78
79 $distriboptions = array('uniform' => get_string('uniform', 'qtype_datasetdependent'), 'loguniform' => get_string('loguniform', 'qtype_datasetdependent'));
80 $mform->addElement('select', "calcdistribution[$idx]", get_string('calcdistribution', 'qtype_datasetdependent'), $distriboptions);
81
82
83 $mform->addElement('submit', "generate[$idx]", get_string('generate', 'qtype_datasetdependent'));
84 $mform->addElement('hidden', "definition[$idx]");
85
86 $repeatedoptions["number[$idx]"]['type'] = PARAM_NUMBER;
87 //$repeatedoptions["number[$idx]"]['rule'] = 'numeric';
88 $repeatedoptions["itemid[$idx]"]['type'] = PARAM_INT;
89 $repeatedoptions["definition[$idx]"]['type'] = PARAM_NOTAGS;
90 }
91 $mform->addElement('hidden', 'wizardpage', 'datasetitems');
92 $mform->setType('wizardpage', PARAM_ALPHA);
93 $this->add_action_buttons(true);
94 }
95
96}
97?>