From e8825e724bf6f916752a067c9be983295729ed4f Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Sat, 21 Jul 2007 07:39:22 +0000 Subject: [PATCH] MDL-10531: GIFT now handles Essay and Description type questions. See help/docs. Merged from STABLE_18 --- question/format/gift/format.php | 58 +++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/question/format/gift/format.php b/question/format/gift/format.php index bee1ed6a0c..b13e403daa 100755 --- a/question/format/gift/format.php +++ b/question/format/gift/format.php @@ -168,25 +168,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 { @@ -220,7 +225,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) { @@ -257,6 +268,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 @@ -521,6 +540,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]; -- 2.39.5