Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Report plugins helper class
 *
 * @package core
 * @subpackage report
 * @copyright 2021 Sujith Haridasan
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace core;
use moodle_url;
use url_select;

/**
 * A helper class with static methods to help report plugins
 *
 * @package core
 * @copyright 2021 Sujith Haridasan
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class report_helper {
    /**
     * Print the selector dropdown
     *
     * @param string $pluginname The report plugin where the header is modified
     * @return void
     */
    public static function print_report_selector(string $pluginname):void {
        global $OUTPUT, $PAGE;

        if ($reportnode = $PAGE->settingsnav->find('coursereports', \navigation_node::TYPE_CONTAINER)) {
< if ($children = $reportnode->children) { < // Menu to select report pages to navigate. < $activeurl = ''; < foreach ($children as $key => $node) { < $name = $node->text;
< if ($node->has_action()) { < $url = $node->action()->out(false); < $menu[$url] = $name; < if ($name === $pluginname) { < $activeurl = $url;
> $menuarray = \core\navigation\views\secondary::create_menu_element([$reportnode]); > if (empty($menuarray)) { > return;
}
> } > $coursereports = get_string('reports'); } > $activeurl = ''; } > if (isset($menuarray[0])) { > // Remove the reports entry. if (!empty($menu)) { > $result = array_search($coursereports, $menuarray[0][$coursereports]); $select = new url_select($menu, $activeurl, null, 'choosecoursereport'); > unset($menuarray[0][$coursereports][$result]); $select->set_label(get_string('report'), ['class' => 'accesshide']); > $select->attributes['style'] = "margin-bottom: 1.5rem"; > // Find the active node. $select->class .= " mb-4"; > foreach ($menuarray[0] as $key => $value) { echo $OUTPUT->render($select); > $check = array_search($pluginname, $value); } > if ($check !== false) { } > $activeurl = $check;
}
> } else { > $result = array_search($coursereports, $menuarray); /** > unset($menuarray[$result]); * Save the last selected report in the session > * > $check = array_search($pluginname, $menuarray); * @param int $id The course id > if ($check !== false) { * @param moodle_url $url The moodle url > $activeurl = $check;
< if (!empty($menu)) { < $select = new url_select($menu, $activeurl, null, 'choosecoursereport'); < $select->set_label(get_string('report'), ['class' => 'accesshide']); < $select->attributes['style'] = "margin-bottom: 1.5rem"; < $select->class .= " mb-4"; < echo $OUTPUT->render($select);
if (!isset($USER->course_last_report)) {
> $USER->course_last_report = []; > $select = new url_select($menuarray, $activeurl, null, 'choosecoursereport'); } > $select->set_label(get_string('reporttype'), ['class' => 'accesshide']); $USER->course_last_report[$id] = $url; > echo \html_writer::tag('div', $OUTPUT->render($select), ['class' => 'tertiary-navigation']);
}
> echo $OUTPUT->heading($pluginname, 2, 'mb-3');
}
> * @deprecated since Moodle 4.0
> > debugging('save_selected_report() has been deprecated because it is no longer used and will be '. > 'removed in future versions of Moodle', DEBUG_DEVELOPER);