Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
 
21
use core\context\system;
22
use core\external\exporter;
23
use core\output\renderer_base;
24
use core_reportbuilder\output\report_action;
25
 
26
/**
27
 * Encapsulate a report action
28
 *
29
 * @package     core_reportbuilder
30
 * @copyright   2025 Paul Holden <paulh@moodle.com>
31
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class report_action_exporter extends exporter {
34
 
35
    /**
36
     * Return a list of objects that are related to the exporter
37
     *
38
     * @return array
39
     */
40
    protected static function define_related(): array {
41
        return [
42
            'reportaction' => report_action::class,
43
        ];
44
    }
45
 
46
    /**
47
     * Return the list of additional properties for read structure and export
48
     *
49
     * @return array[]
50
     */
51
    protected static function define_other_properties(): array {
52
        return [
53
            'tag' => [
54
                'type' => PARAM_ALPHA,
55
            ],
56
            'title' => [
57
                'type' => PARAM_TEXT,
58
            ],
59
            'attributes' => [
60
                'type' => [
61
                    'name' => [
62
                        'type' => PARAM_RAW,
63
                        'optional' => true,
64
                    ],
65
                    'value' => [
66
                        'type' => PARAM_RAW,
67
                        'optional' => true,
68
                    ],
69
                ],
70
                'multiple' => true,
71
            ],
72
        ];
73
    }
74
 
75
    /**
76
     * Return text formatting parameters for title property
77
     *
78
     * @return array
79
     */
80
    protected function get_format_parameters_for_title(): array {
81
        return [
82
            'context' => system::instance(),
83
        ];
84
    }
85
 
86
    /**
87
     * Get the additional values to inject while exporting
88
     *
89
     * @param renderer_base $output
90
     * @return array
91
     */
92
    protected function get_other_values(renderer_base $output): array {
93
 
94
        /** @var report_action $reportaction */
95
        $reportaction = $this->related['reportaction'];
96
 
97
        $attributes = array_map(static function($key, $value): array {
98
            return ['name' => $key, 'value' => $value];
99
        }, array_keys($reportaction->attributes), $reportaction->attributes);
100
 
101
        return [
102
            'tag' => $reportaction->tag ?: 'button',
103
            'title' => $reportaction->title,
104
            'attributes' => $attributes,
105
        ];
106
    }
107
}