Skip to content

Commit

Permalink
MDL-56646 assign: Don't rescale any negative grades
Browse files Browse the repository at this point in the history
  • Loading branch information
xow authored and John Okely committed Aug 28, 2017
1 parent 64b5209 commit e04be43
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mod/assign/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,8 @@ function assign_rescale_activity_grades($course, $cm, $oldmin, $oldmax, $newmin,
'a' => $cm->instance
);

$sql = 'UPDATE {assign_grades} set grade = (((grade - :p1) * :p2) + :p3) where assignment = :a';
// Only rescale grades that are greater than or equal to 0. Anything else is a special value.
$sql = 'UPDATE {assign_grades} set grade = (((grade - :p1) * :p2) + :p3) where assignment = :a and grade >= 0';
$dbupdate = $DB->execute($sql, $params);
if (!$dbupdate) {
return false;
Expand Down
29 changes: 29 additions & 0 deletions mod/assign/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,4 +655,33 @@ public function test_mod_assign_completion_get_active_rule_descriptions() {
$this->assertEquals(mod_assign_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
$this->assertEquals(mod_assign_get_completion_active_rule_descriptions(new stdClass()), []);
}

/**
* Test that if some grades are not set, they are left alone and not rescaled
*/
public function test_assign_rescale_activity_grades_some_unset() {
$this->resetAfterTest();

// As a teacher...
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();

// Grade the student.
$data = ['grade' => 50];
$assign->testable_apply_grade_to_user((object)$data, $this->students[0]->id, 0);

// Try getting another students grade. This will give a grade of -1.
$assign->get_user_grade($this->students[1]->id, true);

// Rescale.
assign_rescale_activity_grades($this->course, $assign->get_course_module(), 0, 100, 0, 10);

// Get the grades for both students.
$student0grade = $assign->get_user_grade($this->students[0]->id, true);
$student1grade = $assign->get_user_grade($this->students[1]->id, true);

// Make sure the real grade is scaled, but the -1 stays the same.
$this->assertEquals($student0grade->grade, 5);
$this->assertEquals($student1grade->grade, -1);
}
}

0 comments on commit e04be43

Please sign in to comment.