]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16869 "Exporting leaves <p> </p> in essay responses" added method to flexible_tab...
authorjamiesensei <jamiesensei>
Tue, 14 Oct 2008 15:00:26 +0000 (15:00 +0000)
committerjamiesensei <jamiesensei>
Tue, 14 Oct 2008 15:00:26 +0000 (15:00 +0000)
lib/tablelib.php
mod/quiz/report/responses/responses_table.php

index 9871f49f6e164d2517d2ce4472b2512167325787..cf81a639aea1580d45e243ed7d9d99e3435013a6 100644 (file)
@@ -717,6 +717,37 @@ class flexible_table {
     }
 
 
+    /**
+     * Used from col_* functions when text is to be displayed. Does the
+     * right thing - either converts text to html or strips any html tags
+     * depending on if we are downloading and what is the download type. Params
+     * are the same as format_text function in weblib.php but some default
+     * options are changed.
+     */
+    function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL){
+        if (!$this->is_downloading()){
+            if (is_null($options)){
+                $options = new stdClass;
+            }
+            //some sensible defaults
+            if (!isset($options->para)){
+                $options->para = false;
+            }
+            if (!isset($options->newlines)){
+                $options->newlines = false;
+            }
+            if (!isset($options->smiley)) {
+                $options->smiley = false;
+            }
+            if (!isset($options->filter)) {
+                $options->filter = false;
+            }
+            return format_text($text, $format, $options);
+        } else {
+            $eci =& $this->export_class_instance();
+            return $eci->format_text($text, $format, $options, $courseid);
+        }
+    }
     /**
      * This method is deprecated although the old api is still supported.
      * @deprecated 1.9.2 - Jun 2, 2008
@@ -1272,6 +1303,16 @@ class table_default_export_format_parent{
     function document_started(){
         return $this->documentstarted;
     }
+    /**
+     * Given text in a variety of format codings, this function returns
+     * the text as safe HTML or as plain text dependent on what is appropriate
+     * for the download format. The default removes all tags.
+     */
+    function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL){
+        //use some whitespace to indicate where there was some line spacing.
+        $text = str_replace(array('</p>', "\n", "\r"), '   ', $text);
+        return strip_tags($text);
+    }
 }
 
 class table_spreadsheet_export_format_parent extends table_default_export_format_parent{
@@ -1503,5 +1544,24 @@ EOF;
         echo "</body>\n</html>";
         exit;
     }
+    function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL){
+        if (is_null($options)){
+            $options = new stdClass;
+        }
+        //some sensible defaults
+        if (!isset($options->para)){
+            $options->para = false;
+        }
+        if (!isset($options->newlines)){
+            $options->newlines = false;
+        }
+        if (!isset($options->smiley)) {
+            $options->smiley = false;
+        }
+        if (!isset($options->filter)) {
+            $options->filter = false;
+        }
+        return format_text($text, $format, $options);
+    }
 }
 ?>
index 9c0bac15a1f06250e1a8c35b88d78454d8d96dd5..cded6554a85b3ae13bff32ae68c838bc0fb28c23 100644 (file)
@@ -161,7 +161,6 @@ class quiz_report_responses_table extends table_sql {
                 if ($response){
                     $format_options = new stdClass;
                     $format_options->para = false;
-                    $format_options->noclean = true;
                     $format_options->newlines = false;
                     $response = format_text($response, FORMAT_MOODLE, $format_options);
                     if (strlen($response) > QUIZ_REPORT_RESPONSES_MAX_LEN_TO_DISPLAY){
@@ -187,7 +186,7 @@ class quiz_report_responses_table extends table_sql {
                 }
                 
             } else {
-                return $response;
+                return $this->format_text($response);
             }
         } else {
             return NULL;