MDL-55360 workshop: Emptying grades to pass should set them to zero
authorDavid Mudrák <david@moodle.com>
Wed, 27 Jul 2016 14:22:12 +0000 (16:22 +0200)
committerDavid Mudrák <david@moodle.com>
Thu, 28 Jul 2016 07:54:43 +0000 (09:54 +0200)
When editing existing workshop with a grade to pass defined, when the
field is emptied, it should be interpreted as setting it to zero. This
was not happening because unformat_float replaces the field with null,
therefore effectively unsetting it.

By casting to float, we interpret all empty values (including null) as
zeros. This behaviour is consistent with how gradebook setup UI works.

mod/workshop/lib.php

index c9f4048..07664a8 100644 (file)
@@ -82,11 +82,11 @@ function workshop_add_instance(stdclass $workshop) {
     $workshop->evaluation            = 'best';
 
     if (isset($workshop->gradinggradepass)) {
-        $workshop->gradinggradepass = unformat_float($workshop->gradinggradepass);
+        $workshop->gradinggradepass = (float)unformat_float($workshop->gradinggradepass);
     }
 
     if (isset($workshop->submissiongradepass)) {
-        $workshop->submissiongradepass = unformat_float($workshop->submissiongradepass);
+        $workshop->submissiongradepass = (float)unformat_float($workshop->submissiongradepass);
     }
 
     if (isset($workshop->submissionfiletypes)) {
@@ -158,11 +158,11 @@ function workshop_update_instance(stdclass $workshop) {
     $workshop->phaseswitchassessment = (int)!empty($workshop->phaseswitchassessment);
 
     if (isset($workshop->gradinggradepass)) {
-        $workshop->gradinggradepass = unformat_float($workshop->gradinggradepass);
+        $workshop->gradinggradepass = (float)unformat_float($workshop->gradinggradepass);
     }
 
     if (isset($workshop->submissiongradepass)) {
-        $workshop->submissiongradepass = unformat_float($workshop->submissiongradepass);
+        $workshop->submissiongradepass = (float)unformat_float($workshop->submissiongradepass);
     }
 
     if (isset($workshop->submissionfiletypes)) {