From 3c150de2834cd415a3986bc0fcbda281c1b27c87 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 12 Nov 2019 11:29:34 +0800 Subject: [PATCH] MDL-67218 form: Do not clear grade when rescaling not enabled --- lib/form/modgrade.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/form/modgrade.php b/lib/form/modgrade.php index 863f1b1db49..410bb17b9e7 100644 --- a/lib/form/modgrade.php +++ b/lib/form/modgrade.php @@ -285,10 +285,18 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group { protected function process_value($type='none', $scale=null, $point=null, $rescalegrades=null) { global $COURSE; $val = 0; - if ($this->isupdate && $this->hasgrades && $this->canrescale && $this->currentgradetype == 'point' && empty($rescalegrades)) { - // If the maxgrade field is disabled with javascript, no value is sent with the form and mform assumes the default. + + // If the maxgrade field is disabled with javascript, no value is sent with the form and mform assumes the default. + if ($this->isupdate && $this->hasgrades && $this->currentgradetype == 'point') { + // If the user cannot rescale, then return the original. + $returnoriginal = !$this->canrescale; + // If the user was forced to choose a rescale option - and they haven't - prevent any changes to the max grade. - return (string)unformat_float($this->currentgrade); + $returnoriginal = $returnoriginal || ($this->canrescale && empty($rescalegrades)); + + if ($returnoriginal) { + return (string)unformat_float($this->currentgrade); + } } switch ($type) { case 'point':