diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 0ce45c0d032..e5d30e9eea2 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -54,6 +54,7 @@ $string['backtoquiz'] = 'Back to quiz editing'; $string['bestgrade'] = 'Best grade'; $string['blackboard'] = 'Blackboard'; $string['blackboard_6'] = 'Blackboard V6+'; +$string['braceerror'] = 'Could not find {...} around answers'; $string['bothattempts'] = 'Show students with and without attempts'; $string['calculated'] = 'Calculated'; $string['calculatedquestion'] = 'Calculated Question not supported at line $a. The question will be ignored'; diff --git a/question/format/gift/format.php b/question/format/gift/format.php index 3ae9e577582..309888d2eaf 100755 --- a/question/format/gift/format.php +++ b/question/format/gift/format.php @@ -165,25 +165,30 @@ class qformat_gift extends qformat_default { // FIND ANSWER section + // no answer means its a description $answerstart = strpos($text, "{"); - if ($answerstart === false) { - $giftleftbraceerror = get_string( 'giftleftbraceerror', 'quiz' ); - $this->error( $giftleftbraceerror, $text ); - return false; - } - $answerfinish = strpos($text, "}"); - if ($answerfinish === false) { - $giftrightbraceerror = get_string( 'giftrightbraceerror', 'quiz' ); - $this->error( $giftrightbraceerror, $text ); + + $description = false; + if (($answerstart === false) and ($answerfinish === false)) { + $description = true; + $answertext = ''; + $answerlength = 0; + } + elseif (!(($answerstart !== false) and ($answerfinish !== false))) { + $this->error( get_string( 'braceerror', 'quiz' ), $text ); return false; } - - $answerlength = $answerfinish - $answerstart; - $answertext = trim(substr($text, $answerstart + 1, $answerlength - 1)); + else { + $answerlength = $answerfinish - $answerstart; + $answertext = trim(substr($text, $answerstart + 1, $answerlength - 1)); + } // Format QUESTION TEXT without answer, inserting "_____" as necessary - if (substr($text, -1) == "}") { + if ($description) { + $questiontext = $text; + } + elseif (substr($text, -1) == "}") { // no blank line if answers follow question, outside of closing punctuation $questiontext = substr_replace($text, "", $answerstart, $answerlength+1); } else { @@ -217,7 +222,13 @@ class qformat_gift extends qformat_default { // determine QUESTION TYPE $question->qtype = NULL; - if ($answertext{0} == "#"){ + if ($description) { + $question->qtype = DESCRIPTION; + } + elseif ($answertext == '') { + $question->qtype = ESSAY; + } + elseif ($answertext{0} == "#"){ $question->qtype = NUMERICAL; } elseif (strpos($answertext, "~") !== false) { @@ -254,6 +265,14 @@ class qformat_gift extends qformat_default { } switch ($question->qtype) { + case DESCRIPTION: + return $question; + break; + case ESSAY: + $question->feedback = ''; + $question->fraction = 0; + return $question; + break; case MULTICHOICE: if (strpos($answertext,"=") === false) { $question->single = 0; // multiple answers are enabled if no single answer is 100% correct @@ -518,6 +537,17 @@ function writequestion( $question ) { // not a real question, used to insert category switch $expout .= "\$CATEGORY: $question->category\n"; break; + case DESCRIPTION: + $expout .= '::'.$this->repchar($question->name).'::'; + $expout .= $tfname; + $expout .= $this->repchar( $question->questiontext, $textformat); + break; + case ESSAY: + $expout .= '::'.$this->repchar($question->name).'::'; + $expout .= $tfname; + $expout .= $this->repchar( $question->questiontext, $textformat); + $expout .= "{}\n"; + break; case TRUEFALSE: $trueanswer = $question->options->answers[$question->options->trueanswer]; $falseanswer = $question->options->answers[$question->options->falseanswer];