Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-37068_23' of git://github.com/timhunt/moodle into M…

…OODLE_23_STABLE
  • Loading branch information...
commit 52817fdbbcd9508098bf2070a6edf78bb1c1c09e 2 parents 757376d + 18651b0
@samhemelryk samhemelryk authored
View
55 question/format/learnwise/format.php
@@ -42,10 +42,14 @@
*/
class qformat_learnwise extends qformat_default {
- function provide_import() {
+ public function provide_import() {
return true;
}
+ public function export_file_extension() {
+ return '.xml';
+ }
+
protected function readquestions($lines) {
$questions = array();
$currentquestion = array();
@@ -62,9 +66,9 @@ protected function readquestions($lines) {
return $questions;
}
- function readquestion($lines) {
+ protected function readquestion($lines) {
$text = implode(' ', $lines);
- $text = str_replace(array('\t','\n','\r','\''), array('','','','\\\''), $text);
+ $text = str_replace(array('\t','\n','\r'), array('','',''), $text);
$startpos = strpos($text, '<question type');
$endpos = strpos($text, '</question>');
@@ -75,8 +79,8 @@ function readquestion($lines) {
preg_match("/<question type=[\"\']([^\"\']+)[\"\']>/i", $text, $matches);
$type = strtolower($matches[1]); // multichoice or multianswerchoice
- $questiontext = $this->unhtmlentities($this->stringbetween($text, '<text>', '</text>'));
- $questionhint = $this->unhtmlentities($this->stringbetween($text, '<hint>', '</hint>'));
+ $questiontext = textlib::entities_to_utf8($this->stringbetween($text, '<text>', '</text>'));
+ $questionhint = textlib::entities_to_utf8($this->stringbetween($text, '<hint>', '</hint>'));
$questionaward = $this->stringbetween($text, '<award>', '</award>');
$optionlist = $this->stringbetween($text, '<answer>', '</answer>');
@@ -89,10 +93,13 @@ function readquestion($lines) {
if ($type == 'multichoice') {
foreach ($optionlist as $option) {
+ if (trim($option) === '') {
+ continue;
+ }
$correct = $this->stringbetween($option, ' correct="', '">');
$answer = $this->stringbetween($option, '">', '</option>');
$optionscorrect[$n] = $correct;
- $optionstext[$n] = $this->unhtmlentities($answer);
+ $optionstext[$n] = textlib::entities_to_utf8($answer);
++$n;
}
} else if ($type == 'multianswerchoice') {
@@ -102,6 +109,9 @@ function readquestion($lines) {
$optionsaward = array();
foreach ($optionlist as $option) {
+ if (trim($option) === '') {
+ continue;
+ }
preg_match("/correct=\"([^\"]*)\"/i", $option, $correctmatch);
preg_match("/award=\"([^\"]*)\"/i", $option, $awardmatch);
@@ -115,7 +125,7 @@ function readquestion($lines) {
$answer = $this->stringbetween($option, '">', '</option>');
$optionscorrect[$n] = $correct;
- $optionstext[$n] = $this->unhtmlentities($answer);
+ $optionstext[$n] = textlib::entities_to_utf8($answer);
$optionsaward[$n] = $award;
++$n;
}
@@ -127,22 +137,25 @@ function readquestion($lines) {
$question = $this->defaultquestion();
$question->qtype = MULTICHOICE;
$question->name = $this->create_default_question_name($questiontext, get_string('questionname', 'question'));
+ $this->add_blank_combined_feedback($question);
$question->questiontext = $questiontext;
+ $question->questiontextformat = FORMAT_HTML;
$question->single = ($type == 'multichoice') ? 1 : 0;
- $question->feedback[] = '';
$question->fraction = array();
$question->answer = array();
for ($n = 0; $n < count($optionstext); ++$n) {
if ($optionstext[$n]) {
- if (!isset($numcorrect)) { // single answer
+ if (!isset($numcorrect)) {
+ // Single answer.
if ($optionscorrect[$n] == 'yes') {
$fraction = (int) $questionaward;
} else {
$fraction = 0;
}
- } else { // mulitple answers
+ } else {
+ // Multiple answers.
if ($optionscorrect[$n] == 'yes') {
$fraction = $optionsaward[$n] / $totalaward;
} else {
@@ -150,15 +163,22 @@ function readquestion($lines) {
}
}
$question->fraction[] = $fraction;
- $question->answer[] = $optionstext[$n];
- $question->feedback[] = ''; // no feedback in this type
+ $question->answer[] = array('text' => $optionstext[$n], 'format' => FORMAT_HTML);
+ $question->feedback[] = array('text' => '', 'format' => FORMAT_HTML); // No feedback in this type.
}
}
return $question;
}
- function stringbetween($text, $start, $end) {
+ /**
+ * Extract the substring of $text between $start and $end.
+ * @param string $text text to analyse.
+ * @param string $start opening delimiter.
+ * @param string $end closing delimiter.
+ * @return string the requested substring.
+ */
+ protected function stringbetween($text, $start, $end) {
$startpos = strpos($text, $start) + strlen($start);
$endpos = strpos($text, $end);
@@ -166,13 +186,4 @@ function stringbetween($text, $start, $end) {
return substr($text, $startpos, $endpos - $startpos);
}
}
-
- function unhtmlentities($string) {
- $transtable = get_html_translation_table(HTML_ENTITIES);
- $transtable = array_flip($transtable);
- return strtr($string, $transtable);
- }
-
}
-
-
View
2  question/format/learnwise/lang/en/qformat_learnwise.php
@@ -24,4 +24,4 @@
*/
$string['pluginname'] = 'Learnwise format';
-$string['plugidnname_help'] = 'This format enables the import of multiple choice questions saved in Learnwise\'s XML format.';
+$string['pluginname_help'] = 'This format enables the import of multiple choice questions saved in Learnwise\'s XML format.';
Please sign in to comment.
Something went wrong with that request. Please try again.