}
function question_print_comment_fields($question, $state, $prefix, $cmoptions, $caption = '') {
+ global $QTYPES;
$idprefix = preg_replace('/[^-_a-zA-Z0-9]/', '', $prefix);
- $grade = question_format_grade($cmoptions, $state->last_graded->grade);
+ if (!question_state_is_graded($state) && $QTYPES[$question->qtype]->is_question_manual_graded($question, $attempt->layout)) {
+ $grade = '';
+ } else {
+ $grade = question_format_grade($cmoptions, $state->last_graded->grade);
+ }
$maxgrade = question_format_grade($cmoptions, $question->maxgrade);
$fieldsize = strlen($maxgrade) - 1;
if (empty($caption)) {
* @param object $question the question
* @param object $state the state to be updated.
* @param object $attempt the attempt the state belongs to, to be updated.
- * @param string $comment the comment the teacher added
- * @param float $grade the grade the teacher assigned.
+ * @param string $comment the new comment from the teacher.
+ * @param mixed $grade the grade the teacher assigned, or '' to not change the grade.
* @return mixed true on success, a string error message if a problem is detected
* (for example score out of range).
*/
function question_process_comment($question, &$state, &$attempt, $comment, $grade) {
global $DB;
+ $grade = trim($grade);
if ($grade < 0 || $grade > $question->maxgrade) {
$a = new stdClass;
$a->grade = $grade;
}
// Update the attempt if the score has changed.
- if (abs($state->last_graded->grade - $grade) > 0.002) {
+ if ($grade !== '' && (abs($state->last_graded->grade - $grade) > 0.002 || $state->last_graded->event != QUESTION_EVENTMANUALGRADE)) {
$attempt->sumgrades = $attempt->sumgrades - $state->last_graded->grade + $grade;
$attempt->timemodified = time();
if (!$DB->update_record('quiz_attempts', $attempt)) {
return get_string('errorupdatingattempt', 'question', $attempt);
}
- }
-
- // Update the state if either the score has changed, or this is the first
- // manual grade event and there is actually a grade or comment to process.
- // 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 && ($grade > 0.002 || $comment != ''))) {
// We want to update existing state (rather than creating new one) if it
// was itself created by a manual grading event.
- $state->update = ($state->event == QUESTION_EVENTMANUALGRADE) ? 1 : 0;
+ $state->update = $state->event == QUESTION_EVENTMANUALGRADE;
// Update the other parts of the state object.
$state->raw_grade = $grade;