Permalink
Browse files

MDL-36167: Assignment quickgrading fix when there is no grade (ensure…

… feedback still saves)

This patch modifies the previous on by Luke Tucker so that the lastmodified hidden field
is always added to the quickgrading form even if there is no grade for the assignment. This
ensures that the lastmodified checks still work (to prevent teachers overwriting each
others feedback) and feedback is saved when there is no grade.
  • Loading branch information...
1 parent a13a170 commit 3b7a18f2e5881c8a738f9cd23037bf4c7efd0448 Damyon Wiese committed with danpoltawski Nov 21, 2012
Showing with 20 additions and 13 deletions.
  1. +20 −13 mod/assign/locallib.php
View
@@ -1022,6 +1022,8 @@ public function display_grade($grade, $editing, $userid=0, $modified=0) {
static $scalegrades = array();
+ $o = '';
+
if ($this->get_instance()->grade >= 0) {
// Normal number
if ($editing && $this->get_instance()->grade > 0) {
@@ -1030,17 +1032,20 @@ public function display_grade($grade, $editing, $userid=0, $modified=0) {
} else {
$displaygrade = format_float($grade);
}
- $o = '<label class="accesshide" for="quickgrade_' . $userid . '">' . get_string('usergrade', 'assign') . '</label>';
- $o .= '<input type="text" id="quickgrade_' . $userid . '" name="quickgrade_' . $userid . '" value="' . $displaygrade
- . '" size="6" maxlength="10" class="quickgrade"/>';
+ $o .= '<label class="accesshide" for="quickgrade_' . $userid . '">' . get_string('usergrade', 'assign') . '</label>';
+ $o .= '<input type="text" id="quickgrade_' . $userid . '" name="quickgrade_' . $userid . '" value="' .
+ $displaygrade . '" size="6" maxlength="10" class="quickgrade"/>';
$o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade,2);
$o .= '<input type="hidden" name="grademodified_' . $userid . '" value="' . $modified . '"/>';
return $o;
} else {
+ $o .= '<input type="hidden" name="grademodified_' . $userid . '" value="' . $modified . '"/>';
if ($grade == -1 || $grade === null) {
- return '-';
+ $o .= '-';
+ return $o;
} else {
- return format_float(($grade),2) .'&nbsp;/&nbsp;'. format_float($this->get_instance()->grade,2);
+ $o .= format_float(($grade),2) .'&nbsp;/&nbsp;'. format_float($this->get_instance()->grade,2);
+ return $o;
}
}
@@ -1050,11 +1055,12 @@ public function display_grade($grade, $editing, $userid=0, $modified=0) {
if ($scale = $DB->get_record('scale', array('id'=>-($this->get_instance()->grade)))) {
$this->cache['scale'] = make_menu_from_list($scale->scale);
} else {
- return '-';
+ $o .= '-';
+ return $o;
}
}
if ($editing) {
- $o = '<label class="accesshide" for="quickgrade_' . $userid . '">' . get_string('usergrade', 'assign') . '</label>';
+ $o .= '<label class="accesshide" for="quickgrade_' . $userid . '">' . get_string('usergrade', 'assign') . '</label>';
$o .= '<select name="quickgrade_' . $userid . '" class="quickgrade">';
$o .= '<option value="-1">' . get_string('nograde') . '</option>';
foreach ($this->cache['scale'] as $optionid => $option) {
@@ -1070,9 +1076,11 @@ public function display_grade($grade, $editing, $userid=0, $modified=0) {
} else {
$scaleid = (int)$grade;
if (isset($this->cache['scale'][$scaleid])) {
- return $this->cache['scale'][$scaleid];
+ $o .= $this->cache['scale'][$scaleid];
+ return $o;
}
- return '-';
+ $o .= '-';
+ return $o;
}
}
}
@@ -3448,12 +3456,12 @@ private function process_save_quick_grades() {
// gets a list of possible users and look for values based upon that.
foreach ($participants as $userid => $unused) {
$modified = optional_param('grademodified_' . $userid, -1, PARAM_INT);
- // gather the userid, updated grade and last modified value
+ // Gather the userid, updated grade and last modified value.
$record = new stdClass();
$record->userid = $userid;
$gradevalue = optional_param('quickgrade_' . $userid, '', PARAM_TEXT);
if($modified >= 0) {
- $record->grade = unformat_float(required_param('quickgrade_' . $record->userid, PARAM_TEXT));
+ $record->grade = unformat_float(optional_param('quickgrade_' . $record->userid, -1, PARAM_TEXT));
}
$record->lastmodified = $modified;
$record->gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, array($userid));
@@ -3491,8 +3499,7 @@ private function process_save_quick_grades() {
foreach ($this->feedbackplugins as $plugin) {
if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->supports_quickgrading()) {
if ($plugin->is_quickgrading_modified($modified->userid, $grade)) {
- if ($modified->lastmodified >= 0 &&
- (int)$current->lastmodified > (int)$modified->lastmodified) {
+ if ((int)$current->lastmodified > (int)$modified->lastmodified) {
return get_string('errorrecordmodified', 'assign');
} else {
$modifiedusers[$modified->userid] = $modified;

0 comments on commit 3b7a18f

Please sign in to comment.