Skip to content

Commit

Permalink
MDL-32913 core_grade:made it more obvious when the gradebook is broke…
Browse files Browse the repository at this point in the history
…n due to a broken calculation
  • Loading branch information
andyjdavis committed May 2, 2013
1 parent 5f8a427 commit 459843d
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions grade/export/lib.php
Expand Up @@ -427,3 +427,13 @@ public function close() {
}
}

/**
* Verify that there is a valid set of grades to export.
* @param $courseid int The course being exported
*/
function export_verify_grades($courseid) {
$regraderesult = grade_regrade_final_grades($courseid);
if (is_array($regraderesult)) {
throw new moodle_exception('gradecantregrade', 'error', '', implode(',', $regraderesult));
}
}
1 change: 1 addition & 0 deletions grade/export/ods/index.php
Expand Up @@ -34,6 +34,7 @@
require_capability('gradeexport/ods:view', $context);

print_grade_page_head($COURSE->id, 'export', 'ods', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_ods'));
export_verify_grades($COURSE->id);

if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/ods:publish', $context);
Expand Down
1 change: 1 addition & 0 deletions grade/export/txt/index.php
Expand Up @@ -34,6 +34,7 @@
require_capability('gradeexport/txt:view', $context);

print_grade_page_head($COURSE->id, 'export', 'txt', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_txt'));
export_verify_grades($COURSE->id);

if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/txt:publish', $context);
Expand Down
1 change: 1 addition & 0 deletions grade/export/xls/index.php
Expand Up @@ -34,6 +34,7 @@
require_capability('gradeexport/xls:view', $context);

print_grade_page_head($COURSE->id, 'export', 'xls', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_xls'));
export_verify_grades($COURSE->id);

if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/xls:publish', $context);
Expand Down
1 change: 1 addition & 0 deletions grade/export/xml/index.php
Expand Up @@ -34,6 +34,7 @@
require_capability('gradeexport/xml:view', $context);

print_grade_page_head($COURSE->id, 'export', 'xml', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_xml'));
export_verify_grades($COURSE->id);

if (!empty($CFG->gradepublishing)) {
$CFG->gradepublishing = has_capability('gradeexport/xml:publish', $context);
Expand Down
5 changes: 4 additions & 1 deletion grade/lib.php
Expand Up @@ -134,7 +134,10 @@ public function init() {

$this->close();

grade_regrade_final_grades($this->course->id);
$regraderesult = grade_regrade_final_grades($this->course->id);
if (is_array($regraderesult)) {
throw new moodle_exception('gradecantregrade', 'error', '', implode(',', $regraderesult));
}
$course_item = grade_item::fetch_course_item($this->course->id);
if ($course_item->needsupdate) {
// can not calculate all final grades - sorry
Expand Down
1 change: 1 addition & 0 deletions lang/en/error.php
Expand Up @@ -244,6 +244,7 @@
$string['forumblockingtoomanyposts'] = 'You have exceeded the posting threshold set for this forum';
$string['generalexceptionmessage'] = 'Exception - {$a}';
$string['gradepubdisable'] = 'Grade publishing disabled';
$string['gradecantregrade'] = 'An error occurred during grade calculation: {$a}';
$string['groupalready'] = 'User already belongs to group {$a}';
$string['groupexistforcourse'] = 'Group "{$a}" already exists for this course';
$string['groupexistforcoursewithidnumber'] = '{$a->problemgroup}: Group "{$a->name}" with an idnumber of "{$a->idnumber}" already exists for this course';
Expand Down
1 change: 1 addition & 0 deletions lang/en/grades.php
Expand Up @@ -173,6 +173,7 @@
$string['encoding'] = 'Encoding';
$string['errorcalculationnoequal'] = 'Formula must start with equal sign (=1+2)';
$string['errorcalculationunknown'] = 'Invalid formula';
$string['errorcalculationbroken'] = 'Probably circular reference or broken calculation formula';
$string['errorgradevaluenonnumeric'] = 'Received non-numeric for low or high grade for';
$string['errornocalculationallowed'] = 'Calculations are not allowed for this item';
$string['errornocategorisedid'] = 'Could not get an uncategorised id!';
Expand Down
4 changes: 2 additions & 2 deletions lib/gradelib.php
Expand Up @@ -1097,9 +1097,9 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null)
continue; // this one is ok
}
$grade_items[$gid]->force_regrading();
$errors[$grade_items[$gid]->id] = 'Probably circular reference or broken calculation formula'; // TODO: localize
$errors[$grade_items[$gid]->id] = get_string('errorcalculationbroken', 'grades');
}
break; // oki, found error
break; // Found error.
}
}

Expand Down

0 comments on commit 459843d

Please sign in to comment.