Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
97.06% |
33 / 34 |
|
50.00% |
1 / 2 |
CRAP | n/a |
0 / 0 |
|
| local_integritycase_extend_navigation_course | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
4 | |||
| local_integritycase_pluginfile | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
7.02 | |||
| 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 | * Navigation and file serving. |
| 19 | * |
| 20 | * @package local_integritycase |
| 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 "Integrity cases" to the course navigation for staff, and for students with a visible case. |
| 27 | * |
| 28 | * @param navigation_node $navigation |
| 29 | * @param stdClass $course |
| 30 | * @param context_course $context |
| 31 | */ |
| 32 | function local_integritycase_extend_navigation_course(navigation_node $navigation, stdClass $course, context_course $context) { |
| 33 | global $USER; |
| 34 | $url = new moodle_url('/local/integritycase/index.php', ['courseid' => $course->id]); |
| 35 | if (has_capability('local/integritycase:view', $context)) { |
| 36 | $navigation->add( |
| 37 | get_string('cases', 'local_integritycase'), |
| 38 | $url, |
| 39 | navigation_node::TYPE_SETTING, |
| 40 | null, |
| 41 | 'local_integritycase', |
| 42 | new pix_icon('i/report', '') |
| 43 | ); |
| 44 | } else if ( |
| 45 | has_capability('local/integritycase:respond', $context) |
| 46 | && \local_integritycase\local\case_manager::for_student((int) $course->id, (int) $USER->id) |
| 47 | ) { |
| 48 | $navigation->add( |
| 49 | get_string('yourcases', 'local_integritycase'), |
| 50 | $url, |
| 51 | navigation_node::TYPE_SETTING, |
| 52 | null, |
| 53 | 'local_integritycase', |
| 54 | new pix_icon('i/report', '') |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Serve evidence files to staff who can view cases in the course. |
| 61 | * |
| 62 | * @param stdClass $course |
| 63 | * @param stdClass|null $cm |
| 64 | * @param context $context |
| 65 | * @param string $filearea |
| 66 | * @param array $args |
| 67 | * @param bool $forcedownload |
| 68 | * @param array $options |
| 69 | * @return bool false if the file is not found |
| 70 | */ |
| 71 | function local_integritycase_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) { |
| 72 | if ($context->contextlevel != CONTEXT_COURSE || $filearea !== 'evidence') { |
| 73 | return false; |
| 74 | } |
| 75 | require_login($course); |
| 76 | require_capability('local/integritycase:view', $context); |
| 77 | $caseid = (int) array_shift($args); |
| 78 | $case = \local_integritycase\local\case_manager::get($caseid); |
| 79 | if ((int) $case->courseid !== (int) $course->id) { |
| 80 | return false; |
| 81 | } |
| 82 | $filename = array_pop($args); |
| 83 | $filepath = $args ? '/' . implode('/', $args) . '/' : '/'; |
| 84 | $file = get_file_storage()->get_file($context->id, 'local_integritycase', 'evidence', $caseid, $filepath, $filename); |
| 85 | if (!$file || $file->is_directory()) { |
| 86 | return false; |
| 87 | } |
| 88 | send_stored_file($file, 0, 0, true, $options); |
| 89 | } |