MDL-72058 reportbuilder: replace custom dataformat export format.

The formatting of exported dataformat content is now always dependent
on whether the format supports HTML or not, so we no longer need our
custom export class for providing the same.
This commit is contained in:
Paul Holden
2022-10-03 09:16:06 +01:00
parent 703f0b2a03
commit 5b353b73d6
3 changed files with 8 additions and 86 deletions
@@ -19,16 +19,15 @@ declare(strict_types=1);
namespace core_reportbuilder\local\helpers;
use context_user;
use core_plugin_manager;
use core_user;
use invalid_parameter_exception;
use stdClass;
use stored_file;
use table_dataformat_export_format;
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;
/**
@@ -163,7 +162,7 @@ class schedule {
// cleaned in order to instantiate export class without exception).
ob_start();
$table->download = $schedule->get('format');
$exportclass = new dataformat_export_format($table, $table->download);
$exportclass = new table_dataformat_export_format($table, $table->download);
ob_end_clean();
// Create our schedule report stored file.
@@ -180,11 +179,14 @@ class schedule {
$storedfile = \core\dataformat::write_data_to_filearea(
$filerecord,
$table->download,
$table->headers,
$exportclass->format_data($table->headers),
$table->rawdata,
static function(stdClass $record) use ($table, $exportclass): array {
static function(stdClass $record, bool $supportshtml) use ($table, $exportclass): array {
$record = $table->format_row($record);
return $exportclass->format_data($record);
if (!$supportshtml) {
$record = $exportclass->format_data($record);
}
return $record;
}
);
@@ -1,61 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
declare(strict_types=1);
namespace core_reportbuilder\output;
use table_dataformat_export_format;
defined('MOODLE_INTERNAL') || die();
require_once("{$CFG->libdir}/tablelib.php");
/**
* Dataformat export class for reports
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dataformat_export_format extends table_dataformat_export_format {
/**
* 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 $row;
}
}
@@ -21,7 +21,6 @@ namespace core_reportbuilder\table;
use context;
use moodle_url;
use renderable;
use table_default_export_format_parent;
use table_sql;
use html_writer;
use core_table\dynamic;
@@ -30,7 +29,6 @@ use core_reportbuilder\local\filters\base;
use core_reportbuilder\local\models\report;
use core_reportbuilder\local\report\base as base_report;
use core_reportbuilder\local\report\filter;
use core_reportbuilder\output\dataformat_export_format;
use core\output\notification;
defined('MOODLE_INTERNAL') || die;
@@ -213,23 +211,6 @@ abstract class base_report_table extends table_sql implements dynamic, renderabl
return static::construct_order_by($columnsortby);
}
/**
* Set the export class to use when downloading reports (TODO: consider applying to all tables, MDL-72058)
*
* @param table_default_export_format_parent|null $exportclass
* @return table_default_export_format_parent|null
*/
public function export_class_instance($exportclass = null) {
if (is_null($this->exportclass) && $this->is_downloading()) {
$this->exportclass = new dataformat_export_format($this, $this->download);
if (!$this->exportclass->document_started()) {
$this->exportclass->start_document($this->filename, $this->sheettitle);
}
}
return $this->exportclass;
}
/**
* Get the context for the table (that of the report persistent)
*