Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

I really wish someone would fix lesson to use the question bank.
  • Loading branch information...
commit 5fe6d4124558772a9c8f79b75c43182d78c70352 1 parent 21415ac
Tim Hunt authored August 30, 2012

Showing 1 changed file with 87 additions and 0 deletions. Show diff stats Hide diff stats

  1. 87  mod/lesson/format.php
87  mod/lesson/format.php
@@ -580,6 +580,93 @@ protected function format_question_text($question) {
580 580
         return html_to_text(format_text($question->questiontext,
581 581
                 $question->questiontextformat, $formatoptions), 0, false);
582 582
     }
  583
+
  584
+    /**
  585
+     * Since the lesson module tries to re-use the question bank import classes in
  586
+     * a crazy way, this is necessary to stop things breaking.
  587
+     */
  588
+    protected function add_blank_combined_feedback($question) {
  589
+        return $question;
  590
+    }
583 591
 }
584 592
 
585 593
 
  594
+/**
  595
+ * Since the lesson module tries to re-use the question bank import classes in
  596
+ * a crazy way, this is necessary to stop things breaking. This should be exactly
  597
+ * the same as the class defined in question/format.php.
  598
+ */
  599
+class qformat_based_on_xml extends qformat_default {
  600
+    /**
  601
+     * A lot of imported files contain unwanted entities.
  602
+     * This method tries to clean up all known problems.
  603
+     * @param string str string to correct
  604
+     * @return string the corrected string
  605
+     */
  606
+    public function cleaninput($str) {
  607
+
  608
+        $html_code_list = array(
  609
+            "'" => "'",
  610
+            "’" => "'",
  611
+            "“" => "\"",
  612
+            "”" => "\"",
  613
+            "–" => "-",
  614
+            "—" => "-",
  615
+        );
  616
+        $str = strtr($str, $html_code_list);
  617
+        // Use textlib entities_to_utf8 function to convert only numerical entities.
  618
+        $str = textlib::entities_to_utf8($str, false);
  619
+        return $str;
  620
+    }
  621
+
  622
+    /**
  623
+     * Return the array moodle is expecting
  624
+     * for an HTML text. No processing is done on $text.
  625
+     * qformat classes that want to process $text
  626
+     * for instance to import external images files
  627
+     * and recode urls in $text must overwrite this method.
  628
+     * @param array $text some HTML text string
  629
+     * @return array with keys text, format and files.
  630
+     */
  631
+    public function text_field($text) {
  632
+        return array(
  633
+            'text' => trim($text),
  634
+            'format' => FORMAT_HTML,
  635
+            'files' => array(),
  636
+        );
  637
+    }
  638
+
  639
+    /**
  640
+     * Return the value of a node, given a path to the node
  641
+     * if it doesn't exist return the default value.
  642
+     * @param array xml data to read
  643
+     * @param array path path to node expressed as array
  644
+     * @param mixed default
  645
+     * @param bool istext process as text
  646
+     * @param string error if set value must exist, return false and issue message if not
  647
+     * @return mixed value
  648
+     */
  649
+    public function getpath($xml, $path, $default, $istext=false, $error='') {
  650
+        foreach ($path as $index) {
  651
+            if (!isset($xml[$index])) {
  652
+                if (!empty($error)) {
  653
+                    $this->error($error);
  654
+                    return false;
  655
+                } else {
  656
+                    return $default;
  657
+                }
  658
+            }
  659
+
  660
+            $xml = $xml[$index];
  661
+        }
  662
+
  663
+        if ($istext) {
  664
+            if (!is_string($xml)) {
  665
+                $this->error(get_string('invalidxml', 'qformat_xml'));
  666
+            }
  667
+            $xml = trim($xml);
  668
+        }
  669
+
  670
+        return $xml;
  671
+    }
  672
+}

0 notes on commit 5fe6d41

Please sign in to comment.
Something went wrong with that request. Please try again.