1
0
mirror of https://github.com/moodle/moodle.git synced 2025-05-11 18:56:09 +02:00

Merge branch 'MDL-73467' of git://github.com/paulholden/moodle

This commit is contained in:
Jun Pataleta 2022-01-13 11:43:32 +08:00
commit 8b73145310
2 changed files with 26 additions and 5 deletions
reportbuilder/classes

@ -28,6 +28,7 @@ use core\message\message;
use core\plugininfo\dataformat;
use core_reportbuilder\local\models\audience as audience_model;
use core_reportbuilder\local\models\schedule as model;
use core_reportbuilder\output\dataformat_export_format;
use core_reportbuilder\table\custom_report_table_view;
/**
@ -153,6 +154,13 @@ class schedule {
$table->setup();
$table->query_db(0, false);
// Set up table as if it were being downloaded, retrieve appropriate export class (ensure output buffer is
// cleaned in order to instantiate export class without exception).
ob_start();
$table->download = $schedule->get('format');
$exportclass = new dataformat_export_format($table, $table->download);
ob_end_clean();
// Create our schedule report stored file.
$context = context_user::instance($schedule->get('usercreated'));
$filerecord = [
@ -166,11 +174,12 @@ class schedule {
$storedfile = \core\dataformat::write_data_to_filearea(
$filerecord,
$schedule->get('format'),
$table->download,
$table->headers,
$table->rawdata,
static function(stdClass $record) use ($table): array {
return $table->format_row($record);
static function(stdClass $record) use ($table, $exportclass): array {
$record = $table->format_row($record);
return $exportclass->format_data($record);
}
);

@ -34,16 +34,28 @@ require_once("{$CFG->libdir}/tablelib.php");
class dataformat_export_format extends table_dataformat_export_format {
/**
* Add a row of data. If the export format doesn't support HTML, then format cell contents to remove tags
* Add a row of data
*
* @param array $row
* @return bool
*/
public function add_data($row): bool {
$row = $this->format_data($row);
return parent::add_data($row);
}
/**
* Format a row of data. If the export format doesn't support HTML, then format cell contents to remove tags
*
* @param array $row
* @return array
*/
public function format_data(array $row): array {
if (!$this->dataformat->supports_html()) {
$row = array_map([$this, 'format_text'], $row);
}
return parent::add_data($row);
return $row;
}
}