Skip to content

Commit

Permalink
Merge branch 'MDL-73467' of git://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Jan 13, 2022
2 parents 03956b8 + b625b9f commit 8b73145
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
15 changes: 12 additions & 3 deletions reportbuilder/classes/local/helpers/schedule.php
Expand Up @@ -28,6 +28,7 @@
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;

/**
Expand Down Expand Up @@ -153,6 +154,13 @@ public static function get_schedule_report_file(model $schedule): stored_file {
$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 = [
Expand All @@ -166,11 +174,12 @@ public static function get_schedule_report_file(model $schedule): stored_file {

$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);
}
);

Expand Down
16 changes: 14 additions & 2 deletions reportbuilder/classes/output/dataformat_export_format.php
Expand Up @@ -34,16 +34,28 @@
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;
}
}

0 comments on commit 8b73145

Please sign in to comment.