Skip to content

Commit

Permalink
Extensions for grades and comments from Thomas Robb.
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Jun 12, 2003
1 parent 55513d3 commit 34c84a1
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions mod/quiz/format/missingword.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?PHP // $Id$
/// Modified by Tom Robb 12 June 2003 to include percentage and comment insertion
/// facility.

////////////////////////////////////////////////////////////////////////////
/// MISSING WORD FORMAT
Expand All @@ -13,9 +15,16 @@
/// Each answer is separated with a tilde ~, and the correct answer is
/// prefixed with an equals sign =
///
/// Percentage weights can be included by following the tilde with the
/// desired percent. Comments can be included for each choice by following
/// the comment with a hash mark ("#") and the comment. Example:
///
/// This is {=the best answer#comment on the best answer ~75%a good
/// answer#comment on the good answer ~a wrong one#comment on the bad answer}
///
////////////////////////////////////////////////////////////////////////////

require("default.php");
require("./default.php");

class quiz_file_format extends quiz_default_format {

Expand All @@ -25,7 +34,8 @@ function readquestion($lines) {
/// object suitable for processing and insertion into Moodle.

$question = NULL;

///$comment added by T Robb
$comment = NULL;
$text = implode($lines, " ");

/// Find answer section
Expand Down Expand Up @@ -92,16 +102,48 @@ function readquestion($lines) {
default:
$question->qtype = MULTICHOICE;

#$answers = swapshuffle($answers);
foreach ($answers as $key => $answer) {
$answer = trim($answer);

// Tom's addition starts here
$answeight = 0;
if (strspn($answer,"1234567890%") > 0){
//Make sure that the percent sign is the last in the span
if (strpos($answer,"%") == strspn($answer,"1234567890%")) {
$answeight0 = substr($answer,0,strspn($answer,"1234567890%"));
$answeight = round(($answeight0/100),2);
$answer = substr($answer,(strspn($answer,"1234567890%")));
}
}
if ($answer[0] == "="){
$answeight = 1;
}
//remove the protective underscore for leading numbers in answers
if ($answer[0] == "_"){
$answer = substr($answer, 1);
}
$answer = trim($answer);

if (strpos($answer,"#") > 0){
$hashpos = strpos($answer,"#");
$comment = addslashes(substr(($answer),$hashpos+1));
$answer = substr($answer,0,$hashpos);
} else {
$comment = "";
}
// End of Tom's addition

if ($answer[0] == "=") {
$question->fraction[$key] = 1;
# $question->fraction[$key] = 1;
$question->fraction[$key] = $answeight;
$answer = substr($answer, 1);
} else {
$question->fraction[$key] = 0;
# $question->fraction[$key] = 0;
$question->fraction[$key] = $answeight;
}
$question->answer[$key] = addslashes($answer);
$question->feedback[$key] = "";
$question->feedback[$key] = $comment;
}

$question->defaultgrade = 1;
Expand All @@ -110,7 +152,6 @@ function readquestion($lines) {
return $question;
}
}

}

?>

0 comments on commit 34c84a1

Please sign in to comment.