Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
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 /** 18 * Report plugins helper class 19 * 20 * @package core 21 * @subpackage report 22 * @copyright 2021 Sujith Haridasan 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace core; 27 use moodle_url; 28 use url_select; 29 30 /** 31 * A helper class with static methods to help report plugins 32 * 33 * @package core 34 * @copyright 2021 Sujith Haridasan 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class report_helper { 38 /** 39 * Print the selector dropdown 40 * 41 * @param string $pluginname The report plugin where the header is modified 42 * @return void 43 */ 44 public static function print_report_selector(string $pluginname):void { 45 global $OUTPUT, $PAGE; 46 47 if ($reportnode = $PAGE->settingsnav->find('coursereports', \navigation_node::TYPE_CONTAINER)) { 48 if ($children = $reportnode->children) { 49 // Menu to select report pages to navigate. 50 $activeurl = ''; 51 foreach ($children as $key => $node) { 52 $name = $node->text; 53 54 if ($node->has_action()) { 55 $url = $node->action()->out(false); 56 $menu[$url] = $name; 57 if ($name === $pluginname) { 58 $activeurl = $url; 59 } 60 } 61 } 62 } 63 64 if (!empty($menu)) { 65 $select = new url_select($menu, $activeurl, null, 'choosecoursereport'); 66 $select->set_label(get_string('report'), ['class' => 'accesshide']); 67 $select->attributes['style'] = "margin-bottom: 1.5rem"; 68 $select->class .= " mb-4"; 69 echo $OUTPUT->render($select); 70 } 71 } 72 } 73 74 /** 75 * Save the last selected report in the session 76 * 77 * @param int $id The course id 78 * @param moodle_url $url The moodle url 79 * @return void 80 */ 81 public static function save_selected_report(int $id, moodle_url $url):void { 82 global $USER; 83 84 // Last selected report. 85 if (!isset($USER->course_last_report)) { 86 $USER->course_last_report = []; 87 } 88 $USER->course_last_report[$id] = $url; 89 } 90 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body