Permalink
Browse files

MDL-35147 lesson: fix regression from MDL-25492.

I really wish someone would fix lesson to use the question bank.
  • Loading branch information...
1 parent 21415ac commit 5fe6d4124558772a9c8f79b75c43182d78c70352 @timhunt timhunt committed Aug 30, 2012
Showing with 87 additions and 0 deletions.
  1. +87 −0 mod/lesson/format.php
View
87 mod/lesson/format.php
@@ -580,6 +580,93 @@ protected function format_question_text($question) {
return html_to_text(format_text($question->questiontext,
$question->questiontextformat, $formatoptions), 0, false);
}
+
+ /**
+ * Since the lesson module tries to re-use the question bank import classes in
+ * a crazy way, this is necessary to stop things breaking.
+ */
+ protected function add_blank_combined_feedback($question) {
+ return $question;
+ }
}
+/**
+ * Since the lesson module tries to re-use the question bank import classes in
+ * a crazy way, this is necessary to stop things breaking. This should be exactly
+ * the same as the class defined in question/format.php.
+ */
+class qformat_based_on_xml extends qformat_default {
+ /**
+ * A lot of imported files contain unwanted entities.
+ * This method tries to clean up all known problems.
+ * @param string str string to correct
+ * @return string the corrected string
+ */
+ public function cleaninput($str) {
+
+ $html_code_list = array(
+ "'" => "'",
+ "’" => "'",
+ "“" => "\"",
+ "”" => "\"",
+ "–" => "-",
+ "—" => "-",
+ );
+ $str = strtr($str, $html_code_list);
+ // Use textlib entities_to_utf8 function to convert only numerical entities.
+ $str = textlib::entities_to_utf8($str, false);
+ return $str;
+ }
+
+ /**
+ * Return the array moodle is expecting
+ * for an HTML text. No processing is done on $text.
+ * qformat classes that want to process $text
+ * for instance to import external images files
+ * and recode urls in $text must overwrite this method.
+ * @param array $text some HTML text string
+ * @return array with keys text, format and files.
+ */
+ public function text_field($text) {
+ return array(
+ 'text' => trim($text),
+ 'format' => FORMAT_HTML,
+ 'files' => array(),
+ );
+ }
+
+ /**
+ * Return the value of a node, given a path to the node
+ * if it doesn't exist return the default value.
+ * @param array xml data to read
+ * @param array path path to node expressed as array
+ * @param mixed default
+ * @param bool istext process as text
+ * @param string error if set value must exist, return false and issue message if not
+ * @return mixed value
+ */
+ public function getpath($xml, $path, $default, $istext=false, $error='') {
+ foreach ($path as $index) {
+ if (!isset($xml[$index])) {
+ if (!empty($error)) {
+ $this->error($error);
+ return false;
+ } else {
+ return $default;
+ }
+ }
+
+ $xml = $xml[$index];
+ }
+
+ if ($istext) {
+ if (!is_string($xml)) {
+ $this->error(get_string('invalidxml', 'qformat_xml'));
+ }
+ $xml = trim($xml);
+ }
+
+ return $xml;
+ }
+}

0 comments on commit 5fe6d41

Please sign in to comment.