Skip to content

Commit

Permalink
MDL-36167: Assignment quickgrading fix when there is no grade (ensure…
Browse files Browse the repository at this point in the history
… 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
Damyon Wiese authored and danpoltawski committed Dec 10, 2012
1 parent a13a170 commit 3b7a18f
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions mod/assign/locallib.php
Expand Up @@ -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) {
Expand All @@ -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;
}
}

Expand All @@ -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) {
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3b7a18f

Please sign in to comment.