MDL-40084 mod_data: Remove xls export, deprecate data_export_xls

This commit is contained in:
Philipp Memmel 2023-03-13 21:49:55 +01:00
parent 8dbb6183ff
commit ab09cf2b84
4 changed files with 45 additions and 38 deletions

View File

@ -61,3 +61,42 @@ function data_get_completion_state($course, $cm, $userid, $type) {
}
return $result;
}
/**
* @deprecated since Moodle 4.3.
* @global object
* @param array $export
* @param string $dataname
* @param int $count
* @return string
*/
function data_export_xls($export, $dataname, $count) {
global $CFG;
debugging('Function data_export_xls() has been deprecated, because xls export has been dropped.',
DEBUG_DEVELOPER);
require_once("$CFG->libdir/excellib.class.php");
$filename = clean_filename("{$dataname}-{$count}_record");
if ($count > 1) {
$filename .= 's';
}
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
$filename .= '.xls';
$filearg = '-';
$workbook = new MoodleExcelWorkbook($filearg);
$workbook->send($filename);
$worksheet = array();
$worksheet[0] = $workbook->add_worksheet('');
$rowno = 0;
foreach ($export as $row) {
$colno = 0;
foreach($row as $col) {
$worksheet[0]->write($rowno, $colno, $col);
$colno++;
}
$rowno++;
}
$workbook->close();
return $filename;
}

View File

@ -102,12 +102,12 @@ if ($mform->is_cancelled()) {
case 'csv':
data_export_csv($exportdata, $formdata['delimiter_name'], $data->name, $count);
break;
case 'xls':
data_export_xls($exportdata, $data->name, $count);
break;
case 'ods':
data_export_ods($exportdata, $data->name, $count);
break;
default:
throw new coding_exception('Invalid export format has been specified. '
. 'Only "csv" and "ods" are currently supported.');
}
}

View File

@ -3135,41 +3135,6 @@ function data_export_csv($export, $delimiter_name, $database, $count, $return=fa
}
}
/**
* @global object
* @param array $export
* @param string $dataname
* @param int $count
* @return string
*/
function data_export_xls($export, $dataname, $count) {
global $CFG;
require_once("$CFG->libdir/excellib.class.php");
$filename = clean_filename("{$dataname}-{$count}_record");
if ($count > 1) {
$filename .= 's';
}
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
$filename .= '.xls';
$filearg = '-';
$workbook = new MoodleExcelWorkbook($filearg);
$workbook->send($filename);
$worksheet = array();
$worksheet[0] = $workbook->add_worksheet('');
$rowno = 0;
foreach ($export as $row) {
$colno = 0;
foreach($row as $col) {
$worksheet[0]->write($rowno, $colno, $col);
$colno++;
}
$rowno++;
}
$workbook->close();
return $filename;
}
/**
* @global object
* @param array $export

View File

@ -1,6 +1,9 @@
This files describes API changes in /mod/data - plugins,
information provided here is intended especially for developers.
== 4.3 ==
* Function data_export_xls() has been deprecated and moved to deprecatedlib, because xls support has already been dropped.
== 4.2 ==
* The field base class now has a method validate(). Overwrite it in the field type to provide validation of field type's
parameters in the field add/modify form.