Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-6315 - Manually grading a question 0 marks was not being register…

…ed. I took the opportunity to clean up the logic in this function a bit.
  • Loading branch information...
commit 24fcdd14c0976998ddf559ea776f64a212991a83 1 parent dd08b0d
tjhunt authored
Showing with 15 additions and 9 deletions.
  1. +15 −9 lib/questionlib.php
View
24 lib/questionlib.php
@@ -1144,33 +1144,39 @@ function question_process_comment($question, &$state, &$attempt, $comment, $grad
if (!set_field('question_sessions', 'comment', $comment, 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
error("Cannot save comment");
}
- // If the teacher has changed the grade then update the attempt and the state
- // The modified attempt is stored to the database, the state not yet but the
- // $state->changed flag is set
+
+ // Update the attempt if the score has changed.
if (abs($state->last_graded->grade - $grade) > 0.002) {
- // the teacher has changed the grade
$attempt->sumgrades = $attempt->sumgrades - $state->last_graded->grade + $grade;
$attempt->timemodified = time();
if (!update_record('quiz_attempts', $attempt)) {
error('Failed to save the current quiz attempt!');
}
+ }
+ // Update the state if either the score has changed, or this is the first
+ // manual grade event.
+ // We don't need to store the modified state in the database, we just need
+ // to set the $state->changed flag.
+ if (abs($state->last_graded->grade - $grade) > 0.002 ||
+ $state->last_graded->event != QUESTION_EVENTMANUALGRADE) {
$state->raw_grade = $grade;
$state->grade = $grade;
$state->penalty = 0;
$state->timestamp = time();
$state->seq_number++;
- // We need to indicate that the state has changed in order for it to be saved
- $state->changed = 1;
+ $state->event = QUESTION_EVENTMANUALGRADE;
+
// We want to update existing state (rather than creating new one) if it
- // was itself created by a manual grading event
+ // was itself created by a manual grading event.
$state->update = ($state->event == QUESTION_EVENTMANUALGRADE) ? 1 : 0;
- $state->event = QUESTION_EVENTMANUALGRADE;
// Update the last graded state (don't simplify!)
unset($state->last_graded);
$state->last_graded = clone($state);
- unset($state->last_graded->changed);
+
+ // We need to indicate that the state has changed in order for it to be saved.
+ $state->changed = 1;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.