mirror of
https://github.com/moodle/moodle.git
synced 2025-07-26 00:31:35 +02:00
Merge branch 'MDL-72058' of https://github.com/paulholden/moodle
This commit is contained in:
@@ -2197,7 +2197,17 @@ class table_default_export_format_parent {
|
||||
function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) {
|
||||
//use some whitespace to indicate where there was some line spacing.
|
||||
$text = str_replace(array('</p>', "\n", "\r"), ' ', $text);
|
||||
return strip_tags($text);
|
||||
return html_entity_decode(strip_tags($text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a row of data, removing HTML tags and entities from each of the cells
|
||||
*
|
||||
* @param array $row
|
||||
* @return array
|
||||
*/
|
||||
public function format_data(array $row): array {
|
||||
return array_map([$this, 'format_text'], $row);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2284,13 +2294,13 @@ class table_dataformat_export_format extends table_default_export_format_parent
|
||||
* @param array $headers
|
||||
*/
|
||||
public function output_headers($headers) {
|
||||
$this->columns = $headers;
|
||||
$this->columns = $this->format_data($headers);
|
||||
if (method_exists($this->dataformat, 'write_header')) {
|
||||
error_log('The function write_header() does not support multiple sheets. In order to support multiple sheets you ' .
|
||||
'must implement start_output() and start_sheet() and remove write_header() in your dataformat.');
|
||||
$this->dataformat->write_header($headers);
|
||||
$this->dataformat->write_header($this->columns);
|
||||
} else {
|
||||
$this->dataformat->start_sheet($headers);
|
||||
$this->dataformat->start_sheet($this->columns);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2300,6 +2310,10 @@ class table_dataformat_export_format extends table_default_export_format_parent
|
||||
* @param array $row One record of data
|
||||
*/
|
||||
public function add_data($row) {
|
||||
if (!$this->supports_html()) {
|
||||
$row = $this->format_data($row);
|
||||
}
|
||||
|
||||
$this->dataformat->write_record($row, $this->rownum++);
|
||||
return true;
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ Declaration is as follow:
|
||||
* Added $CFG->proxylogunsafe and proxyfixunsafe to detect code which doesn't honor the proxy config
|
||||
* Function admin_externalpage_setup() now has additional option 'nosearch' allowing to remove Site administration search form.
|
||||
* The function print_error has been deprecated. Kindly use moodle_exception.
|
||||
* When exporting table content, HTML tags/entities will be removed when the selected dataformat does not support HTML
|
||||
* The abstract `get_name` method has been moved from `\core\task\scheduled_task` to the `\core\task\task_base` class and can now be
|
||||
implemented by adhoc tasks. For backwards compatibility, a default implementation has been added to `\core\task\adhoc_task` to
|
||||
return the class name.
|
||||
|
@@ -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 <paulh@moodle.com>
|
||||
* @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)
|
||||
*
|
||||
|
Reference in New Issue
Block a user