MDL-34074 - lib - Creation of a csv upload class which is FRC 4180 compliant and the alteration of various files around Moodle to use this class.

This commit is contained in:
Adrian Greeve
2012-08-02 13:18:57 +08:00
parent 55a568fa7d
commit 9a5abd1b70
6 changed files with 319 additions and 93 deletions
+15 -14
View File
@@ -1557,18 +1557,19 @@ class table_ods_export_format extends table_spreadsheet_export_format_parent {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class table_text_export_format_parent extends table_default_export_format_parent {
protected $seperator = "\t";
protected $seperator = "tab";
protected $mimetype = 'text/tab-separated-values';
protected $ext = '.txt';
protected $myexporter;
public function __construct() {
$this->myexporter = new csv_export_writer($this->seperator, '"', $this->mimetype);
}
public function start_document($filename) {
$this->filename = $filename . $this->ext;
header('Content-Type: ' . $this->mimetype . '; charset=UTF-8');
header('Content-Disposition: attachment; filename="' . $this->filename . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
header('Pragma: public');
$this->filename = $filename;
$this->documentstarted = true;
$this->myexporter->set_filename($filename, $this->ext);
}
public function start_table($sheettitle) {
@@ -1576,19 +1577,20 @@ class table_text_export_format_parent extends table_default_export_format_parent
}
public function output_headers($headers) {
echo $this->format_row($headers);
$this->myexporter->add_data($headers);
}
public function add_data($row) {
echo $this->format_row($row);
$this->myexporter->add_data($row);
return true;
}
public function finish_table() {
echo "\n\n";
//nothing to do here
}
public function finish_document() {
$this->myexporter->download_file();
exit;
}
@@ -1612,24 +1614,23 @@ class table_text_export_format_parent extends table_default_export_format_parent
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class table_tsv_export_format extends table_text_export_format_parent {
protected $seperator = "\t";
protected $seperator = "tab";
protected $mimetype = 'text/tab-separated-values';
protected $ext = '.txt';
}
require_once($CFG->libdir . '/csvlib.class.php');
/**
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class table_csv_export_format extends table_text_export_format_parent {
protected $seperator = ",";
protected $seperator = "comma";
protected $mimetype = 'text/csv';
protected $ext = '.csv';
}
/**
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}