MDL-56046 core: enable multiple sheets for flexible table

This commit is contained in:
Mark Nelson
2017-06-26 13:55:21 +08:00
parent a54703d88f
commit 4e50a38018
2 changed files with 39 additions and 15 deletions
+24 -8
View File
@@ -125,6 +125,12 @@ class flexible_table {
*/
private $prefs = array();
/** @var $sheettitle */
protected $sheettitle;
/** @var $filename */
protected $filename;
/**
* Constructor
* @param string $uniqueid all tables have to have a unique id, this is used
@@ -180,7 +186,7 @@ class flexible_table {
} else if (is_null($this->exportclass) && !empty($this->download)) {
$this->exportclass = new table_dataformat_export_format($this, $this->download);
if (!$this->exportclass->document_started()) {
$this->exportclass->start_document($this->filename);
$this->exportclass->start_document($this->filename, $this->sheettitle);
}
}
return $this->exportclass;
@@ -1731,11 +1737,14 @@ class table_dataformat_export_format extends table_default_export_format_parent
* Start document
*
* @param string $filename
* @param string $sheettitle
*/
public function start_document($filename) {
$this->filename = $filename;
public function start_document($filename, $sheettitle) {
$this->documentstarted = true;
$this->dataformat->set_filename($filename);
$this->dataformat->send_http_headers();
$this->dataformat->set_sheettitle($sheettitle);
$this->dataformat->start_output();
}
/**
@@ -1745,7 +1754,6 @@ class table_dataformat_export_format extends table_default_export_format_parent
*/
public function start_table($sheettitle) {
$this->dataformat->set_sheettitle($sheettitle);
$this->dataformat->send_http_headers();
}
/**
@@ -1755,7 +1763,11 @@ class table_dataformat_export_format extends table_default_export_format_parent
*/
public function output_headers($headers) {
$this->columns = $headers;
$this->dataformat->write_header($headers);
if (method_exists($this->dataformat, 'write_header')) {
$this->dataformat->write_header($headers);
} else {
$this->dataformat->start_sheet($headers);
}
}
/**
@@ -1772,15 +1784,19 @@ class table_dataformat_export_format extends table_default_export_format_parent
* Finish export
*/
public function finish_table() {
$this->dataformat->write_footer($this->columns);
if (method_exists($this->dataformat, 'write_footer')) {
$this->dataformat->write_footer($this->columns);
} else {
$this->dataformat->close_sheet($this->columns);
}
}
/**
* Finish download
*/
public function finish_document() {
exit;
$this->dataformat->close_output();
exit();
}
}