]> git.mjollnir.org Git - moodle.git/commitdiff
more work on the calculated and datasetdependent qtype
authorjamiesensei <jamiesensei>
Sat, 13 Jan 2007 08:59:00 +0000 (08:59 +0000)
committerjamiesensei <jamiesensei>
Sat, 13 Jan 2007 08:59:00 +0000 (08:59 +0000)
lang/en_utf8/qtype_calculated.php
lang/en_utf8/qtype_datasetdependent.php [new file with mode: 0644]
question/type/calculated/edit_calculated_form.php
question/type/datasetdependent/abstractqtype.php
question/type/datasetdependent/datasetdefinitions_form.php [new file with mode: 0644]
question/type/datasetdependent/datasetitems_form.php [new file with mode: 0644]

index 6144790f473dc5b1348dc39d6dccb2c663fe1f2c..2b2a5091825c901ae3e9f777ea9b0318067aee4e 100644 (file)
@@ -10,4 +10,5 @@ $string['mustbenumeric'] = 'You must enter a number here.';
 $string['mustnotbenumeric'] = 'This can\'t be a number.';
 $string['youmustenteramultiplierhere'] = 'You must enter a multiplier here.';
 $string['nextpage'] = 'Next Page';
+$string['makecopynextpage'] = 'Next Page (new question)';
 ?>
\ No newline at end of file
diff --git a/lang/en_utf8/qtype_datasetdependent.php b/lang/en_utf8/qtype_datasetdependent.php
new file mode 100644 (file)
index 0000000..cc46217
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+$string['itemno'] = 'Item $a';
+$string['param'] = 'Param {<strong>$a</strong>}';
+$string['additem'] = 'Add Item';
+$string['itemtoadd'] = 'Item To Add';
+$string['calclength'] = 'Significant Figures';
+$string['calcdistribution'] = 'Distribution';
+$string['uniform'] = 'Uniform';
+$string['loguniform'] = 'Loguniform';
+$string['generate'] = 'Generate';
+$string['calcmin'] = 'Minimum';
+$string['calcmax'] = 'Maximum';
+$string['minmax'] = 'Range of Values';
+?>
\ No newline at end of file
index 693c4cb6f5122f7ef541c60f0002c53809dea046..fc9442db7a66b643e8031fa55a7da403906da1bf 100644 (file)
@@ -152,9 +152,11 @@ class question_edit_calculated_form extends question_edit_form {
                     $key++;
                 }
             }
-            $default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
-            $question = (object)((array)$question + $default_values);
         }
+        $default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
+        $default_values['makecopy'] = get_string('makecopynextpage', 'qtype_calculated');
+        $question = (object)((array)$question + $default_values);
+
 
         parent::set_data($question);
     }
