Skip to content

Commit

Permalink
MDL-55520 forms: Mod grade is changing values back to default
Browse files Browse the repository at this point in the history
When a field is disabled in the page - no value is sent and modgrade is reverting
to the default. This change prevents the max grade from changing accidentally.
  • Loading branch information
Damyon Wiese committed Aug 11, 2016
1 parent 56394c8 commit 6037304
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/form/modgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ public function exportValue(&$submitvalues, $notused = false) {
$point = (isset($vals['modgrade_point'])) ? $vals['modgrade_point'] : null;
$scale = (isset($vals['modgrade_scale'])) ? $vals['modgrade_scale'] : null;
$rescalegrades = (isset($vals['modgrade_rescalegrades'])) ? $vals['modgrade_rescalegrades'] : null;
$return = $this->process_value($type, $scale, $point);

$return = $this->process_value($type, $scale, $point, $rescalegrades);
return array($this->getName() => $return, $this->getName() . '_rescalegrades' => $rescalegrades);
}

Expand All @@ -276,11 +277,17 @@ public function exportValue(&$submitvalues, $notused = false) {
* @param string $type The value of the grade type select box. Can be 'none', 'scale', or 'point'
* @param string|int $scale The value of the scale select box.
* @param string|int $point The value of the point grade textbox.
* @param string $rescalegrades The value of the rescalegrades select.
* @return int The resulting value
*/
protected function process_value($type='none', $scale=null, $point=null) {
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 user was forced to choose a rescale option - and they haven't - prevent any changes to the max grade.
return $this->currentgrade;
}
switch ($type) {
case 'point':
if ($this->validate_point($point) === true) {
Expand Down

0 comments on commit 6037304

Please sign in to comment.