mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-73275' of https://github.com/paulholden/moodle
This commit is contained in:
commit
3946c78c2e
2 changed files with 68 additions and 0 deletions
49
reportbuilder/classes/output/dataformat_export_format.php
Normal file
49
reportbuilder/classes/output/dataformat_export_format.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?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. If the export format doesn't support HTML, then format cell contents to remove tags
|
||||
*
|
||||
* @param array $row
|
||||
* @return bool
|
||||
*/
|
||||
public function add_data($row): bool {
|
||||
if (!$this->dataformat->supports_html()) {
|
||||
$row = array_map([$this, 'format_text'], $row);
|
||||
}
|
||||
|
||||
return parent::add_data($row);
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ 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;
|
||||
|
@ -29,6 +30,7 @@ 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;
|
||||
|
@ -173,6 +175,23 @@ abstract class base_report_table extends table_sql implements dynamic, renderabl
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue