| 1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
declare(strict_types=1);
|
|
|
18 |
|
|
|
19 |
namespace core_reportbuilder\external;
|
|
|
20 |
|
| 1441 |
ariadna |
21 |
use core_customfield\external\field_data_exporter;
|
| 1 |
efrain |
22 |
use core\external\persistent_exporter;
|
| 1441 |
ariadna |
23 |
use core\output\renderer_base;
|
| 1 |
efrain |
24 |
use core_reportbuilder\datasource;
|
|
|
25 |
use core_reportbuilder\manager;
|
|
|
26 |
use core_reportbuilder\local\models\report;
|
| 1441 |
ariadna |
27 |
use core_tag\external\{tag_item_exporter, util};
|
|
|
28 |
use core\user;
|
| 1 |
efrain |
29 |
use core_user\external\user_summary_exporter;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Custom report details exporter class
|
|
|
33 |
*
|
|
|
34 |
* @package core_reportbuilder
|
|
|
35 |
* @copyright 2022 Paul Holden <paulh@moodle.com>
|
|
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
37 |
*/
|
|
|
38 |
class custom_report_details_exporter extends persistent_exporter {
|
|
|
39 |
|
|
|
40 |
/** @var report The persistent object we will export. */
|
|
|
41 |
protected $persistent = null;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Return the name of the class we are exporting
|
|
|
45 |
*
|
|
|
46 |
* @return string
|
|
|
47 |
*/
|
|
|
48 |
protected static function define_class(): string {
|
|
|
49 |
return report::class;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Return a list of additional properties used only for display
|
|
|
54 |
*
|
|
|
55 |
* @return array
|
|
|
56 |
*/
|
|
|
57 |
protected static function define_other_properties(): array {
|
|
|
58 |
return [
|
|
|
59 |
'sourcename' => [
|
|
|
60 |
'type' => PARAM_RAW,
|
|
|
61 |
'null' => NULL_ALLOWED,
|
|
|
62 |
],
|
| 1441 |
ariadna |
63 |
'tags' => [
|
|
|
64 |
'type' => tag_item_exporter::read_properties_definition(),
|
|
|
65 |
'multiple' => true,
|
|
|
66 |
],
|
|
|
67 |
'customfields' => ['type' => field_data_exporter::read_properties_definition()],
|
| 1 |
efrain |
68 |
'modifiedby' => ['type' => user_summary_exporter::read_properties_definition()],
|
|
|
69 |
];
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* Get additional values to inject while exporting
|
|
|
74 |
*
|
|
|
75 |
* @param renderer_base $output
|
|
|
76 |
* @return array
|
|
|
77 |
*/
|
|
|
78 |
protected function get_other_values(renderer_base $output): array {
|
| 1441 |
ariadna |
79 |
$reportid = $this->persistent->get('id');
|
| 1 |
efrain |
80 |
$source = $this->persistent->get('source');
|
| 1441 |
ariadna |
81 |
$usermodified = user::get_user($this->persistent->get('usermodified'));
|
| 1 |
efrain |
82 |
|
|
|
83 |
return [
|
|
|
84 |
'sourcename' => manager::report_source_exists($source, datasource::class) ? $source::get_name() : null,
|
| 1441 |
ariadna |
85 |
'tags' => util::get_item_tags('core_reportbuilder', 'reportbuilder_report', $reportid),
|
|
|
86 |
'customfields' => (new field_data_exporter(null, [
|
|
|
87 |
'component' => 'core_reportbuilder',
|
|
|
88 |
'area' => 'report',
|
|
|
89 |
'instanceid' => $reportid,
|
|
|
90 |
]))->export($output),
|
| 1 |
efrain |
91 |
'modifiedby' => (new user_summary_exporter($usermodified))->export($output),
|
|
|
92 |
];
|
|
|
93 |
}
|
|
|
94 |
}
|