Merge branch 'MDL-50394_master' of git://github.com/markn86/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 8 Jun 2015 16:32:45 +0000 (18:32 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 8 Jun 2015 16:32:45 +0000 (18:32 +0200)
course/modedit.php
course/moodleform_mod.php

index aaa87e9..4b9edaf 100644 (file)
@@ -262,6 +262,12 @@ if ($mform->is_cancelled()) {
         redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
     }
 } else if ($fromform = $mform->get_data()) {
+    // Convert the grade pass value - we may be using a language which uses commas,
+    // rather than decimal points, in numbers. These need to be converted so that
+    // they can be added to the DB.
+    if (isset($fromform->gradepass)) {
+        $fromform->gradepass = unformat_float($fromform->gradepass);
+    }
 
     if (!empty($fromform->update)) {
         list($cm, $fromform) = update_moduleinfo($cm, $fromform, $course, $mform);
index da113c3..0f7ab3f 100644 (file)
@@ -299,10 +299,19 @@ abstract class moodleform_mod extends moodleform {
             $errors['assessed'] = get_string('scaleselectionrequired', 'rating');
         }
 
+        // Check that the grade pass is a valid number.
+        $gradepassvalid = false;
+        if (isset($data['gradepass'])) {
+            if (unformat_float($data['gradepass'], true) === false) {
+                $errors['gradepass'] = get_string('err_numeric', 'form');
+            } else {
+                $gradepassvalid = true;
+            }
+        }
+
         // Grade to pass: ensure that the grade to pass is valid for points and scales.
         // If we are working with a scale, convert into a positive number for validation.
-
-        if (isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) {
+        if ($gradepassvalid && isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) {
             $scale = !empty($data['grade']) ? $data['grade'] : $data['scale'];
             if ($scale < 0) {
                 $scalevalues = $DB->get_record('scale', array('id' => -$scale));
@@ -672,8 +681,7 @@ abstract class moodleform_mod extends moodleform {
             $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
             $mform->addHelpButton('gradepass', 'gradepass', 'grades');
             $mform->setDefault('gradepass', '');
-            $mform->setType('gradepass', PARAM_FLOAT);
-            $mform->addRule('gradepass', null, 'numeric', null, 'client');
+            $mform->setType('gradepass', PARAM_RAW);
             if (!$this->_features->rating) {
                 $mform->disabledIf('gradepass', 'grade[modgrade_type]', 'eq', 'none');
             }