MDL-56046 core: enable multiple sheets for flexible table
This commit is contained in:
+28
-8
@@ -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;
|
||||
@@ -1741,11 +1747,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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1755,7 +1764,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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1765,7 +1773,13 @@ 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')) {
|
||||
error_log('The function write_header() does not support multiple tables. In order to support multiple tables you ' .
|
||||
'must implement start_output() and start_sheet() and remove write_header() in your dataformat.');
|
||||
$this->dataformat->write_header($headers);
|
||||
} else {
|
||||
$this->dataformat->start_sheet($headers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1782,15 +1796,21 @@ 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')) {
|
||||
error_log('The function write_footer() does not support multiple tables. In order to support multiple tables you ' .
|
||||
'must implement close_sheet() and close_output() and remove write_footer() in your dataformat.');
|
||||
$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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user