Skip to content

Commit

Permalink
MDL-43071 assign: Fix offline grades import for scale grading.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Nov 26, 2013
1 parent 20776b4 commit 3bc1bd6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 9 additions & 5 deletions mod/assign/feedback/offline/importgradesform.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ public function definition() {

$scaleoptions = null;
if ($assignment->get_instance()->grade < 0) {
$scale = $DB->get_record('scale', array('id'=>-($assignment->get_instance()->grade)));
if ($scale) {
$scaleoptions = explode(',', $scale->scale);
if ($scale = $DB->get_record('scale', array('id'=>-($assignment->get_instance()->grade)))) {
$scaleoptions = make_menu_from_list($scale->scale);
}
}
if (!$gradeimporter->init()) {
Expand Down Expand Up @@ -104,7 +103,7 @@ public function definition() {
// This is a scale - we need to convert any grades to indexes in the scale.
$scaleindex = array_search($grade, $scaleoptions);
if ($scaleindex !== false) {
$grade = $scaleindex + 1;
$grade = $scaleindex;
} else {
$grade = '';
}
Expand Down Expand Up @@ -132,8 +131,13 @@ public function definition() {

if (!$skip) {
$update = true;
if (!empty($scaleoptions)) {
$formattedgrade = $scaleoptions[$grade];
} else {
$formattedgrade = format_float($grade, 2);
}
$updates[] = get_string('gradeupdate', 'assignfeedback_offline',
array('grade'=>format_float($grade, 2), 'student'=>$userdesc));
array('grade'=>$formattedgrade, 'student'=>$userdesc));
}

if ($ignoremodified || !$stalemodificationdate) {
Expand Down
7 changes: 3 additions & 4 deletions mod/assign/feedback/offline/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ public function process_import_grades($draftid, $importid, $ignoremodified) {
// Does this assignment use a scale?
$scaleoptions = null;
if ($this->assignment->get_instance()->grade < 0) {
$scale = $DB->get_record('scale', array('id'=>-($this->assignment->get_instance()->grade)));
if ($scale) {
$scaleoptions = explode(',', $scale->scale);
if ($scale = $DB->get_record('scale', array('id'=>-($this->assignment->get_instance()->grade)))) {
$scaleoptions = make_menu_from_list($scale->scale);
}
}
// We may need to upgrade the gradebook comments after this update.
Expand All @@ -127,7 +126,7 @@ public function process_import_grades($draftid, $importid, $ignoremodified) {
// This is a scale - we need to convert any grades to indexes in the scale.
$scaleindex = array_search($record->grade, $scaleoptions);
if ($scaleindex !== false) {
$record->grade = $scaleindex + 1;
$record->grade = $scaleindex;
} else {
$record->grade = '';
}
Expand Down

0 comments on commit 3bc1bd6

Please sign in to comment.