mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-15777 - whole database module export rejigged to use files api.
disabled ods and excel export for now until those libraries work with files api. reverted a previous patch I had in this area.
This commit is contained in:
parent
513e0bed18
commit
1bf8c6b2cb
5 changed files with 22 additions and 34 deletions
|
@ -210,6 +210,7 @@ $string['pagesize'] = 'Entries per page';
|
||||||
$string['participants'] = 'Participants';
|
$string['participants'] = 'Participants';
|
||||||
$string['picture'] = 'Picture';
|
$string['picture'] = 'Picture';
|
||||||
$string['pleaseaddsome'] = 'Please create some below or <a href=\"$a\">choose a predefined set</a> to get started.';
|
$string['pleaseaddsome'] = 'Please create some below or <a href=\"$a\">choose a predefined set</a> to get started.';
|
||||||
|
$string['portfolionotfile'] = 'Export to a portfolio rather than a file (csv only)';
|
||||||
$string['presetinfo'] = 'Saving as a preset will publish this template. Other users may be able to use it in their databases.';
|
$string['presetinfo'] = 'Saving as a preset will publish this template. Other users may be able to use it in their databases.';
|
||||||
$string['presets'] = 'Presets';
|
$string['presets'] = 'Presets';
|
||||||
$string['radiobutton'] = 'Radio buttons';
|
$string['radiobutton'] = 'Radio buttons';
|
||||||
|
|
|
@ -44,7 +44,6 @@ $string['nonprimative'] = 'A non primative value was passed as a callback argume
|
||||||
$string['notexportable'] = 'Sorry, but the type of content you are trying to export is not exportable';
|
$string['notexportable'] = 'Sorry, but the type of content you are trying to export is not exportable';
|
||||||
$string['nouploaddirectory'] = 'Could not create a temporary directory to package your data into';
|
$string['nouploaddirectory'] = 'Could not create a temporary directory to package your data into';
|
||||||
$string['portfolio'] = 'Portfolio';
|
$string['portfolio'] = 'Portfolio';
|
||||||
$string['portfolionotfile'] = 'Export to a portfolio rather than a file';
|
|
||||||
$string['portfolios'] = 'Portfolios';
|
$string['portfolios'] = 'Portfolios';
|
||||||
$string['plugin'] = 'Portfolio Plugin';
|
$string['plugin'] = 'Portfolio Plugin';
|
||||||
$string['plugincouldnotpackage'] = 'Failed to package up your data for export';
|
$string['plugincouldnotpackage'] = 'Failed to package up your data for export';
|
||||||
|
|
|
@ -74,6 +74,7 @@ if($mform->is_cancelled()) {
|
||||||
if (array_key_exists('portfolio', $formdata) && !empty($formdata['portfolio'])) {
|
if (array_key_exists('portfolio', $formdata) && !empty($formdata['portfolio'])) {
|
||||||
// fake portfolio callback stuff and redirect
|
// fake portfolio callback stuff and redirect
|
||||||
$formdata['id'] = $cm->id;
|
$formdata['id'] = $cm->id;
|
||||||
|
$formdata['exporttype'] = 'csv'; // force for now
|
||||||
$url = portfolio_fake_add_url($formdata['portfolio'], 'data_portfolio_caller', '/mod/data/lib.php', $formdata);
|
$url = portfolio_fake_add_url($formdata['portfolio'], 'data_portfolio_caller', '/mod/data/lib.php', $formdata);
|
||||||
redirect($url);
|
redirect($url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,12 +53,12 @@ class mod_data_export_form extends moodleform {
|
||||||
}
|
}
|
||||||
$this->add_checkbox_controller(1, null, null, 1);
|
$this->add_checkbox_controller(1, null, null, 1);
|
||||||
require_once($CFG->libdir . '/portfoliolib.php');
|
require_once($CFG->libdir . '/portfoliolib.php');
|
||||||
if (false) { // @todo penny replace with permissions check
|
if (true) { // @todo penny replace with permissions check
|
||||||
if ($portfoliooptions = portfolio_instance_select(
|
if ($portfoliooptions = portfolio_instance_select(
|
||||||
portfolio_instances(),
|
portfolio_instances(),
|
||||||
call_user_func(array('data_portfolio_caller', 'supported_formats')),
|
call_user_func(array('data_portfolio_caller', 'supported_formats')),
|
||||||
'data_portfolio_caller', '', true, true)) {
|
'data_portfolio_caller', '', true, true)) {
|
||||||
$mform->addElement('header', 'notice', get_string('portfolionotfile', 'portfolio') . ':');
|
$mform->addElement('header', 'notice', get_string('portfolionotfile', 'data') . ':');
|
||||||
$portfoliooptions[0] = get_string('none');
|
$portfoliooptions[0] = get_string('none');
|
||||||
ksort($portfoliooptions);
|
ksort($portfoliooptions);
|
||||||
$mform->addElement('select', 'portfolio', get_string('portfolio', 'portfolio'), $portfoliooptions);
|
$mform->addElement('select', 'portfolio', get_string('portfolio', 'portfolio'), $portfoliooptions);
|
||||||
|
|
|
@ -2281,7 +2281,7 @@ function data_supports($feature) {
|
||||||
default: return null;
|
default: return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function data_export_csv($export, $delimiter_name, $dataname, $count, $todir=false) {
|
function data_export_csv($export, $delimiter_name, $dataname, $count, $return=false) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
require_once($CFG->libdir . '/csvlib.class.php');
|
require_once($CFG->libdir . '/csvlib.class.php');
|
||||||
$delimiter = csv_import_reader::get_delimiter($delimiter_name);
|
$delimiter = csv_import_reader::get_delimiter($delimiter_name);
|
||||||
|
@ -2292,7 +2292,7 @@ function data_export_csv($export, $delimiter_name, $dataname, $count, $todir=fal
|
||||||
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
|
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
|
||||||
$filename .= clean_filename("-${delimiter_name}_separated");
|
$filename .= clean_filename("-${delimiter_name}_separated");
|
||||||
$filename .= '.csv';
|
$filename .= '.csv';
|
||||||
if (!$todir) {
|
if (empty($return)) {
|
||||||
header("Content-Type: application/download\n");
|
header("Content-Type: application/download\n");
|
||||||
header("Content-Disposition: attachment; filename=$filename");
|
header("Content-Disposition: attachment; filename=$filename");
|
||||||
header('Expires: 0');
|
header('Expires: 0');
|
||||||
|
@ -2307,22 +2307,15 @@ function data_export_csv($export, $delimiter_name, $dataname, $count, $todir=fal
|
||||||
}
|
}
|
||||||
$returnstr .= implode($delimiter, $row) . "\n";
|
$returnstr .= implode($delimiter, $row) . "\n";
|
||||||
}
|
}
|
||||||
if (empty($todir)) {
|
if (empty($return)) {
|
||||||
echo $returnstr;
|
echo $returnstr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// @todo - convert to files api.
|
return $returnstr;
|
||||||
$status = ($handle = fopen($todir . '/' . $filename, 'w'));
|
|
||||||
$status = $status && fwrite($handle, $returnstr);
|
|
||||||
$status = $status && fclose($handle);
|
|
||||||
if ($status) {
|
|
||||||
return $filename;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function data_export_xls($export, $dataname, $count, $todir=false) {
|
function data_export_xls($export, $dataname, $count) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
require_once("$CFG->libdir/excellib.class.php");
|
require_once("$CFG->libdir/excellib.class.php");
|
||||||
$filename = clean_filename("${dataname}-${count}_record");
|
$filename = clean_filename("${dataname}-${count}_record");
|
||||||
|
@ -2333,13 +2326,8 @@ function data_export_xls($export, $dataname, $count, $todir=false) {
|
||||||
$filename .= '.xls';
|
$filename .= '.xls';
|
||||||
|
|
||||||
$filearg = '-';
|
$filearg = '-';
|
||||||
if ($todir) {
|
|
||||||
$filearg = $todir . '/' . $filename;
|
|
||||||
}
|
|
||||||
$workbook = new MoodleExcelWorkbook($filearg);
|
$workbook = new MoodleExcelWorkbook($filearg);
|
||||||
if (!$todir) {
|
$workbook->send($filename);
|
||||||
$workbook->send($filename);
|
|
||||||
}
|
|
||||||
$worksheet = array();
|
$worksheet = array();
|
||||||
$worksheet[0] =& $workbook->add_worksheet('');
|
$worksheet[0] =& $workbook->add_worksheet('');
|
||||||
$rowno = 0;
|
$rowno = 0;
|
||||||
|
@ -2356,7 +2344,7 @@ function data_export_xls($export, $dataname, $count, $todir=false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function data_export_ods($export, $dataname, $count, $todir=false) {
|
function data_export_ods($export, $dataname, $count) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
require_once("$CFG->libdir/odslib.class.php");
|
require_once("$CFG->libdir/odslib.class.php");
|
||||||
$filename = clean_filename("${dataname}-${count}_record");
|
$filename = clean_filename("${dataname}-${count}_record");
|
||||||
|
@ -2366,13 +2354,8 @@ function data_export_ods($export, $dataname, $count, $todir=false) {
|
||||||
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
|
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
|
||||||
$filename .= '.ods';
|
$filename .= '.ods';
|
||||||
$filearg = '-';
|
$filearg = '-';
|
||||||
if ($todir) {
|
$workbook = new MoodleODSWorkbook($filearg);
|
||||||
$filearg = $todir . '/' . $filename;
|
$workbook->send($filename);
|
||||||
}
|
|
||||||
$workbook = new MoodleODSWorkbook($filearg, (empty($todir)));
|
|
||||||
if (!$todir) {
|
|
||||||
$workbook->send($filename);
|
|
||||||
}
|
|
||||||
$worksheet = array();
|
$worksheet = array();
|
||||||
$worksheet[0] =& $workbook->add_worksheet('');
|
$worksheet[0] =& $workbook->add_worksheet('');
|
||||||
$rowno = 0;
|
$rowno = 0;
|
||||||
|
@ -2475,19 +2458,23 @@ class data_portfolio_caller extends portfolio_module_caller_base {
|
||||||
public function prepare_package() {
|
public function prepare_package() {
|
||||||
global $DB;
|
global $DB;
|
||||||
$count = count($this->exportdata);
|
$count = count($this->exportdata);
|
||||||
|
$content = '';
|
||||||
|
$filename = '';
|
||||||
switch ($this->exporttype) {
|
switch ($this->exporttype) {
|
||||||
case 'csv':
|
case 'csv':
|
||||||
$return = data_export_csv($this->exportdata, $this->delimiter, $this->cm->name, $count, $tempdir);
|
$content = data_export_csv($this->exportdata, $this->delimiter, $this->cm->name, $count, true);
|
||||||
|
$filename = clean_filename($this->cm->name . '.csv');
|
||||||
break;
|
break;
|
||||||
case 'xls':
|
case 'xls':
|
||||||
$return = data_export_xls($this->exportdata, $this->cm->name, $count, $tempdir);
|
portfolio_exporter::raise_error('notimplemented', 'portfolio');
|
||||||
|
$content = data_export_xls($this->exportdata, $this->cm->name, $count, true);
|
||||||
break;
|
break;
|
||||||
case 'ods':
|
case 'ods':
|
||||||
$return = data_export_ods($this->exportdata, $this->cm->name, $count, $tempdir);
|
portfolio_exporter::raise_error('notimplemented', 'portfolio');
|
||||||
|
$content = data_export_ods($this->exportdata, $this->cm->name, $count, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $return;
|
return $this->exporter->write_new_file($content, $filename);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check_permissions() {
|
public function check_permissions() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue