]> git.mjollnir.org Git - moodle.git/commitdiff
working on multipage form for calculated question type
authorjamiesensei <jamiesensei>
Thu, 11 Jan 2007 04:59:16 +0000 (04:59 +0000)
committerjamiesensei <jamiesensei>
Thu, 11 Jan 2007 04:59:16 +0000 (04:59 +0000)
lang/en_utf8/qtype_calculated.php
question/question2.php
question/type/calculated/edit_calculated_form.php
question/type/calculated/questiontype.php
question/type/datasetdependent/abstractqtype.php
question/type/edit_question_form.php
question/type/questiontype.php

index def5ace36f61d07c9ab76fd08571afc708880c59..6144790f473dc5b1348dc39d6dccb2c663fe1f2c 100644 (file)
@@ -4,9 +4,10 @@ $string['correctanswershowsformat'] = 'Format';
 $string['tolerance'] = 'Tolerance &plusmn;';
 $string['addmoreanswerblanks'] = 'Add another answer blank.';
 $string['addmoreunitblanks'] = 'Blanks for $a More Units';
-$string['answerhdr'] = 'Answer $a';
+$string['answerhdr'] = 'Answer';
 $string['atleastoneanswer'] = 'You need to provide at least one answer.';
 $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';
 ?>
\ No newline at end of file
index ad70e3cf22a6b2c2bccd4bf7c341750539a5f8e7..9406650c62970b783ef94a7ef46f771d477960aa 100644 (file)
@@ -24,6 +24,7 @@ if (!$returnurl && isset($SESSION->fromurl)) {
 $id = optional_param('id', 0, PARAM_INT); // question id
 $qtype = optional_param('qtype', '', PARAM_FILE);
 $categoryid = optional_param('category', 0, PARAM_INT);
+$wizard =  optional_param('wizard', '', PARAM_ALPHA);
 
 // Validate the URL parameters.
 if ($id = optional_param('id', 0, PARAM_INT)) {
@@ -31,12 +32,12 @@ if ($id = optional_param('id', 0, PARAM_INT)) {
         print_error('questiondoesnotexist', 'question', $returnurl);
     }
     get_question_options($question);
-    $submiturl = "question2.php?id=$id&returnurl=" . urlencode($returnurl);
+    $submiturl = "question2.php?id=$id&returnurl=" . urlencode($returnurl).'&wizard='.$wizard;
 } else if ($categoryid && $qtype) { // only for creating new questions
     $question = new stdClass;
     $question->category = $categoryid;
     $question->qtype = $qtype;
-    $submiturl = "question2.php?category=$categoryid&qtype=$qtype&returnurl=" . urlencode($returnurl);
+    $submiturl = "question2.php?category=$categoryid&qtype=$qtype&returnurl=" . urlencode($returnurl).'&wizard='.$wizard;
 } else {
     print_error('notenoughdatatoeditaquestion', 'question', $returnurl);
 }
@@ -62,10 +63,20 @@ $coursecontext = get_context_instance(CONTEXT_COURSE, $category->course);
 require_capability('moodle/question:manage', $coursecontext);
 
 // Create the question editing form.
-$mform = $QTYPES[$question->qtype]->create_editing_form($submiturl, $question, $category->course);
+if ($wizard!==''){
+    if (!method_exists($QTYPES[$question->qtype], 'next_wizard_form')){
+        print_error('missingimportantcode', 'question', $returnurl, 'wizard form definition');
+    } else {
+        $mform = $QTYPES[$question->qtype]->next_wizard_form($submiturl, $question, $wizard);
+    }
+} else {
+    $mform = $QTYPES[$question->qtype]->create_editing_form($submiturl, $question, $category->course);
+}
+
 if ($mform === null) {
     print_error('missingimportantcode', 'question', $returnurl, 'question editing form definition');
 }
+$mform->set_defaults($question);
 
 if ($mform->is_cancelled()){
     redirect($returnurl);
@@ -75,12 +86,16 @@ if ($mform->is_cancelled()){
         $question->hidden = 0; // Copies should not be hidden
     }
     $question = $QTYPES[$qtype]->save_question($question, $data, $COURSE);
-
-    if (optional_param('inpopup', 0, PARAM_BOOL)) {
-        notify(get_string('changessaved'), '');
-        close_window(3);
+    if ($QTYPES[$qtype]->finished_edit_wizard($question)){
+        if (optional_param('inpopup', 0, PARAM_BOOL)) {
+            notify(get_string('changessaved'), '');
+            close_window(3);
+        } else {
+            redirect($SESSION->returnurl);
+        }
+        die;
     } else {
-        redirect($SESSION->returnurl);
+        redirect($submiturl.'&wizard='.$data->wizardpage);
     }
 } else {
     // Display the question editing form
@@ -94,10 +109,11 @@ if ($mform->is_cancelled()){
                 get_string("editquestions", "quiz").'</a> -> '.$streditingquestion;
     }
     print_header_simple($streditingquestion, '', $strediting);
-
-    print_heading_with_help(get_string("editing".$question->qtype, "quiz"), $question->qtype, "quiz");
-
-    $mform->set_defaults($question);
+    if (isset($mform->heading)){
+        print $mform->heading;
+    } else {
+        print_heading_with_help(get_string("editing".$question->qtype, "quiz"), $question->qtype, "quiz");
+    }
     $mform->display();
     print_footer($COURSE);
 }
index d82474cc8f09c5d33f2f59073229575cef67dea2..e698271235537d0ea552f386098a289ed434716d 100644 (file)
@@ -25,9 +25,10 @@ class question_edit_calculated_form extends question_edit_form {
      */
     function definition_inner(&$mform) {
         global $QTYPES;
-        $this->qtypeobj = $QTYPES['calculated'];
+        $this->qtypeobj =& $QTYPES[$this->qtype()];
 
 //------------------------------------------------------------------------------------------
+/*      //not working now datasetdependent code cannot handle multiple answer formulas and not needed ??
         $repeated = array();
         $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated', '{no}'));
 
@@ -59,7 +60,38 @@ class question_edit_calculated_form extends question_edit_form {
             $count = 0;
         }
         $repeatsatstart = $count + 1;
-        $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', 1, get_string('addmoreanswerblanks', 'qtype_calculated'));
+        $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', 1, get_string('addmoreanswerblanks', 'qtype_calculated'));*/
+//------------------------------------------------------------------------------------------
+
+        $mform->addElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated'));
+
+        $mform->addElement('text', 'answers[0]', get_string('correctanswerformula', 'quiz'));
+        $mform->setType('answers[0]', PARAM_NOTAGS);
+
+/*        $creategrades = get_grade_options();
+        $gradeoptions = $creategrades->gradeoptions;
+        $mform->addElement('select', 'fraction[0]', get_string('grade'), $gradeoptions);
+        $mform->setDefault('fraction[0]', 0);*/
+        $mform->addElement('hidden', 'fraction[0]', 1);
+        $mform->setConstants(array('fraction[0]'=>PARAM_INT));
+
+        $tolgrp = array();
+        $tolgrp[] =& $mform->createElement('text', 'tolerance[0]', get_string('tolerance', 'qtype_calculated'));
+        $mform->setType('tolerance[0]', PARAM_NUMBER);
+        $mform->setDefault('tolerance[0]', 0.01);
+        $tolgrp[] =& $mform->createElement('select', 'tolerancetype[0]', get_string('tolerancetype', 'quiz'), $this->qtypeobj->tolerance_types());
+        $mform->addGroup($tolgrp, 'tolgrp', get_string('tolerance', 'qtype_calculated'), null, false);
+
+        $anslengrp = array();
+        $anslengrp[] =&  $mform->createElement('select', 'correctanswerlength[0]', get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
+        $mform->setDefault('correctanswerlength[0]', 2);
+
+        $answerlengthformats = array('1' => get_string('decimalformat', 'quiz'), '2' => get_string('significantfiguresformat', 'quiz'));
+        $anslengrp[] =&  $mform->createElement('select', 'correctanswerformat[0]', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
+        $mform->addGroup($anslengrp, 'anslengrp', get_string('correctanswershows', 'qtype_calculated'), null, false);
+
+        $mform->addElement('htmleditor', 'feedback[0]', get_string('feedback', 'quiz'));
+        $mform->setType('feedback[0]', PARAM_RAW);
 
 //------------------------------------------------------------------------------------------
         $repeated = array();
@@ -87,6 +119,8 @@ class question_edit_calculated_form extends question_edit_form {
 
         //hidden elements
         $mform->addElement('hidden', 'wizardpage', 'question');
+        $mform->setType('wizardpage', PARAM_ALPHA);
+
 
     }
 
@@ -96,10 +130,10 @@ class question_edit_calculated_form extends question_edit_form {
             if (count($answers)) {
                 $key = 0;
                 foreach ($answers as $answer){
-                    $default_values['answers['.$key.']'] = $answers->answer;
-                    $default_values['fraction['.$key.']'] = $answers->fraction;
-                    $default_values['tolerance['.$key.']'] = $answers->tolerance;
-                    $default_values['correctanswerlength['.$key.']'] = $answers->correctanswerlength;
+                    $default_values['answers['.$key.']'] = $answer->answer;
+                    $default_values['fraction['.$key.']'] = $answer->fraction;
+                    $default_values['tolerance['.$key.']'] = $answer->tolerance;
+                    $default_values['correctanswerlength['.$key.']'] = $answer->correctanswerlength;
                     $default_values['correctanswerformat['.$key.']'] = $answer->correctanswerformat;
                     $default_values['feedback['.$key.']'] = $answer->feedback;
                     $key++;
@@ -118,7 +152,10 @@ class question_edit_calculated_form extends question_edit_form {
                     $key++;
                 }
             }
-            $question = (object)((array)$question + $default_values);        }
+            $default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
+            $question = (object)((array)$question + $default_values);
+        }
+
         parent::set_defaults($question);
     }
 
index 0507b180753ed9d900f124bb9f7c2c1e6e730609..66b51882bcbbdd5014af4eefb0ddbd2c21f39c26 100644 (file)
@@ -238,7 +238,7 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype
             $answer->answer = $correctanswer->answer;
         }
         $numericalquestion->questiontext = parent::substitute_variables(
-         $numericalquestion->questiontext, $state->options->dataset);
+        $numericalquestion->questiontext, $state->options->dataset);
         $virtualqtype->print_question_formulation_and_controls($numericalquestion,
          $state, $cmoptions, $options);
     }
@@ -597,7 +597,7 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype
         }
         return $str;
     }
