MDL-16869 "Exporting leaves <p> </p> 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.

This commit is contained in:
jamiesensei 2008-10-14 15:00:26 +00:00
parent f298a6255c
commit ef27e74273
2 changed files with 61 additions and 2 deletions

View 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);
}
}
?>

View 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;