Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | n/a |
0 / 0 |
|
| local_finalgrades_extend_navigation_course | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| local_finalgrades_pluginfile | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | // This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>. |
| 16 | |
| 17 | /** |
| 18 | * Library functions for local_finalgrades. |
| 19 | * |
| 20 | * @package local_finalgrades |
| 21 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 22 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * Add "Final grades" to the course menu for teachers and approvers. |
| 27 | * |
| 28 | * @param navigation_node $navigation |
| 29 | * @param stdClass $course |
| 30 | * @param context $context |
| 31 | */ |
| 32 | function local_finalgrades_extend_navigation_course(navigation_node $navigation, stdClass $course, context $context) { |
| 33 | if ($course->id == SITEID) { |
| 34 | return; |
| 35 | } |
| 36 | if (!has_any_capability(['local/finalgrades:submit', 'local/finalgrades:approve'], $context)) { |
| 37 | return; |
| 38 | } |
| 39 | $navigation->add( |
| 40 | get_string('finalgrades', 'local_finalgrades'), |
| 41 | new moodle_url('/local/finalgrades/index.php', ['id' => $course->id]), |
| 42 | navigation_node::TYPE_SETTING, |
| 43 | null, |
| 44 | 'local_finalgrades', |
| 45 | new pix_icon('i/grades', '') |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Serve the export files to users who may download them. |
| 51 | * |
| 52 | * @param stdClass $course |
| 53 | * @param stdClass|null $cm |
| 54 | * @param context $context |
| 55 | * @param string $filearea |
| 56 | * @param array $args |
| 57 | * @param bool $forcedownload |
| 58 | * @param array $options |
| 59 | * @return bool False when the file is not found. |
| 60 | */ |
| 61 | function local_finalgrades_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) { |
| 62 | if ($context->contextlevel != CONTEXT_SYSTEM || $filearea !== \local_finalgrades\local\exporter::FILEAREA) { |
| 63 | return false; |
| 64 | } |
| 65 | require_login(null, false); |
| 66 | require_capability('local/finalgrades:export', $context); |
| 67 | $itemid = (int) array_shift($args); |
| 68 | $filename = array_pop($args); |
| 69 | $file = get_file_storage()->get_file($context->id, 'local_finalgrades', $filearea, $itemid, '/', $filename); |
| 70 | if (!$file || $file->is_directory()) { |
| 71 | return false; |
| 72 | } |
| 73 | send_stored_file($file, 0, 0, true, $options); |
| 74 | } |