Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made it possble to give negative grades for single multichoice answer…

…s in a question with embedded answers, as suggested by Koen Roggemans. The total score of the whole question must still be greater than or equeal to zero.
  • Loading branch information...
commit 7c9c2a8da68f420a8fa04ae1a90493a1dbe4f633 1 parent cc652b4
kaipe authored
Showing with 12 additions and 7 deletions.
  1. +1 −1  mod/quiz/format/multianswer.php
  2. +11 −6 mod/quiz/lib.php
View
2  mod/quiz/format/multianswer.php
@@ -17,7 +17,7 @@
// ANSWER_ALTERNATIVE regexes
define("ANSWER_ALTERNATIVE_FRACTION_REGEX",
- '=|%([0-9]+)%');
+ '=|%(-?[0-9]+)%');
define("ANSWER_ALTERNATIVE_ANSWER_REGEX",
'[^~#}]+');
define("ANSWER_ALTERNATIVE_FEEDBACK_REGEX",
View
17 mod/quiz/lib.php
@@ -819,10 +819,10 @@ function quiz_print_question($number, $question, $grade, $quizid,
$inputname= " name=\"q{$realquestion->id}ma$multianswer->id\" ";
if (!empty($response)
- && $responseitems = explode('-', array_shift($response), 2))
+ && ereg('(.[^-]*)-(.+)', array_shift($response), $responseitems))
{
- $responsefractiongrade = (float)$responseitems[0];
- $actualresponse = $responseitems[1];
+ $responsefractiongrade = (float)$responseitems[1];
+ $actualresponse = $responseitems[2];
if (1.0 == $responsefractiongrade) {
$style = 'style="background-color:lime"';
@@ -1593,7 +1593,10 @@ function quiz_save_attempt($quiz, $questions, $result, $attemptnum) {
return true;
}
-function quiz_grade_attempt_question_result($question, $answers) {
+function quiz_grade_attempt_question_result($question,
+ $answers,
+ $gradecanbenegative= false)
+{
$grade = 0; // default
$correct = array();
$feedback = array();
@@ -1767,7 +1770,7 @@ function quiz_grade_attempt_question_result($question, $answers) {
$subquestion->qtype = $multianswer->answertype;
$subquestion->grade = $multianswer->norm;
$subresult = quiz_grade_attempt_question_result
- ($subquestion, $multianswer->subanswers);
+ ($subquestion, $multianswer->subanswers, true);
break;
}
}
@@ -1797,7 +1800,9 @@ function quiz_grade_attempt_question_result($question, $answers) {
return quiz_grade_attempt_question_result($realquestion, $answers);
}
- $result->grade = max(0.0, $grade); // No negative grades
+ $result->grade =
+ $gradecanbenegative ? $grade // Grade can be negative
+ : max(0.0, $grade); // Grade must not be negative
$result->correct = $correct;
$result->feedback = $feedback;
$result->response = $response;
Please sign in to comment.
Something went wrong with that request. Please try again.