MDL-38744 completion: add missing setType and properly allow float
[moodle.git] / completion / criteria / completion_criteria_grade.php
index d0f976b..c7847c5 100644 (file)
@@ -63,12 +63,13 @@ class completion_criteria_grade extends completion_criteria {
     public function config_form_display(&$mform, $data = null) {
         $mform->addElement('checkbox', 'criteria_grade', get_string('enable'));
         $mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
-        $mform->setDefault('criteria_grade_value', $data);
+        $mform->setType('criteria_grade_value', PARAM_RAW); // Uses unformat_float.
+        $mform->setDefault('criteria_grade_value', format_float($data));
         $mform->addElement('static', 'criteria_grade_value_note', '', get_string('criteriagradenote', 'completion'));
 
         if ($this->id) {
             $mform->setDefault('criteria_grade', 1);
-            $mform->setDefault('criteria_grade_value', $this->gradepass);
+            $mform->setDefault('criteria_grade_value', format_float($this->gradepass));
         }
     }
 
@@ -79,11 +80,11 @@ class completion_criteria_grade extends completion_criteria {
      */
     public function update_config(&$data) {
 
+        $formatedgrade = unformat_float($data->criteria_grade_value);
         // TODO validation
-        if (!empty($data->criteria_grade) && is_numeric($data->criteria_grade_value))
-        {
+        if (!empty($formatedgrade) && is_numeric($formatedgrade)) {
             $this->course = $data->id;
-            $this->gradepass = $data->criteria_grade_value;
+            $this->gradepass = $formatedgrade;
             $this->insert();
         }
     }