mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 09:56:38 +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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue