MDL-75532 enrol_lti: fix optional lineitemsurl in grade sync task
[moodle.git] / reportbuilder / view.php
blob9aab7a3990c19adc2a1e241d09a9ef4ee82d2d18
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.
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/>.
17 /**
18 * View a custom report
20 * @package core_reportbuilder
21 * @copyright 2021 David Matamoros <davidmc@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 declare(strict_types=1);
27 use core_reportbuilder\event\report_viewed;
28 use core_reportbuilder\manager;
29 use core_reportbuilder\output\custom_report;
30 use core_reportbuilder\permission;
32 require_once(__DIR__ . '/../config.php');
33 require_once("{$CFG->libdir}/adminlib.php");
35 $reportid = required_param('id', PARAM_INT);
37 admin_externalpage_setup('customreports', null, ['id' => $reportid], new moodle_url('/reportbuilder/view.php'));
38 navigation_node::override_active_url(new moodle_url('/reportbuilder/index.php'));
40 $report = manager::get_report_from_id($reportid);
41 permission::require_can_view_report($report->get_report_persistent());
43 $PAGE->set_context($report->get_context());
44 $PAGE->navbar->add(get_string('viewreport', 'core_reportbuilder'), $PAGE->url);
46 /** @var \core_reportbuilder\output\renderer $renderer */
47 $renderer = $PAGE->get_renderer('core_reportbuilder');
49 $reportname = $report->get_report_persistent()->get_formatted_name();
50 $PAGE->set_title($reportname);
51 $PAGE->set_heading($reportname);
53 echo $OUTPUT->header();
55 $export = (new custom_report($report->get_report_persistent(), false))->export_for_template($renderer);
56 echo $renderer->render_from_template('core_reportbuilder/report', $export);
58 echo $OUTPUT->footer();
60 // Trigger report viewed event.
61 report_viewed::create_from_object($report->get_report_persistent())->trigger();