questions manual grading: MDL-15147 refine the logic for distinguishing '' and 0, so you can grade an essay 0 without making a comment, but also, grade some, but not all student's work in the manual grading report.

This commit is contained in:
tjhunt 2008-12-12 09:00:11 +00:00
parent e285b6a8b6
commit 83f0fef567

View File

@ -1734,8 +1734,13 @@ function get_question_image($question) {
}
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)) {
@ -1776,14 +1781,15 @@ function question_print_comment_fields($question, $state, $prefix, $cmoptions, $
* @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;
@ -1800,24 +1806,16 @@ function question_process_comment($question, &$state, &$attempt, $comment, $grad
}
// 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;