moodle/lib/classes/report_helper.php
Eloy Lafuente (stronk7) ba1f804ffa
MDL-65292 style: Fix all function declarations white space
This has been generated running the following Sniffs, all
them part of the Moodle's CodeSniffer standard:
- PSR12.Functions.ReturnTypeDeclaration
- PSR12.Functions.NullableTypeDeclaration
- moodle.Methods.MethodDeclarationSpacing
- Squiz.Whitespace.ScopeKeywordSpacing

All them are, exclusively, about correct spacing, so the changes
are, all them, only white space changes.

Only exceptions to the above are 3 changes what were setting the
return type in a new line, and, when that happens, the closing
parenthesis (bracket) has to go to the same line than the colon.
2024-02-28 23:33:26 +01:00

114 lines
3.9 KiB
PHP

<?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;
/**
* 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)) {
$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.
$result = array_search($coursereports, $menuarray[0][$coursereports]);
unset($menuarray[0][$coursereports][$result]);
// Find the active node.
foreach ($menuarray[0] as $key => $value) {
$check = array_search($pluginname, $value);
if ($check !== false) {
$activeurl = $check;
}
}
} else {
$result = array_search($coursereports, $menuarray);
unset($menuarray[$result]);
$check = array_search($pluginname, $menuarray);
if ($check !== false) {
$activeurl = $check;
}
}
$selectmenu = new \core\output\select_menu('reporttype', $menuarray, $activeurl);
$selectmenu->set_label(get_string('reporttype'), ['class' => 'sr-only']);
$options = \html_writer::tag(
'div',
$OUTPUT->render_from_template('core/tertiary_navigation_selector', $selectmenu->export_for_template($OUTPUT)),
['class' => 'row pb-3']
);
echo \html_writer::tag(
'div',
$options,
['class' => 'tertiary-navigation full-width-bottom-border ml-0', 'id' => 'tertiary-navigation']);
} else {
echo $OUTPUT->heading($pluginname, 2, 'mb-3');
}
}
/**
* Save the last selected report in the session
*
* @deprecated since Moodle 4.0
* @param int $id The course id
* @param moodle_url $url The moodle url
* @return void
*/
public static function save_selected_report(int $id, moodle_url $url): void {
global $USER;
debugging('save_selected_report() has been deprecated because it is no longer used and will be '.
'removed in future versions of Moodle', DEBUG_DEVELOPER);
// Last selected report.
if (!isset($USER->course_last_report)) {
$USER->course_last_report = [];
}
$USER->course_last_report[$id] = $url;
}
}