From: jamiesensei Date: Tue, 14 Oct 2008 15:00:26 +0000 (+0000) Subject: MDL-16869 "Exporting leaves

in essay responses" added method to flexible_tab... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ef27e742738e6f693b2638104dc0e2845e86226d;p=moodle.git MDL-16869 "Exporting leaves

in essay responses" added method to flexible_table class format_text that takes the same parameters as format_text the function in weblib. If the table is not in download mode then this formats the text as html. If it is then it strips the tags or does the right thing depending on the download type. Added methods to download classes to tell flexible_table class what should be done with html. --- diff --git a/lib/tablelib.php b/lib/tablelib.php index 9871f49f6e..cf81a639ae 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -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('

', "\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 "\n"; 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); + } } ?> diff --git a/mod/quiz/report/responses/responses_table.php b/mod/quiz/report/responses/responses_table.php index 9c0bac15a1..cded6554a8 100644 --- a/mod/quiz/report/responses/responses_table.php +++ b/mod/quiz/report/responses/responses_table.php @@ -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;