Skip to content

Commit

Permalink
MDL-13269 fixed regrading of activity raw grades
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Feb 17, 2008
1 parent 44ceee9 commit d29877a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
3 changes: 2 additions & 1 deletion course/modedit.php
Expand Up @@ -407,7 +407,8 @@
}

rebuild_course_cache($course->id);

grade_regrade_final_grades($course->id);

if (isset($fromform->submitbutton)) {
redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
} else {
Expand Down
46 changes: 24 additions & 22 deletions lib/grade/grade_item.php
Expand Up @@ -698,7 +698,9 @@ function regrade_final_grades($userid=null) {
/**
* Given a float grade value or integer grade scale, applies a number of adjustment based on
* 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
*/
function adjust_raw_grade($rawgrade, $rawmin, $rawmax) {
Expand All @@ -718,7 +720,7 @@ function adjust_raw_grade($rawgrade, $rawmin, $rawmax) {

// Standardise score to the new grade range
// 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);
}

Expand All @@ -743,7 +745,7 @@ function adjust_raw_grade($rawgrade, $rawmin, $rawmax) {

// Convert scale if needed
// 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);
}

Expand Down Expand Up @@ -1406,14 +1408,14 @@ function update_final_grade($userid, $finalgrade=false, $source=NULL, $feedback=
$this->force_regrading();

} 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();
}

} else if (!$this->needsupdate) {
$course_item = grade_item::fetch_course_item($this->courseid);
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();
}
} else {
Expand Down Expand Up @@ -1483,27 +1485,24 @@ function update_raw_grade($userid, $rawgrade=false, $source=NULL, $feedback=fals
}

// we need proper floats here for !== comparison later
if (!is_null($grade->rawgrade)) {
$grade->rawgrade = (float)$grade->rawgrade;
}

$oldgrade = new object();
$oldgrade->finalgrade = $grade->finalgrade;
$oldgrade->rawgrade = $grade->rawgrade;
$oldgrade->rawgrademin = $grade->rawgrademin;
$oldgrade->rawgrademax = $grade->rawgrademax;
$oldgrade->rawscaleid = $grade->rawscaleid;
$oldgrade->finalgrade = grade_floatval($grade->finalgrade);
$oldgrade->rawgrade = grade_floatval($grade->rawgrade);
$oldgrade->rawgrademin = grade_floatval($grade->rawgrademin);
$oldgrade->rawgrademax = grade_floatval($grade->rawgrademax);
$oldgrade->rawscaleid = grade_floatval($grade->rawscaleid);
$oldgrade->feedback = $grade->feedback;
$oldgrade->feedbackformat = $grade->feedbackformat;

// fist copy current grademin/max and scale
$grade->rawgrademin = $this->grademin;
$grade->rawgrademax = $this->grademax;
$grade->rawscaleid = $this->scaleid;
// use new min and max
$grade->rawgrade = grade_floatval($grade->rawgrade);
$grade->rawgrademin = grade_floatval($this->grademin);
$grade->rawgrademax = grade_floatval($this->grademax);
$grade->rawscaleid = grade_floatval($this->scaleid);

// change raw grade?
if ($rawgrade !== false) {
$grade->rawgrade = $rawgrade;
$grade->rawgrade = grade_floatval($rawgrade);
}

// do we have comment from teacher?
Expand All @@ -1512,6 +1511,11 @@ function update_raw_grade($userid, $rawgrade=false, $source=NULL, $feedback=fals
$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)) {
$grade->timemodified = null; // dategraded hack - not graded if no grade present, comments do not count here as grading
}
Expand All @@ -1536,11 +1540,9 @@ function update_raw_grade($userid, $rawgrade=false, $source=NULL, $feedback=fals
} else if (!$this->needsupdate) {
$course_item = grade_item::fetch_course_item($this->courseid);
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();
}
} else {
$this->force_regrading();
}
}

Expand Down
13 changes: 12 additions & 1 deletion lib/gradelib.php
Expand Up @@ -768,7 +768,7 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null)
}
if ($course_item->needsupdate) {
$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 {
Expand Down Expand Up @@ -1243,4 +1243,15 @@ function grade_course_reset($courseid) {
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;
}
?>

0 comments on commit d29877a

Please sign in to comment.