]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20296 Units handling for numerical and calculatedquestions
authorpichetp <pichetp>
Wed, 7 Oct 2009 20:45:45 +0000 (20:45 +0000)
committerpichetp <pichetp>
Wed, 7 Oct 2009 20:45:45 +0000 (20:45 +0000)
question/type/calculated/edit_calculated_form.php
question/type/calculatedsimple/edit_calculatedsimple_form.php
question/type/calculatedsimple/questiontype.php
question/type/numerical/db/install.xml
question/type/numerical/db/upgrade.php
question/type/numerical/display.html [new file with mode: 0644]
question/type/numerical/edit_numerical_form.php
question/type/numerical/version.php
question/type/shortanswer/display.html

index 8286f4130d4dc31ddd253a0d28cf67687a7b38a0..80537cc33f68a343bd10b72eea6ef2442aadfa80 100644 (file)
@@ -193,8 +193,14 @@ class question_edit_calculated_form extends question_edit_form {
                 $mform->addElement('hidden', 'multiplier'."[$i]", optional_param('multiplier'."[$i]", '', PARAM_NUMBER));
                 $mform->setType('multiplier'."[$i]", PARAM_NUMBER);
             }  
+          $mform->addElement('hidden','unitgradingtype',optional_param('unitgradingtype', '', PARAM_INT)) ;
+          $mform->addElement('hidden','unitpenalty',optional_param('unitpenalty', '', PARAM_NUMBER)) ;
+          $mform->addElement('hidden','showunits',optional_param('showunits', '', PARAM_INT)) ;
+          $mform->addElement('hidden','unitsleft',optional_param('unitsleft', '', PARAM_INT)) ; 
+          $mform->addElement('hidden','instructions',optional_param('instructions', '', PARAM_RAW)) ;  
 
         }else {
+        $QTYPES['numerical']->edit_numerical_options($mform,$this);
             $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}'));    
             $repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz'));
             $repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz'));
