mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-48634 grades: Add an option to rescale when changing the maxgrade
This commit is contained in:
parent
9d5d9c64ff
commit
d629c601c5
12 changed files with 422 additions and 11 deletions
|
@ -1315,6 +1315,52 @@ function assign_user_complete($course, $user, $coursemodule, $assign) {
|
|||
echo $assignment->view_student_summary($user, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rescale all grades for this activity and push the new grades to the gradebook.
|
||||
*
|
||||
* @param stdClass $course Course db record
|
||||
* @param stdClass $cm Course module db record
|
||||
* @param float $oldmin
|
||||
* @param float $oldmax
|
||||
* @param float $newmin
|
||||
* @param float $newmax
|
||||
*/
|
||||
function assign_rescale_activity_grades($course, $cm, $oldmin, $oldmax, $newmin, $newmax) {
|
||||
global $DB;
|
||||
|
||||
if ($oldmax <= $oldmin) {
|
||||
// Grades cannot be scaled.
|
||||
return false;
|
||||
}
|
||||
$scale = ($newmax - $newmin) / ($oldmax - $oldmin);
|
||||
if (($newmax - $newmin) <= 1) {
|
||||
// We would lose too much precision, lets bail.
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'p1' => $oldmin,
|
||||
'p2' => $scale,
|
||||
'p3' => $newmin,
|
||||
'a' => $cm->instance
|
||||
);
|
||||
|
||||
$sql = 'UPDATE {assign_grades} set grade = (((grade - :p1) * :p2) + :p3) where assignment = :a';
|
||||
$dbupdate = $DB->execute($sql, $params);
|
||||
if (!$dbupdate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now re-push all grades to the gradebook.
|
||||
$dbparams = array('id' => $cm->instance);
|
||||
$assign = $DB->get_record('assign', $dbparams);
|
||||
$assign->cmidnumber = $cm->idnumber;
|
||||
|
||||
assign_update_grades($assign);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the grade information for the assignment for this user.
|
||||
*
|
||||
|
|
49
mod/assign/tests/behat/rescale_grades.feature
Normal file
49
mod/assign/tests/behat/rescale_grades.feature
Normal file
|
@ -0,0 +1,49 @@
|
|||
@mod @mod_assign
|
||||
Feature: Check that the assignment grade can be rescaled when the max grade is changed
|
||||
In order to ensure that the percentages are not affected by changes to the max grade
|
||||
As a teacher
|
||||
I need to rescale all grades when updating the max grade
|
||||
|
||||
@javascript
|
||||
Scenario: Update the max grade for an assignment and rescale existing grades
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category | groupmode |
|
||||
| Course 1 | C1 | 0 | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student10@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And the following "groups" exist:
|
||||
| name | course | idnumber |
|
||||
| Group 1 | C1 | G1 |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
And I add a "Assignment" to section "1" and I fill the form with:
|
||||
| Assignment name | Test assignment name |
|
||||
| Description | Test assignment description |
|
||||
When I follow "Test assignment name"
|
||||
Then I follow "View/grade all submissions"
|
||||
And I click on "Grade Student 1" "link" in the "Student 1" "table_row"
|
||||
And I set the field "Grade out of 100" to "40"
|
||||
And I press "Save changes"
|
||||
And I press "Continue"
|
||||
And "Student 1" row "Grade" column of "generaltable" table should contain "40.00"
|
||||
And I follow "Edit settings"
|
||||
And I expand all fieldsets
|
||||
And I set the field "Maximum points" to "80"
|
||||
And I press "Save and display"
|
||||
And I follow "View/grade all submissions"
|
||||
And "Student 1" row "Grade" column of "generaltable" table should contain "40.00"
|
||||
And I follow "Edit settings"
|
||||
And I expand all fieldsets
|
||||
And I set the field "Maximum points" to "100"
|
||||
And I set the field "Rescale existing grades" to "Yes"
|
||||
And I press "Save and display"
|
||||
Then I follow "View/grade all submissions"
|
||||
And "Student 1" row "Grade" column of "generaltable" table should contain "50.00"
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue