Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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;
20
 
21
use stdClass;
22
use core_reportbuilder\table\system_report_table;
23
 
24
/**
25
 * Testable system report table for getting report data
26
 *
27
 * @package     core_reportbuilder
28
 * @copyright   2021 Paul Holden <paulh@moodle.com>
29
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class testable_system_report_table extends system_report_table {
32
 
33
    /**
34
     * Format each row of returned data, replacing aliased column names with the original
35
     *
36
     * @param array|stdClass $row
37
     * @return array
38
     */
39
    public function format_row($row): array {
40
        $record = parent::format_row($row);
41
        $result = [];
42
 
43
        $columns = $this->report->get_columns();
44
        foreach ($columns as $column) {
45
            $result[$column->get_name()] = $record[$column->get_column_alias()];
46
        }
47
 
48
        return $result;
49
    }
50
 
51
    /**
52
     * Return all table rows
53
     *
54
     * @return array
55
     */
56
    public function get_table_rows(): array {
57
        global $PAGE;
58
 
59
        $PAGE->set_url('/');
60
 
61
        $result = [];
62
 
63
        $this->guess_base_url();
64
        $this->setup();
65
 
66
        $this->query_db(0, false);
67
        foreach ($this->rawdata as $record) {
68
            $result[] = $this->format_row($record);
69
        }
70
 
71
        $this->close_recordset();
72
 
73
        return $result;
74
    }
75
}