@@ -253,7 +259,7 @@ class question_edit_calculated_form extends question_edit_form {
 
     function set_data($question) {
         if (isset($this->editasmultichoice)){
-             $default_values['multichoice']= 1 ; //$this->editasmultichoice ;
+             $default_values['multichoice']= $this->editasmultichoice ; //$this->editasmultichoice ;
         }
         if (isset($question->options)){
             $answers = $question->options->answers;
@@ -270,6 +276,12 @@ class question_edit_calculated_form extends question_edit_form {
                     $key++;
                 }
             }
+          $default_values['unitgradingtype'] = $question->options->unitgradingtype ;
+          $default_values['unitpenalty'] = $question->options->unitpenalty ;
+          $default_values['showunits'] = $question->options->showunits ;
+          $default_values['unitsleft'] = $question->options->unitsleft ;
+          $default_values['instructions'] = $question->options->instructions  ;
+
             if (isset($question->options->units)){
                 $units  = array_values($question->options->units);
                 // make sure the default unit is at index 0
index 2ce33499e798f301156d4c17e586f84b8ac5c647..0ef397a17fce38da0ed274b160d33c4185c1a55f 100644 (file)
@@ -52,6 +52,8 @@ class question_edit_calculatedsimple_form extends question_edit_form {
         global $QTYPES, $SESSION, $CFG, $DB;
         $this->regenerate = true;
         $this->question = $question;
+                echo "<p> question <pre>";print_r($question);echo "</pre></p>";
+
         $this->qtypeobj =& $QTYPES[$this->question->qtype];
         //get the dataset definitions for this question
         //coming here everytime even when using a NoSubmitButton
@@ -136,6 +138,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
                         if(trim($answer) != ''){  // just look for non-empty 
                             $this->answer[$key]=new stdClass();
                             $this->answer[$key]->answer = $answer;
+                            $this->answer[$key]->fraction = $fraction[$key];
                             $this->answer[$key]->tolerance = $tolerance[$key];
                             $this->answer[$key]->tolerancetype = $tolerancetype[$key];
                             $this->answer[$key]->correctanswerlength = $correctanswerlength[$key];
@@ -150,7 +153,8 @@ class question_edit_calculatedsimple_form extends question_edit_form {
                 if ($olddef  = optional_param('datasetdef', '', PARAM_RAW)){ 
                     $calcmin = optional_param('calcmin', '', PARAM_NUMBER); 
                     $calclength = optional_param('calclength', '', PARAM_INT); 
-                    $calcmax = optional_param('calcmax', '', PARAM_NUMBER); 
+                    $calcmax = optional_param('calcmax', '', PARAM_NUMBER);
+                    $oldoptions  = optional_param('defoptions', '', PARAM_RAW); 
                     $newdatasetvalues = false ; 
                     for($key = 1 ; $key <= sizeof($olddef) ; $key++) {
                         $def = $olddef[$key] ;
@@ -158,7 +162,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
                         $this->datasetdefs[$def]->type = 1;
                         $this->datasetdefs[$def]->category = 0;
                       //  $this->datasets[$key]->name = $datasetname;
-                      //  $this->datasetdefs[$def]->options = $oldoptions[$key] ;
+                        $this->datasetdefs[$def]->options = $oldoptions[$key] ;
                         $this->datasetdefs[$def]->calcmin = $calcmin[$key] ;
                         $this->datasetdefs[$def]->calcmax = $calcmax[$key] ;
                         $this->datasetdefs[$def]->calclength = $calclength[$key] ;
@@ -283,6 +287,8 @@ class question_edit_calculatedsimple_form extends question_edit_form {
         $this->qtypeobj =& $QTYPES[$this->qtype()];
         $strquestionlabel = $this->qtypeobj->comment_header($this->nonemptyanswer);
         $label = get_string("sharedwildcards", "qtype_datasetdependent");
+        $mform->addElement('hidden', 'multichoice', 0);
+        $mform->addElement('hidden', 'synchronize', 0);
         $mform->addElement('hidden', 'initialcategory', 1);
         $mform->setType('initialcategory', PARAM_INT);
         $mform->addElement('hidden', 'reload', 1);
@@ -297,6 +303,8 @@ class question_edit_calculatedsimple_form extends question_edit_form {
         $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'),
                 $creategrades->gradeoptions, 1, 1);
 
+        $QTYPES['numerical']->edit_numerical_options($mform,$this);
+        
         $repeated = array();
         $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}'));
 
@@ -324,6 +332,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
             $firstunit->setValue('1.0');
             $firstunit->setPersistantFreeze(true);
         }
+
         //hidden elements
    //     $mform->addElement('hidden', 'wizard', 'datasetdefinitions');
    //     $mform->setType('wizard', PARAM_ALPHA);
@@ -359,6 +368,8 @@ class question_edit_calculatedsimple_form extends question_edit_form {
                     $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
                     $mform->addElement('hidden', "datasetdef[$idx]");
                     $mform->setType("datasetdef[$idx]", PARAM_RAW);
+                    $mform->addElement('hidden', "defoptions[$idx]");
+                    $mform->setType("defoptions[$idx]", PARAM_RAW);                                        
                     $idx++;
                     $mform->addElement('static', "divider[$j]", '', '<hr />');
                     $j++;
@@ -538,6 +549,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
         $mform->closeHeaderBefore('warningnowildcards');
     }
 
+
 //------------------------------------------------------------------------------------------------------------------------------
         //non standard name for button element needed so not using add_action_buttons
         //hidden elements
@@ -575,10 +587,11 @@ class question_edit_calculatedsimple_form extends question_edit_form {
     function set_data($question) {
             $answer = $this->answer;
         $default_values = array();
-         /*   if (count($answer)) {
+            if (count($answer)) {
                 $key = 0;
                 foreach ($answer as $answer){
                     $default_values['answer['.$key.']'] = $answer->answer;
+                  //  echo "<p> $answer->fraction </p>"; 
                     $default_values['fraction['.$key.']'] = $answer->fraction;
                     $default_values['tolerance['.$key.']'] = $answer->tolerance;
                     $default_values['tolerancetype['.$key.']'] = $answer->tolerancetype;
@@ -587,8 +600,16 @@ class question_edit_calculatedsimple_form extends question_edit_form {
                     $default_values['feedback['.$key.']'] = $answer->feedback;
                     $key++;
                 }
-            }*/
+            }
+            $default_values['multichoice'] = 0 ;
+            $default_values['synchronize'] = 0 ;
             if (isset($question->options)){
+                    $default_values['unitgradingtype'] = $question->options->unitgradingtype ;
+                    $default_values['unitpenalty'] = $question->options->unitpenalty ;
+                    $default_values['showunits'] = $question->options->showunits ;
+                    $default_values['unitsleft'] = $question->options->unitsleft ;
+                    $default_values['instructions'] = $question->options->instructions  ;
+
                 $units  = array_values($question->options->units);
                 // make sure the default unit is at index 0
                 usort($units, create_function('$a, $b',
@@ -781,7 +802,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
         }
                 /*Here we use the already done the error analysis so that 
         * we could force all wild cards values display if there is an error in values.
-        * as using a , in a number */
+        * as using a , in a number *//*
         $numbers = $data['number'];
         foreach ($numbers as $key => $number){
             if(! is_numeric($number)){
@@ -796,7 +817,7 @@ class question_edit_calculatedsimple_form extends question_edit_form {
                 $errors['number['.$key.']'] = get_string('notvalidnumber', 'qtype_datasetdependent');
             }        
         }
-        
+        */
         if ( $this->noofitems==0  ){
             $errors['warning'] = get_string('warning', 'mnet');
         }
index 787dba5fdc12cf5271914b53d40bae8b1fa30a21..3009c28f1486c0b628ff4065507b593e1e2a1469 100644 (file)
@@ -24,7 +24,7 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
     function save_question_options($question) {
         //$options = $question->subtypeoptions;
         // Get old answers:
-        global $CFG, $DB;
+        global $CFG, $DB , $QTYPES;
 
         if (isset($question->answer) && !isset($question->answers)) {
             $question->answers = $question->answer;
@@ -40,7 +40,7 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
         }
 
         // Save the units.
-        $virtualqtype = $this->get_virtual_qtype();
+        $virtualqtype = $this->get_virtual_qtype($question);
         $result = $virtualqtype->save_numerical_units($question);
         if (isset($result->error)) {
             return $result;
@@ -180,6 +180,11 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
         if(!empty($question->makecopy) && !empty($question->convert)) {
             $DB->set_field('question', 'qtype', 'calculated', array('id'=> $question->id));
         }
+        $result = $QTYPES['numerical']->save_numerical_options($question);
+        if (isset($result->error)) {
+            return $result;
+        }
+
         if (!empty($result->notice)) {
             return $result;
         }
@@ -261,7 +266,7 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
     }
 
     function comment_on_datasetitems($questionid, $answers,$data, $number) {
-        global $DB;
+        global $DB,$QTYPES;
         $comment = new stdClass;
         $comment->stranswers = array();
         $comment->outsidelimit = false ;
@@ -278,7 +283,7 @@ class question_calculatedsimple_qtype extends question_calculated_qtype {
         $strmax = get_string('max', 'quiz');
         $errors = '';
         $delimiter = ': ';
-        $virtualqtype = $this->get_virtual_qtype();
+        $virtualqtype = & $QTYPES['numerical'] ; //$this->get_virtual_qtype($question);
         foreach ($answers as $key => $answer) {
             $formula = $this->substitute_variables($answer->answer,$data);
             $formattedanswer = qtype_calculated_calculate_answer(
index 731cfe9a1dceee5da4160a71c14cad10bc6350ea..735fc4b46606820a912858c9b5c1ec7924f18d60 100644 (file)
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="question/type/numerical/db" VERSION="20060812" COMMENT="XMLDB file for Moodle question/type/numerical"
+<XMLDB PATH="question/type/numerical/db" VERSION="20091001" COMMENT="XMLDB file for Moodle question/type/numerical"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
 >
   <TABLES>
-    <TABLE NAME="question_numerical" COMMENT="Options for numerical questions." NEXT="question_numerical_units">
+    <TABLE NAME="question_numerical" COMMENT="Options for numerical questions." NEXT="question_numerical_options">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="question"/>
         <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Redundant, because of the answer field. Foreign key references question.id." PREVIOUS="id" NEXT="answer"/>
         <INDEX NAME="answer" UNIQUE="false" FIELDS="answer"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="question_numerical_units" COMMENT="Optional unit options for numerical questions. This table is also used by the calculated question type." PREVIOUS="question_numerical">
+    <TABLE NAME="question_numerical_options" COMMENT="Options for questions of type numerical This table is also used by the calculated question type" PREVIOUS="question_numerical" NEXT="question_numerical_units">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="question"/>
+        <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="instructions"/>
+        <FIELD NAME="instructions" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Feedback shown for any incorrect response." PREVIOUS="question" NEXT="showunits"/>
+        <FIELD NAME="showunits" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="display units as multichoice" PREVIOUS="instructions" NEXT="unitsleft"/>
+        <FIELD NAME="unitsleft" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="display the unit at left as in $1.00" PREVIOUS="showunits" NEXT="unitgradingtype"/>
+        <FIELD NAME="unitgradingtype" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="0 no penalty, 1 total grade, 2 response grade" PREVIOUS="unitsleft" NEXT="unitpenalty"/>
+        <FIELD NAME="unitpenalty" TYPE="number" LENGTH="12" NOTNULL="true" UNSIGNED="true" DEFAULT="0.1" SEQUENCE="false" DECIMALS="7" PREVIOUS="unitgradingtype"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="question"/>
+        <KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="question_numerical_units" COMMENT="Optional unit options for numerical questions. This table is also used by the calculated question type." PREVIOUS="question_numerical_options">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="question"/>
         <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key references question.id" PREVIOUS="id" NEXT="multiplier"/>
index 57813f207f9aae6e4069730aeafb4f42195559b6..930f91cfb101657bd065fadc9ea30e18214efde6 100644 (file)
@@ -27,6 +27,30 @@ function xmldb_qtype_numerical_upgrade($oldversion) {
     $result = true;
 
 //===== 1.9.0 upgrade line ======//
+    if ($result && $oldversion < 2009100100 ) { //New version in version.php
+
+    /// Define table question_numerical_options to be created
+        $table = new xmldb_table('question_numerical_options');
+
+    /// Adding fields to table question_numerical_options
+        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+        $table->add_field('question', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('instructions', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
+        $table->add_field('showunits', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('unitsleft', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
+        $table->add_field('unitgradingtype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('unitpenalty', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0.1');
+
+    /// Adding keys to table question_numerical_options
+        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+        $table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
+    /// Conditionally launch create table for question_calculated_options
+        if (!$dbman->table_exists($table)) {
+            // $dbman->create_table doesnt return a result, we just have to trust it
+            $dbman->create_table($table);
+        }//else 
+        upgrade_plugin_savepoint($result, 2009100100, 'qtype', 'numerical');
+    }
 
     return $result;
 }
diff --git a/question/type/numerical/display.html b/question/type/numerical/display.html
new file mode 100644 (file)
index 0000000..daea9e6
--- /dev/null
@@ -0,0 +1,226 @@
+<?php     
+// as the entry is controlled the question type here is numerical
+                  $nameunit   = "name=\"".$question->name_prefix."unit\"";
+                  $nameanswer   = "name=\"".$question->name_prefix."answer\"";
+//if left unit is placed before answer so we need to answer field text and a center pice for the show units options 
+// split the respnse in 2 element numerical and units
+/*if (!empty($question->options->showunits)){
+        if(isset($question->options->units) &&  count($question->options->units)){
+            $length = 0;
+            $goodkey = 0 ;
+            foreach ($question->options->units as $key => $unit){
+                if (false === stripos($value, $unit->unit)){                   
+                }else{
+                    
+                    if(strlen($unit->unit)> $length) {$length =strlen($unit->unit);
+                    $goodkey = $key ;
+                }
+                }
+            }
+            if($length){
+                $value = str_replace($question->options->units[$goodkey]->unit, '' , $value);
+            }
+            $state->responses['unit']=$goodkey ;<div class="ablock clearfix">
+        }
+        
+    }*/
+            if (isset($state->responses['answer']) && $state->responses['answer']!='') {
+            $valueanswer = ' value="'.s($state->responses['answer']).'" ';
+        } else {
+            $valueanswer = ' value="" ';
+        }
+            if (isset($state->responses['unit']) && $state->responses['unit']!='') {
+            $valueunit = ' value="'.s($state->responses['unit']).'" ';
+        } else {
+            
+            $valueunit = ' value="" ';
+            if ($question->options->showunits == 2 ){
+              $valueunit = ' value="'.s($question->options->units[0]->unit).'" '; 
+            } 
+        }
+        // put a div to enclose the answer and unit elements<div class="clearfix"></div> 
+        $textlength = 20 ;
+?>
+
+<?php
+ if ( $question->options->unitsleft == 0 ){ ?>
+
+  <div class="answer">
+    <fieldset class="answer"  id="generalheader">
+        <legend class="ftoggler">
+           <?php echo get_string('number', 'quiz') ; ?>
+        </legend>
+    <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly  $nameanswer $valueanswer"; //
+    ?> size="<?php echo $textlength;?>" />
+    <?php echo $feedbackimg; ?>
+</fieldset>
+  </div>
+    
+<?php }// display unit
+        $class = ''; 
+        $feedbackimgunit = '';
+        if ($options->feedback){
+            $classunit = question_get_feedback_class(1-$this->raw_unitpenalty);
+            $feedbackimgunit = question_get_feedback_image(1-$this->raw_unitpenalty, $options->feedback);
+        }
+        if ($question->options->showunits == 3 || (isset($question->options->units) && count($question->options->units) == 0 )) {// no unit display or tested
+     
+?>
+  <div class="answer">
+    <input type="hidden"  
+    <?php 
+    echo $nameunit;  
+    ?> 
+   value ="" />
+  </div>
+<?php
+  } else if ($question->options->showunits == 0  ) {// display unit text input 
+?>   
+<div class="answer">
+    <fieldset class="clearfix"  id="generalheader">
+        <legend class="ftoggler">
+           <?php echo get_string('unit', 'quiz'); ?>
+        </legend>
+    <input type="text" class="<?php echo $classunit; ?>" <?php echo "$readonly  $nameunit $valueunit"; //
+    ?> size="<?php echo $textlength;?>"/>
+    <?php echo $feedbackimgunit; ?>
+</fieldset>
+  </div>
+<?php            
+
+  } else if ($question->options->showunits == 2 ) {// display text
+     
+?>
+  <div class="answer">
+    <fieldset class="clearfix"  id="generalheader">
+        <legend class="ftoggler">
+           <?php echo get_string('unit', 'quiz'); 
+           //echo $question->options->units[0]->unit  ;
+            ?>
+        </legend>
+    <input type="hidden"  
+    <?php 
+    echo $nameunit; echo $valueunit ; 
+
+    ?> 
+   />
+ <?php   echo $question->options->units[0]->unit  ;
+
+         echo '&nbsp; ' ; 
+     ?>
+    </fieldset>
+  </div>
+  
+  <?php
+
+    //display the units as choice    
+    
+    } else if ($question->options->showunits == 1){?>
+
+
+<?php 
+    //display the units as choice    
+    if ($question->options->showunits == 1 && isset($question->options->units)){?>
+          <div class="answer">
+            <table class="answer">
+
+<?php       foreach ($question->options->units as $key => $unit) { 
+            $checked = '';
+            $chosen = false;
+              
+                $type = 'type="radio"';
+             //   $nameunit   = "name=\"".$question->name_prefix;//."unit\"";
+                if (isset($state->responses['unit'])){
+                    if ($state->responses['unit'] == $unit->unit) {
+                    $checked = 'checked="checked"';
+                    $chosen = true;
+                }
+                }else if ($key == 0) {
+                    $checked = 'checked="checked"';
+                    $chosen = true;
+                }
+            $aid = $question->id ; 
+            $a = new stdClass;
+            $a->id   = $question->name_prefix."unit" ;//. "2"
+            $a->class = '';
+            $a->feedbackimg = '';
+
+            // Print the control
+            $a->control = "<input $readonly  $nameunit $checked $type value=\"$key\" />";
+
+            if ($options->correct_responses && $answer->fraction > 0) {
+                $a->class = question_get_feedback_class(1);
+            }
+            if (($options->feedback && $chosen) || $options->correct_responses) {
+                if ($type == ' type="checkbox" ') {
+                    $a->feedbackimg = question_get_feedback_image($answer->fraction > 0 ? 1 : 0, $chosen && $options->feedback);
+                } else {
+                    $a->feedbackimg = question_get_feedback_image($answer->fraction, $chosen && $options->feedback);
+                }
+            }
+
+            // Print the answer text
+            $a->text = format_text($unit->unit, FORMAT_MOODLE, $formatoptions, $cmoptions->course);
+            $row = 0 ;
+
+?>
+                  <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
+                    <td class="c0 control">
+                      <?php echo $a->control; ?>
+                    </td>
+                    <td class="c1 text <?php echo $a->class ?>">
+                      <label for="<?php echo $a->id ?>">
+                        <?php echo $a->text; ?>
+                        <?php echo $a->feedbackimg; ?>
+                      </label>
+                    </td>
+                  </tr>
+                <?php } ?>
+
+         </table>
+                                      
+         </div>  
+            <?php } // end unit choices
+            // display intructions
+            // general message first
+        }
+     
+ if ($question->options->unitsleft == 1 ){?>
+             
+ <div class="answer">
+    <fieldset class="clearfix"  id="generalheader">
+        <legend class="ftoggler">
+           <?php echo get_string('number', 'quiz'); ?>
+        </legend>
+    <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly  $nameanswer $valueanswer"; //
+    ?> size="<?php echo $textlength;?>"/>
+    <?php echo $feedbackimg; ?>
+   </fieldset>
+  </div>                   
+<?php }  
+        //</div> put a div to enclose the answer and unit elements
+?>
+
+
+
+       <div class="feedback">
+        <fieldset class="clearfix"  id="generalheader">
+        <legend class="ftoggler">
+           <?php echo get_string('instructions', 'quiz'); ?>
+        </legend>
+       <div class="feedback">
+     <?php echo get_string('validnumber', 'numerical');?>
+       </div>
+     <?php if (!empty($question->options->instructions)){?>
+        <div>
+     <?php   echo  format_text($question->options->instructions, true, $formatoptions, $cmoptions->course);?>
+        </div> 
+     <?php }?> 
+     </fieldset>      
+     </div>           
+
+  <?php  ?>
+
index 9bb9676aa74f4735e2ec17e293f3efceb38423c2..2933439f644f2834aec0b8fe66926b6d92feb435 100644 (file)
@@ -31,13 +31,42 @@ class question_edit_numerical_form extends question_edit_form {
      * @param MoodleQuickForm $mform the form being built.
      */
     function definition_inner(&$mform) {
+        global $QTYPES ;
 
 //------------------------------------------------------------------------------------------
         $creategrades = get_grade_options();
         $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_numerical', '{no}'),
                 $creategrades->gradeoptions);
 //------------------------------------------------------------------------------------------
-        $repeated = array();
+        $QTYPES['numerical']->edit_numerical_options($mform);
+        /*
+        $mform->addElement('header', 'unithandling', get_string("Units handling", 'qtype_numerical'));
+        $currentgrp1 = array();
+        
+        $currentgrp1[] =& $mform->createElement('text', 'unitpenalty', get_string('Penalty for bad unit', 'qtype_numerical') ,
+                array('size' => 3));
+        $currentgrp1[] =& $mform->createElement('static', 'penalty1','hello', get_string('as decimal fraction (0-1) of', 'qtype_numerical'));
+        $mform->addGroup($currentgrp1, 'penaltygrp', get_string('Penalty for bad unit', 'qtype_numerical'), null, false);
+        $mform->setType('unitpenalty', PARAM_NUMBER);
+        //$mform->addRule('unitpenalty', null, 'required', null, 'client');
+        $mform->setDefault('unitpenalty', 0.1);
+        $currentgrp = array();
+        $currentgrp[] =& $mform->createElement('radio', 'unitgradingtype', 'or', get_string('question grade', 'qtype_numerical'),1);
+        $currentgrp[] =& $mform->createElement('radio', 'unitgradingtype', '', get_string(' response grade', 'qtype_numerical'),2);
+        $mform->setDefault('unitgradingtype', 1);
+        $mform->addGroup($currentgrp, 'penaltychoicegrp', '',' or ', false);
+        $mform->setHelpButton('penaltychoicegrp', array('penaltygrp', get_string('unitpenalty', 'qtype_numerical'), 'qtype_numerical'));
+        $mform->addElement('radio', 'showunits', 'Edit unit  ', get_string('Editable text input element', 'qtype_numerical'),0);
+        $mform->addElement('radio', 'showunits', 'Select units ', get_string('Choice radio element', 'qtype_numerical'),1);
+        $mform->addElement('radio', 'showunits', 'Display unit ', get_string('NON editable text of Unit No1', 'qtype_numerical'),2);
+        $mform->addElement('radio', 'showunits', 'No unit display', get_string("Only numerical answer will be graded leave Unit No1 empty", 'qtype_numerical'),3);
+        $mform->setDefault('showunits', 0);
+        $currentgrp = array();
+        $leftgrp[] =& $mform->createElement('radio', 'unitsleft', '', get_string('left as $1.00', 'qtype_numerical'),1);
+        $leftgrp[] =& $mform->createElement('radio', 'unitsleft', '', get_string('rigth as 1.00cm', 'qtype_numerical'),0);
+        $mform->addGroup($leftgrp, 'unitsleft', 'Unit position',' or ', false);
+        $mform->setDefault('unitsleft', 0);
+        $repeated = array();*/
         $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}'));
 
         $repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz'));
@@ -71,6 +100,12 @@ class question_edit_numerical_form extends question_edit_form {
 
     function set_data($question) {
         if (isset($question->options)){
+          $default_values['unitgradingtype'] = $question->options->unitgradingtype ;
+          $default_values['unitpenalty'] = $question->options->unitpenalty ;
+          $default_values['showunits'] = $question->options->showunits ;
+          $default_values['unitsleft'] = $question->options->unitsleft ;
+          $default_values['instructions'] = $question->options->instructions  ;
+
             $answers = $question->options->answers;
             if (count($answers)) {
                 $key = 0;
index e1b7f3eee11d36f9af81744676def4084cf9ab98..c033bef16bcb3975854d5f4cf44f7f0bf5268be0 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP // $Id$
 
-$plugin->version  = 2006121500;
+$plugin->version  = 2009100100;
 $plugin->requires = 2007101000;
 
 ?>
index 6f1bbb478b20f1595db8743d1b13a73f7d072a15..375a20b42809932796e3f1673f9938c04e36b8eb 100644 (file)
   <div class="prompt">
     <?php echo get_string("answer", "quiz").': '; ?>
   </div>
-
+  <?php if ($question->qtype == 'numerical' || $question->qtype == 'calculated' || $question->qtype == 'calculatedsimple' ){ 
+        include("$CFG->dirroot/question/type/numerical/display.html");?>
+<?php }else {?>
   <div class="answer">
     <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $inputname $value"; ?> size="80"/>
     <?php echo $feedbackimg; ?>
   </div>
+<?php  }?>
   <?php if ($feedback) { ?>
     <div class="feedback">
       <?php echo $feedback ?>