mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 14:03:52 +01:00
MDL-56646 assign: Don't rescale any negative grades
This commit is contained in:
parent
64b52095e5
commit
e04be435e0
@ -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;
|
||||
|
@ -655,4 +655,33 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user