-    
+
 /// BACKUP FUNCTIONS ////////////////////////////
 
     /*
index 16fb812040021091d95f9621e754b140fa350282..a7b4d97fbe6adc2a732dde1d0a5a7e9773ea49b6 100644 (file)
@@ -168,6 +168,39 @@ class question_dataset_dependent_questiontype extends default_questiontype {
         }
     }
 
+    // This gets called by question2.php after the standard question is saved
+    function &next_wizard_form($submiturl, $question, $wizard){
+        global $CFG, $SESSION;
+
+        // Catch invalid navigation & reloads
+        if (empty($question->id) && empty($SESSION->datasetdependent)) {
+            redirect('edit.php', 'The page you are loading has expired.', 3);
+        }
+        if (!isset($question->id)){
+            $question =& $SESSION->datasetdependent->questionform;
+        }
+
+        // See where we're coming from
+        switch($wizard) {
+            case 'question':
+                require("$CFG->dirroot/question/type/datasetdependent/datasetdefinitions_form.php");
+                $mform =& new question_dataset_dependent_definitions_form($submiturl, $question);
+                $mform->heading = print_heading_with_help(get_string("choosedatasetproperties", "quiz"), "questiondatasets", "quiz", '', true);
+                break;
+            case 'datasetdefinitions':
+            case 'datasetitems':
+                require("$CFG->dirroot/question/type/datasetdependent/datasetitems_form.php");
+                $mform =& new question_dataset_dependent_items_form($submiturl, $question);
+                $streditdatasets = get_string("editdatasets", "quiz");
+                $mform->heading  = print_heading_with_help($streditdatasets, 'questiondatasets', "quiz", '', true);
+                break;
+            default:
+                error('Incorrect or no wizard page specified!');
+                break;
+        }
+
+        return $mform;
+    }
     function save_question($question, &$form, $course) {
         // For dataset dependent questions a wizard is used for editing
         // questions. Therefore saving the question is delayed until
index 6ebae88dc2ff39e5cf9073d1f5ddf4558898441e..610695ad60af8123b48473dbf5a1b54a9a555e8d 100644 (file)
@@ -23,12 +23,7 @@ class question_edit_form extends moodleform {
      * @var object
      */
     var $question;
