]> git.mjollnir.org Git - moodle.git/commitdiff
some extra validaton for multichoice and some bug fixes for multichoice and random...
authorjamiesensei <jamiesensei>
Mon, 8 Jan 2007 10:35:57 +0000 (10:35 +0000)
committerjamiesensei <jamiesensei>
Mon, 8 Jan 2007 10:35:57 +0000 (10:35 +0000)
lang/en_utf8/qtype_multichoice.php
question/type/multichoice/edit_multichoice_form.php
question/type/random/edit_random_form.php

index 7b04cd2a1b440dad0cf7b05af033637216a4c01e..ff25aea1ec338fd39fb896d553c0e5c4826be5da 100644 (file)
@@ -11,6 +11,8 @@ $string['choices'] = 'Available choices';
 $string['clozeaid'] = 'Enter missing word';
 $string['correctfeedback'] = 'For any correct answer';
 $string['editingmultichoice'] = 'Editing a Multiple Choice question';
+$string['errfractionsaddwrong'] = 'The positive grades you have chosen do not add up to 100%%<br />Instead, they add up to $a%%';
+$string['errfractionsnomax'] = 'One of the answers should be 100%%, so that it is<br />possible to get a full grade for this question.';
 $string['feedback'] = 'Feedback';
 $string['fillouttwochoices'] = 'You must fill out at least two choices.  Choices left blank will not be used.';
 $string['fractionsaddwrong'] = 'The positive grades you have chosen do not add up to 100%%<br />Instead, they add up to $a%%<br />Do you want to go back and fix this question?';
index b3701cb9fe6c5a04a35fbdafc32970d26214657c..b11790e698fc421a1d6dda07b5e1c40ffb4827b3 100644 (file)
@@ -78,7 +78,7 @@ class question_edit_multichoice_form extends question_edit_form {
             $default_values['shuffleanswers'] =  $question->options->shuffleanswers;
             $default_values['correctfeedback'] =  $question->options->correctfeedback;
             $default_values['partiallycorrectfeedback'] =  $question->options->partiallycorrectfeedback;
-            $default_values['overallincorrectfeedback'] =  $question->options->overallincorrectfeedback;
+            $default_values['incorrectfeedback'] =  $question->options->incorrectfeedback;
             $question = (object)((array)$question + $default_values);
         }
         parent::set_defaults($question);
@@ -92,12 +92,27 @@ class question_edit_multichoice_form extends question_edit_form {
         $errors = array();
         $answers = $data['answer'];
         $answercount = 0;
-        foreach ($answers as $answer){
+
+        $totalfraction = 0;
+        $maxfraction = -1;
+
+        foreach ($answers as $key => $answer){
+            //check no of choices
             $trimmedanswer = trim($answer);
             if (!empty($trimmedanswer)){
                 $answercount++;
             }
+            //check grades
+            if ($answer != '') {
+                if ($data['fraction'][$key] > 0) {
+                    $totalfraction += $data['fraction'][$key];
+                }
+                if ($data['fraction'][$key] > $maxfraction) {
+                    $maxfraction = $data['fraction'][$key];
+                }
+            }
         }
+
         if ($answercount==0){
             $errors['answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
             $errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
@@ -105,6 +120,20 @@ class question_edit_multichoice_form extends question_edit_form {
             $errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
 
         }
+
+        /// Perform sanity checks on fractional grades
+        if ($data['single']) {
+            if ($maxfraction != 1) {
+                $maxfraction = $maxfraction * 100;
+                $errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_multichoice', $maxfraction);
+            }
+        } else {
+            $totalfraction = round($totalfraction,2);
+            if ($totalfraction != 1) {
+                $totalfraction = $totalfraction * 100;
+                $errors['fraction[0]'] = get_string('errfractionsaddwrong', 'qtype_multichoice', $totalfraction);
+            }
+        }
         return $errors;
     }
 }
index 39dadd7485432cff6d496c2ae5a337e789b49add..707957bde4e0065a8d492c4d5cd8056a57221bf1 100644 (file)
@@ -41,6 +41,9 @@ class question_edit_random_form extends question_edit_form {
         $mform->addElement('advcheckbox', 'questiontext', get_string("recurse", "quiz"), null, null, array(0, 1));
 
         // Standard fields at the end of the form.
+        $mform->addElement('hidden', 'questiontextformat', 0);
+        $mform->setType('questiontextformat', PARAM_INT);
+
         $mform->addElement('hidden', 'id');
         $mform->setType('id', PARAM_INT);
 
@@ -55,9 +58,7 @@ class question_edit_random_form extends question_edit_form {
 
         $buttonarray = array();
         $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        if (!empty($this->question->id)) {
-            $buttonarray[] = &$mform->createElement('submit', 'makecopy', get_string('makecopy', 'quiz'));
-        }
+
         $buttonarray[] = &$mform->createElement('cancel');
         $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
         $mform->closeHeaderBefore('buttonar');