@@ -174,11 +176,13 @@ class question_edit_calculated_form extends question_edit_form {
         foreach ($answers as $key => $answer){
             //check no of choices
             $trimmedanswer = trim($answer);
-            if (!empty($trimmedanswer)){
+            if (!empty($trimmedanswer)||$answercount==0){
                 $eqerror = qtype_calculated_find_formula_errors($trimmedanswer);
                 if (FALSE !== $eqerror){
                     $errors['answers['.$key.']'] = $eqerror;
                 }
+            }
+            if (!empty($trimmedanswer)){
                 if ('2' == $data['correctanswerformat'][$key]
                         && '0' == $data['correctanswerlength'][$key]) {
                     $errors['correctanswerlength['.$key.']'] = get_string('zerosignificantfiguresnotallowed','quiz');
index a7b4d97fbe6adc2a732dde1d0a5a7e9773ea49b6..5e5c29ee6baaf4407e6a5a79c14ea50172cd2e5c 100644 (file)
@@ -228,8 +228,7 @@ class question_dataset_dependent_questiontype extends default_questiontype {
                         $SESSION->datasetdependent->definitionform = $form;
                     } else {
                         // Something went wrong, go back to the first page
-                        redirect("question.php?category={$question->category}" .
-                                 "&qtype={$question->qtype}");
+                        redirect("question.php?category={$question->category}" ."&qtype={$question->qtype}");
                     }
                 } else {
                     $this->save_dataset_definitions($form);
@@ -237,8 +236,7 @@ class question_dataset_dependent_questiontype extends default_questiontype {
                 break;
             case 'datasetitems':
                 if (empty($form->id) && isset($form->addbutton)) {
-                    $question = parent::save_question($question,
-                     $SESSION->datasetdependent->questionform, $course);
+                    $question = parent::save_question($question, $SESSION->datasetdependent->questionform, $course);
                     $SESSION->datasetdependent->definitionform->id = $form->id = $question->id;
                     $this->save_dataset_definitions($SESSION->datasetdependent->definitionform);
                     unset($SESSION->datasetdependent);
diff --git a/question/type/datasetdependent/datasetdefinitions_form.php b/question/type/datasetdependent/datasetdefinitions_form.php
new file mode 100644 (file)
index 0000000..73e61b7
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+class question_dataset_dependent_definitions_form extends moodleform {
+    /**
+     * Question object with options and answers already loaded by get_question_options
+     * Be careful how you use this it is needed sometimes to set up the structure of the
+     * form in definition_inner but data is always loaded into the form with set_defaults.
+     *
+     * @var object
+     */
+    var $question;
+    /**
+     * Reference to question type object
+     *
+     * @var question_dataset_dependent_questiontype
+     */
+    var $qtypeobj;
+    /**
+     * Add question-type specific form fields.
+     *
+     * @param MoodleQuickForm $mform the form being built.
+     */
+    function question_dataset_dependent_definitions_form($submiturl, $question){
+        global $QTYPES;
+        $this->question = $question;
+        $this->qtypeobj =& $QTYPES[$this->question->qtype];
+        parent::moodleform($submiturl);
+    }
+    function definition() {
+        $mform =& $this->_form;
+
+        $possibledatasets = $this->qtypeobj->find_dataset_names($this->question->questiontext);
+        $mandatorydatasets = array();
+        foreach ($this->question->answers as $answer) {
+            $mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
+        }
+        $key = 0;
+        $datasetmenus = array();
+        foreach ($mandatorydatasets as $datasetname) {
+            if (!isset($datasetmenus[$datasetname])) {
+                list($options, $selected) =
+                        $this->qtypeobj->dataset_options($this->question, $datasetname);
+                unset($options['0']); // Mandatory...
+                $label = get_string("wildcard", "quiz"). " <strong>$datasetname</strong> ". get_string("substitutedby", "quiz");
+                $mform->addElement('select', "dataset[$key]", $label, $options);
+                $mform->setDefault("dataset[$key]", $selected);
+                $datasetmenus[$datasetname]='';
+                $key++;
+            }
+        }
+        foreach ($possibledatasets as $datasetname) {
+            if (!isset($datasetmenus[$datasetname])) {
+                list($options, $selected) =
+                        $this->qtypeobj->dataset_options($this->question, $datasetname);
+                $label = get_string("wildcard", "quiz"). " <strong>$datasetname</strong> ". get_string("substitutedby", "quiz");
+                $mform->addElement('select', "dataset[$key]", $label, $options);
+                $mform->setDefault("dataset[$key]", $selected);
+                $datasetmenus[$datasetname]='';
+                $key++;
+            }
+        }
+        //hidden elements
+        $mform->addElement('hidden', 'wizardpage', 'datasetdefinitions');
+        $mform->setType('wizardpage', PARAM_ALPHA);
+        $this->add_action_buttons(true, get_string('nextpage', 'qtype_calculated'));
+    }
+
+}
+?>
\ No newline at end of file
diff --git a/question/type/datasetdependent/datasetitems_form.php b/question/type/datasetdependent/datasetitems_form.php
new file mode 100644 (file)
index 0000000..719c301
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+class question_dataset_dependent_items_form extends moodleform {
+    /**
+     * Question object with options and answers already loaded by get_question_options
+     * Be careful how you use this it is needed sometimes to set up the structure of the
+     * form in definition_inner but data is always loaded into the form with set_defaults.
+     *
+     * @var object
+     */
+    var $question;
+    /**
+     * Reference to question type object
+     *
+     * @var question_dataset_dependent_questiontype
+     */
+    var $qtypeobj;
+    /**
+     * Add question-type specific form fields.
+     *
+     * @param MoodleQuickForm $mform the form being built.
+     */
+    function question_dataset_dependent_items_form($submiturl, $question){
+        global $QTYPES;
+        $this->question = $question;
+        $this->qtypeobj =& $QTYPES[$this->question->qtype];
+        parent::moodleform($submiturl);
+    }
+    function definition() {
+        $mform =& $this->_form;
+
+        $repeated = array();
+        $repeatedoptions = array();
+        $repeated[] =& $mform->createElement('header', 'itemhdr', get_string('itemno', 'qtype_datasetdependent', '{no}'));
+        $params = array('a', 'b', 'c');
+        foreach ($params as $paramno => $param){
+            $idx = $paramno +1;
+            $repeated[] =& $mform->createElement('text', "number[$idx]", get_string('param', 'qtype_datasetdependent', $param));
+            $repeated[] =& $mform->createElement('hidden', "itemid[$idx]");
+            $repeated[] =& $mform->createElement('hidden', "definition[$idx]");
+
+            $repeatedoptions["number[$idx]"]['type'] = PARAM_NUMBER;
+            //$repeatedoptions["number[$idx]"]['rule'] = 'numeric';
+            $repeatedoptions["itemid[$idx]"]['type'] = PARAM_INT;
+            $repeatedoptions["definition[$idx]"]['type'] = PARAM_NOTAGS;
+        }
+
+        /*if (isset($this->question->options)){
+            $countanswers = count($this->question->options->answers);
+        } else {
+            $countanswers = 0;
+        }
+        $repeatsatstart = (QUESTION_NUMANS_START > ($countanswers + QUESTION_NUMANS_ADD))?
+                            QUESTION_NUMANS_START : ($countanswers + QUESTION_NUMANS_ADD);
+        */
+        $repeatsatstart = 3;
+        $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'itemsno', 'itemsadd', 1, get_string('additem', 'qtype_datasetdependent'));
+
+
+        if ($this->qtypeobj->supports_dataset_item_generation()){
+            $radiogrp = array();
+            $radiogrp[] =& $mform->createElement('radio', "forceregeneration", 0, get_string('reuseifpossible', 'quiz'));
+            $radiogrp[] =& $mform->createElement('radio', "forceregeneration", 1, get_string('forceregeneration', 'quiz'));
+            $mform->addGroup($radiogrp, 'forceregenerationgrp', '', null, false);
+        }
+
+        $mform->addElement('header', 'additemhdr', get_string('itemtoadd', 'qtype_datasetdependent'));
+        foreach ($params as $paramno => $param){
+            $idx = $paramno +1;
+            $mform->addElement('text', "numbertoadd[$idx]", get_string('param', 'qtype_datasetdependent', $param));
+
+            $minmaxgrp = array();
+            $minmaxgrp[] =& $mform->createElement('text', "calcmin[$idx]", get_string('calcmin', 'qtype_datasetdependent'), 'size="3"');
+            $minmaxgrp[] =& $mform->createElement('text', "calcmax[$idx]", get_string('calcmax', 'qtype_datasetdependent'), 'size="3"');
+            $mform->addGroup($minmaxgrp, 'minmaxgrp', get_string('minmax', 'qtype_datasetdependent'), ' - ', false);
+
+            $precisionoptions = range(0, 10);
+            $mform->addElement('select', "calclength[$idx]", get_string('calclength', 'qtype_datasetdependent'), $precisionoptions);
+
+            $distriboptions = array('uniform' => get_string('uniform', 'qtype_datasetdependent'), 'loguniform' => get_string('loguniform', 'qtype_datasetdependent'));
+            $mform->addElement('select', "calcdistribution[$idx]", get_string('calcdistribution', 'qtype_datasetdependent'), $distriboptions);
+
+
+            $mform->addElement('submit', "generate[$idx]", get_string('generate', 'qtype_datasetdependent'));
+            $mform->addElement('hidden', "definition[$idx]");
+
+            $repeatedoptions["number[$idx]"]['type'] = PARAM_NUMBER;
+            //$repeatedoptions["number[$idx]"]['rule'] = 'numeric';
+            $repeatedoptions["itemid[$idx]"]['type'] = PARAM_INT;
+            $repeatedoptions["definition[$idx]"]['type'] = PARAM_NOTAGS;
+        }
+        $mform->addElement('hidden', 'wizardpage', 'datasetitems');
+        $mform->setType('wizardpage', PARAM_ALPHA);
+        $this->add_action_buttons(true);
+    }
+
+}
+?>
\ No newline at end of file