2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Report plugins helper class
22 * @copyright 2021 Sujith Haridasan
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 * A helper class with static methods to help report plugins
33 * @copyright 2021 Sujith Haridasan
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 * Print the selector dropdown
40 * @param string $pluginname The report plugin where the header is modified
43 public static function print_report_selector(string $pluginname):void
{
44 global $OUTPUT, $PAGE;
46 if ($reportnode = $PAGE->settingsnav
->find('coursereports', \navigation_node
::TYPE_CONTAINER
)) {
48 $menuarray = \core\navigation\views\secondary
::create_menu_element([$reportnode]);
49 if (empty($menuarray)) {
53 $coursereports = get_string('reports');
55 if (isset($menuarray[0])) {
56 // Remove the reports entry.
57 $result = array_search($coursereports, $menuarray[0][$coursereports]);
58 unset($menuarray[0][$coursereports][$result]);
60 // Find the active node.
61 foreach ($menuarray[0] as $key => $value) {
62 $check = array_search($pluginname, $value);
63 if ($check !== false) {
68 $result = array_search($coursereports, $menuarray);
69 unset($menuarray[$result]);
71 $check = array_search($pluginname, $menuarray);
72 if ($check !== false) {
77 $selectmenu = new \core\output\
select_menu('reporttype', $menuarray, $activeurl);
78 $selectmenu->set_label(get_string('reporttype'), ['class' => 'sr-only']);
79 $options = \html_writer
::tag(
81 $OUTPUT->render_from_template('core/tertiary_navigation_selector', $selectmenu->export_for_template($OUTPUT)),
82 ['class' => 'row pb-3']
84 echo \html_writer
::tag(
87 ['class' => 'tertiary-navigation full-width-bottom-border ml-0', 'id' => 'tertiary-navigation']);
89 echo $OUTPUT->heading($pluginname, 2, 'mb-3');
94 * Save the last selected report in the session
96 * @deprecated since Moodle 4.0
97 * @param int $id The course id
98 * @param moodle_url $url The moodle url
101 public static function save_selected_report(int $id, moodle_url
$url):void
{
104 debugging('save_selected_report() has been deprecated because it is no longer used and will be '.
105 'removed in future versions of Moodle', DEBUG_DEVELOPER
);
107 // Last selected report.
108 if (!isset($USER->course_last_report
)) {
109 $USER->course_last_report
= [];
111 $USER->course_last_report
[$id] = $url;