-    /**
-     * Course id
-     *
-     * @var integer
-     */
-    var $courseid;
+
     function question_edit_form($submiturl, $question){
         $this->question = $question;
         parent::moodleform($submiturl);
@@ -51,7 +46,7 @@ class question_edit_form extends moodleform {
         // Standard fields at the start of the form.
         $mform->addElement('header', 'generalheader', get_string("general", 'form'));
 
-        $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'),
+        $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'), null,
                 array('courseid' => $COURSE->id, 'published' => true, 'only_editable' => true));
 
         $mform->addElement('text', 'name', get_string('questionname', 'quiz'),
@@ -82,6 +77,7 @@ class question_edit_form extends moodleform {
         $mform->addElement('text', 'defaultgrade', get_string('defaultgrade', 'quiz'),
                 array('size' => 3));
         $mform->setType('defaultgrade', PARAM_INT);
+        $mform->setDefault('defaultgrade', 1);
         $mform->addRule('defaultgrade', null, 'required', null, 'client');
 
         $mform->addElement('text', 'penalty', get_string('penaltyfactor', 'quiz'),
@@ -89,6 +85,7 @@ class question_edit_form extends moodleform {
         $mform->setType('penalty', PARAM_NUMBER);
         $mform->addRule('penalty', null, 'required', null, 'client');
         $mform->setHelpButton('penalty', array('penalty', get_string('penalty', 'quiz'), 'quiz'));
+        $mform->setDefault('penalty', 0.1);
 
         $mform->addElement('htmleditor', 'generalfeedback', get_string('generalfeedback', 'quiz'),
                 array('rows' => 10, 'course' => $COURSE->id));
@@ -132,9 +129,7 @@ class question_edit_form extends moodleform {
 
     function set_defaults($question) {
         global $QTYPES;
-        if (!isset($question->id)){
-            $QTYPES[$question->qtype]->set_default_options($question);
-        }
+        $QTYPES[$question->qtype]->set_default_options($question);
         if (empty($question->image)){
             unset($question->image);
         }
index 182468b3f30e50e7b2e82a5e8cbb070fd8936b0d..5a8abf9ac422c616ebed1f17d2f2ced696449d26 100644 (file)
@@ -101,8 +101,6 @@ class default_questiontype {
      * @param $question
      */
     function set_default_options(&$question) {
-        $question->penalty = 0.1;
-        $question->defaultgrade = 1;
     }
 
     /**