]> git.mjollnir.org Git - moodle.git/commitdiff
quiz settings: MDL-18583 When a quiz has no grade, make it clear that you can only...
authortjhunt <tjhunt>
Wed, 18 Mar 2009 07:33:56 +0000 (07:33 +0000)
committertjhunt <tjhunt>
Wed, 18 Mar 2009 07:33:56 +0000 (07:33 +0000)
When the maximum grade for the quiz is 0, we disable all the overall feedback form controls except for the first, and display an explanitory message.

lang/en_utf8/quiz.php
mod/quiz/lib.php
mod/quiz/mod_form.php

index 84316f9595157f713a013e7c252d27d27445efd1..2b1ddfff4e33f73303a17f5641c146a54adb1456 100644 (file)
@@ -446,6 +446,7 @@ $string['noconnection'] = 'There is currently no connection to a web service tha
 $string['nodataset'] = 'nothing - it is not a wild card';
 $string['nodatasubmitted'] = 'No data was submitted.';
 $string['noessayquestionsfound'] = 'No manually graded questions found';
+$string['nogradewarning'] = 'This quiz is not graded, so you cannot set overall feedback that differs by grade.';
 $string['nomatchinganswer'] = 'You must specify an answer matching the question \'$a\'.';
 $string['nominal'] = 'Nominal';
 $string['nomoreattempts'] = 'No more attempts are allowed';
index 24e7a97f7dfd83353393c4b3b3d80df8cfa96976..981134c1c4ebf9c248a71bb972a2e864196969b5 100644 (file)
@@ -827,9 +827,11 @@ function quiz_process_options(&$quiz) {
         $numboundaries = $i;
 
         // Check there is nothing in the remaining unused fields.
-        for ($i = $numboundaries; $i < count($quiz->feedbackboundaries); $i += 1) {
-            if (!empty($quiz->feedbackboundaries[$i]) && trim($quiz->feedbackboundaries[$i]) != '') {
-                return get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
+        if (!empty($quiz->feedbackboundaries)) {
+            for ($i = $numboundaries; $i < count($quiz->feedbackboundaries); $i += 1) {
+                if (!empty($quiz->feedbackboundaries[$i]) && trim($quiz->feedbackboundaries[$i]) != '') {
+                    return get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
+                }
             }
         }
         for ($i = $numboundaries + 1; $i < count($quiz->feedbacktext); $i += 1) {
index 8779599eba41ba903e37ea7de4a18c6f8a719068..20f9649a62b18063de6c3ae815bdad1e04b12234 100644 (file)
@@ -88,8 +88,6 @@ class mod_quiz_mod_form extends moodleform_mod {
         $mform->setDefault('grademethod', $quizconfig->grademethod);
         $mform->disabledIf('grademethod', 'attempts', 'eq', 1);
 
-        $mform->addElement('hidden', 'grade', $quizconfig->maximumgrade);
-
 //-------------------------------------------------------------------------------
         $mform->addElement('header', 'layouthdr', get_string('layout', 'quiz'));
 
@@ -274,11 +272,23 @@ class mod_quiz_mod_form extends moodleform_mod {
         $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz'));
         $mform->setHelpButton('overallfeedbackhdr', array('overallfeedback', get_string('overallfeedback', 'quiz'), 'quiz'));
 
+        $mform->addElement('hidden', 'grade', $quizconfig->maximumgrade);
+        if (empty($this->_cm)) {
+            $needwarning = $quizconfig->maximumgrade == 0;
+        } else {
+            $needwarning = $DB->get_field('quiz', 'grade', array('id' => $this->_instance));
+        }
+        if ($needwarning) {
+            $mform->addElement('static', 'nogradewarning', '', get_string('nogradewarning', 'quiz'));
+        }
+
         $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%');
 
-        $repeatarray=array();
+        $repeatarray = array();
         $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbacktext', get_string('feedback', 'quiz'), array('size' => 50));
+        $mform->setType('feedbacktext', PARAM_RAW);
         $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10));
+        $mform->setType('feedbackboundaries', PARAM_NOTAGS);
 
         if (!empty($this->_instance)) {
             $this->_feedbacks = $DB->get_records('quiz_feedback', array('quizid'=>$this->_instance), 'mingrade DESC');
@@ -287,20 +297,24 @@ class mod_quiz_mod_form extends moodleform_mod {
         }
         $numfeedbacks = max(count($this->_feedbacks) * 1.5, 5);
 
-        $mform->setType('feedbacktext', PARAM_RAW);
-        $mform->setType('feedbackboundaries', PARAM_NOTAGS);
-
         $nextel=$this->repeat_elements($repeatarray, $numfeedbacks - 1,
                 array(), 'boundary_repeats', 'boundary_add_fields', 3,
                 get_string('addmoreoverallfeedbacks', 'quiz'), true);
 
-        //put some extra elements in before the button
+        // Put some extra elements in before the button
         $insertEl = &MoodleQuickForm::createElement('text', "feedbacktext[$nextel]", get_string('feedback', 'quiz'), array('size' => 50));
         $mform->insertElementBefore($insertEl, 'boundary_add_fields');
 
         $insertEl = &MoodleQuickForm::createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%');
         $mform->insertElementBefore($insertEl, 'boundary_add_fields');
 
+        // Add the disabledif rules. We cannot do this using the $repeatoptions parameter to
+        // repeat_elements becuase we don't want to dissable the first feedbacktext.
+        for ($i = 0; $i < $nextel; $i++) {
+            $mform->disabledIf('feedbackboundaries[' . $i . ']', 'grade', 'eq', 0);
+            $mform->disabledIf('feedbacktext[' . ($i + 1) . ']', 'grade', 'eq', 0);
+        }
+
 //-------------------------------------------------------------------------------
         $features = new stdClass;
         $features->groups = true;
@@ -314,6 +328,10 @@ class mod_quiz_mod_form extends moodleform_mod {
     }
 
     function data_preprocessing(&$default_values){
+        if (isset($default_values['grade'])) {
+            $default_values['grade'] = $default_values['grade'] + 0; // Convert to a real number, so we don't get 0.0000.
+        }
+
         if (count($this->_feedbacks)) {
             $key = 0;
             foreach ($this->_feedbacks as $feedback){
@@ -400,12 +418,14 @@ class mod_quiz_mod_form extends moodleform_mod {
         $numboundaries = $i;
 
         // Check there is nothing in the remaining unused fields.
-        for ($i = $numboundaries; $i < count($data['feedbackboundaries'] ); $i += 1) {
-            if (!empty($data['feedbackboundaries'][$i] ) && trim($data['feedbackboundaries'][$i] ) != '') {
-                $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
+        if (!empty($data['feedbackboundaries'])) {
+            for ($i = $numboundaries; $i < count($data['feedbackboundaries']); $i += 1) {
+                if (!empty($data['feedbackboundaries'][$i] ) && trim($data['feedbackboundaries'][$i] ) != '') {
+                    $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
+                }
             }
         }
-        for ($i = $numboundaries + 1; $i < count($data['feedbacktext'] ); $i += 1) {
+        for ($i = $numboundaries + 1; $i < count($data['feedbacktext']); $i += 1) {
             if (!empty($data['feedbacktext'][$i] ) && trim($data['feedbacktext'][$i] ) != '') {
                 $errors["feedbacktext[$i]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
             }