From 93a501c1812110b18de8f50a7823d1f9b83a9d23 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Thu, 30 Nov 2006 08:27:58 +0000 Subject: [PATCH] fix for MDL-7496, incorrect is read almost last, need to be said first --- question/type/shortanswer/display.html | 6 - question/type/shortanswer/questiontype.php | 126 +++++++++++++++++++-- 2 files changed, 114 insertions(+), 18 deletions(-) diff --git a/question/type/shortanswer/display.html b/question/type/shortanswer/display.html index ab9f6a3266..d7f3f38295 100644 --- a/question/type/shortanswer/display.html +++ b/question/type/shortanswer/display.html @@ -21,9 +21,3 @@ print_question_submit_buttons($question, $state, $cmoptions, $options); ?> - - -
- -
- diff --git a/question/type/shortanswer/questiontype.php b/question/type/shortanswer/questiontype.php index 1d03a54806..c18c22d60a 100644 --- a/question/type/shortanswer/questiontype.php +++ b/question/type/shortanswer/questiontype.php @@ -123,7 +123,6 @@ class question_shortanswer_qtype extends default_questiontype { function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { global $CFG; /// This implementation is also used by question type 'numerical' - $correctanswers = $this->get_correct_responses($question, $state); $readonly = empty($options->readonly) ? '' : 'readonly="readonly"'; $formatoptions = new stdClass; $formatoptions->noclean = true; @@ -157,17 +156,8 @@ class question_shortanswer_qtype extends default_questiontype { } } } - - $correctanswer = ''; - if ($options->readonly && $options->correct_responses) { - $delimiter = ''; - if ($correctanswers) { - foreach ($correctanswers as $ca) { - $correctanswer .= $delimiter.$ca; - $delimiter = ', '; - } - } - } + + /// Removed correct answer, to be displayed later MDL-7496 include("$CFG->dirroot/question/type/shortanswer/display.html"); } @@ -314,6 +304,118 @@ class question_shortanswer_qtype extends default_questiontype { return $status; } + + + /** + * Prints the score obtained and maximum score available plus any penalty + * information + * + * This function prints a summary of the scoring in the most recently + * graded state (the question may not have been submitted for marking at + * the current state). The default implementation should be suitable for most + * question types. + * @param object $question The question for which the grading details are + * to be rendered. Question type specific information + * is included. The maximum possible grade is in + * ->maxgrade. + * @param object $state The state. In particular the grading information + * is in ->grade, ->raw_grade and ->penalty. + * @param object $cmoptions + * @param object $options An object describing the rendering options. + */ + function print_question_grading_details(&$question, &$state, $cmoptions, $options) { + /* The default implementation prints the number of marks if no attempt + has been made. Otherwise it displays the grade obtained out of the + maximum grade available and a warning if a penalty was applied for the + attempt and displays the overall grade obtained counting all previous + responses (and penalties) */ + + // MDL-7496 show correct answer after "Incorrect" + $correctanswer = ''; + if ($correctanswers = $this->get_correct_responses($question, $state)) { + if ($options->readonly && $options->correct_responses) { + $delimiter = ''; + if ($correctanswers) { + foreach ($correctanswers as $ca) { + $correctanswer .= $delimiter.$ca; + $delimiter = ', '; + } + } + } + } + + if (QUESTION_EVENTDUPLICATE == $state->event) { + echo ' '; + print_string('duplicateresponse', 'quiz'); + } + if (!empty($question->maxgrade) && $options->scores) { + if (question_state_is_graded($state->last_graded)) { + // Display the grading details from the last graded state + $grade = new stdClass; + $grade->cur = round($state->last_graded->grade, $cmoptions->decimalpoints); + $grade->max = $question->maxgrade; + $grade->raw = round($state->last_graded->raw_grade, $cmoptions->decimalpoints); + + // let student know wether the answer was correct + echo '
'; + print_string('correct', 'quiz'); + } else if ($state->last_graded->raw_grade > 0) { + echo ' partiallycorrect">'; + print_string('partiallycorrect', 'quiz'); + // MDL-7496 + if ($correctanswer) { + echo ('
'); + print_string('correctansweris', 'quiz', s($correctanswer)); + echo ('
'); + } + } else { + echo ' incorrect">'; + // MDL-7496 + print_string('incorrect', 'quiz'); + if ($correctanswer) { + echo ('
'); + print_string('correctansweris', 'quiz', s($correctanswer)); + echo ('
'); + } + } + echo '
'; + + echo '
'; + // print grade for this submission + print_string('gradingdetails', 'quiz', $grade); + if ($cmoptions->penaltyscheme) { + // print details of grade adjustment due to penalties + if ($state->last_graded->raw_grade > $state->last_graded->grade){ + echo ' '; + print_string('gradingdetailsadjustment', 'quiz', $grade); + } + // print info about new penalty + // penalty is relevant only if the answer is not correct and further attempts are possible + if (($state->last_graded->raw_grade < $question->maxgrade) and (QUESTION_EVENTCLOSEANDGRADE !== $state->event)) { + if ('' !== $state->last_graded->penalty && ((float)$state->last_graded->penalty) > 0.0) { + // A penalty was applied so display it + echo ' '; + print_string('gradingdetailspenalty', 'quiz', $state->last_graded->penalty); + } else { + /* No penalty was applied even though the answer was + not correct (eg. a syntax error) so tell the student + that they were not penalised for the attempt */ + echo ' '; + print_string('gradingdetailszeropenalty', 'quiz'); + } + } + } + echo '
'; + } + } + } + + + + + } //// END OF CLASS //// -- 2.39.5