MDL-13269 fixed regrading of activity raw grades; merged from MOODLE_19_STABLE

This commit is contained in:
skodak 2008-02-17 16:01:24 +00:00
parent 322a5f6301
commit b45d83916f
3 changed files with 38 additions and 24 deletions

View file

@ -407,6 +407,7 @@
} }
rebuild_course_cache($course->id); rebuild_course_cache($course->id);
grade_regrade_final_grades($course->id);
if (isset($fromform->submitbutton)) { if (isset($fromform->submitbutton)) {
redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule"); redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");

View file

@ -698,7 +698,9 @@ class grade_item extends grade_object {
/** /**
* Given a float grade value or integer grade scale, applies a number of adjustment based on * Given a float grade value or integer grade scale, applies a number of adjustment based on
* grade_item variables and returns the result. * grade_item variables and returns the result.
* @param object $rawgrade The raw grade value. * @param float $rawgrade The raw grade value.
* @param float $rawmin original rawmin
* @param float $rawmax original rawmax
* @return mixed * @return mixed
*/ */
function adjust_raw_grade($rawgrade, $rawmin, $rawmax) { function adjust_raw_grade($rawgrade, $rawmin, $rawmax) {
@ -718,7 +720,7 @@ class grade_item extends grade_object {
// Standardise score to the new grade range // Standardise score to the new grade range
// NOTE: this is not compatible with current assignment grading // NOTE: this is not compatible with current assignment grading
if ($rawmin != $this->grademin or $rawmax != $this->grademax) { if ($this->itemmodule != 'assignment' and ($rawmin != $this->grademin or $rawmax != $this->grademax)) {
$rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax); $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax);
} }
@ -743,7 +745,7 @@ class grade_item extends grade_object {
// Convert scale if needed // Convert scale if needed
// NOTE: this is not compatible with current assignment grading // NOTE: this is not compatible with current assignment grading
if ($rawmin != $this->grademin or $rawmax != $this->grademax) { if ($this->itemmodule != 'assignment' and ($rawmin != $this->grademin or $rawmax != $this->grademax)) {
$rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax); $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax);
} }
@ -1406,14 +1408,14 @@ class grade_item extends grade_object {
$this->force_regrading(); $this->force_regrading();
} else if ($this->is_course_item() and !$this->needsupdate) { } else if ($this->is_course_item() and !$this->needsupdate) {
if (!grade_regrade_final_grades($this->courseid, $userid, $this)) { if (grade_regrade_final_grades($this->courseid, $userid, $this) !== true) {
$this->force_regrading(); $this->force_regrading();
} }
} else if (!$this->needsupdate) { } else if (!$this->needsupdate) {
$course_item = grade_item::fetch_course_item($this->courseid); $course_item = grade_item::fetch_course_item($this->courseid);
if (!$course_item->needsupdate) { if (!$course_item->needsupdate) {
if (!grade_regrade_final_grades($this->courseid, $userid, $this)) { if (grade_regrade_final_grades($this->courseid, $userid, $this) !== true) {
$this->force_regrading(); $this->force_regrading();
} }
} else { } else {
@ -1483,27 +1485,24 @@ class grade_item extends grade_object {
} }
// we need proper floats here for !== comparison later // we need proper floats here for !== comparison later
if (!is_null($grade->rawgrade)) {
$grade->rawgrade = (float)$grade->rawgrade;
}
$oldgrade = new object(); $oldgrade = new object();
$oldgrade->finalgrade = $grade->finalgrade; $oldgrade->finalgrade = grade_floatval($grade->finalgrade);
$oldgrade->rawgrade = $grade->rawgrade; $oldgrade->rawgrade = grade_floatval($grade->rawgrade);
$oldgrade->rawgrademin = $grade->rawgrademin; $oldgrade->rawgrademin = grade_floatval($grade->rawgrademin);
$oldgrade->rawgrademax = $grade->rawgrademax; $oldgrade->rawgrademax = grade_floatval($grade->rawgrademax);
$oldgrade->rawscaleid = $grade->rawscaleid; $oldgrade->rawscaleid = grade_floatval($grade->rawscaleid);
$oldgrade->feedback = $grade->feedback; $oldgrade->feedback = $grade->feedback;
$oldgrade->feedbackformat = $grade->feedbackformat; $oldgrade->feedbackformat = $grade->feedbackformat;
// fist copy current grademin/max and scale // use new min and max
$grade->rawgrademin = $this->grademin; $grade->rawgrade = grade_floatval($grade->rawgrade);
$grade->rawgrademax = $this->grademax; $grade->rawgrademin = grade_floatval($this->grademin);
$grade->rawscaleid = $this->scaleid; $grade->rawgrademax = grade_floatval($this->grademax);
$grade->rawscaleid = grade_floatval($this->scaleid);
// change raw grade? // change raw grade?
if ($rawgrade !== false) { if ($rawgrade !== false) {
$grade->rawgrade = $rawgrade; $grade->rawgrade = grade_floatval($rawgrade);
} }
// do we have comment from teacher? // do we have comment from teacher?
@ -1512,6 +1511,11 @@ class grade_item extends grade_object {
$grade->feedbackformat = $feedbackformat; $grade->feedbackformat = $feedbackformat;
} }
// update final grade if possible
if (!$grade->is_locked() and !$grade->is_overridden()) {
$grade->finalgrade = grade_floatval($this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax));
}
if (is_null($grade->rawgrade)) { if (is_null($grade->rawgrade)) {
$grade->timemodified = null; // dategraded hack - not graded if no grade present, comments do not count here as grading $grade->timemodified = null; // dategraded hack - not graded if no grade present, comments do not count here as grading
} }
@ -1536,11 +1540,9 @@ class grade_item extends grade_object {
} else if (!$this->needsupdate) { } else if (!$this->needsupdate) {
$course_item = grade_item::fetch_course_item($this->courseid); $course_item = grade_item::fetch_course_item($this->courseid);
if (!$course_item->needsupdate) { if (!$course_item->needsupdate) {
if (!grade_regrade_final_grades($this->courseid, $userid, $this)) { if (grade_regrade_final_grades($this->courseid, $userid, $this) !== true) {
$this->force_regrading(); $this->force_regrading();
} }
} else {
$this->force_regrading();
} }
} }

View file

@ -768,7 +768,7 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null)
} }
if ($course_item->needsupdate) { if ($course_item->needsupdate) {
$updated_item->force_regrading(); $updated_item->force_regrading();
return 'Can not do fast regrading after updating of raw grades'; return array($course_item->id =>'Can not do fast regrading after updating of raw grades');
} }
} else { } else {
@ -1243,4 +1243,15 @@ function grade_course_reset($courseid) {
return true; return true;
} }
/**
* Convert number to float or null
* @param mixed number
* @return mixed float or null
*/
function grade_floatval($number) {
if (is_null($number)) {
return null;
}
return (float)$number;
}
?> ?>