Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.24% |
20 / 21 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
| cases | |
95.24% |
20 / 21 |
|
85.71% |
6 / 7 |
7 | |
0.00% |
0 / 1 |
| get_name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| is_available | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| initialise | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| get_default_columns | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| get_default_column_sorting | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_default_filters | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_default_conditions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | namespace local_integritycase\reportbuilder\datasource; |
| 18 | |
| 19 | use core_reportbuilder\datasource; |
| 20 | use core_reportbuilder\local\entities\{course, user}; |
| 21 | use lang_string; |
| 22 | use local_integritycase\reportbuilder\local\entities\integritycase; |
| 23 | |
| 24 | /** |
| 25 | * Report source for integrity cases across the site. |
| 26 | * |
| 27 | * Only offered to, and only usable by, people with local/integritycase:viewall at site level: a |
| 28 | * custom report built on it shows cases from every course. |
| 29 | * |
| 30 | * @package local_integritycase |
| 31 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 32 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 33 | */ |
| 34 | class cases extends datasource { |
| 35 | /** |
| 36 | * Source name. |
| 37 | * |
| 38 | * @return string |
| 39 | */ |
| 40 | public static function get_name(): string { |
| 41 | return get_string('casesource', 'local_integritycase'); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Only for people allowed to see every case. |
| 46 | * |
| 47 | * @return bool |
| 48 | */ |
| 49 | public static function is_available(): bool { |
| 50 | return has_capability('local/integritycase:viewall', \context_system::instance()); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Join the case to its course, student and handler. |
| 55 | */ |
| 56 | protected function initialise(): void { |
| 57 | $caseentity = new integritycase(); |
| 58 | $alias = $caseentity->get_table_alias('local_integritycase'); |
| 59 | $this->set_main_table('local_integritycase', $alias); |
| 60 | $this->add_entity($caseentity); |
| 61 | |
| 62 | $courseentity = new course(); |
| 63 | $coursealias = $courseentity->get_table_alias('course'); |
| 64 | $this->add_entity($courseentity->add_join("JOIN {course} {$coursealias} ON {$coursealias}.id = {$alias}.courseid")); |
| 65 | |
| 66 | $student = (new user())->set_entity_name('student')->set_entity_title(new lang_string('student', 'local_integritycase')); |
| 67 | $studentalias = $student->get_table_alias('user'); |
| 68 | $this->add_entity($student->add_join("JOIN {user} {$studentalias} ON {$studentalias}.id = {$alias}.studentid")); |
| 69 | |
| 70 | $handler = (new user())->set_entity_name('handler')->set_entity_title(new lang_string('handler', 'local_integritycase')); |
| 71 | $handleralias = $handler->get_table_alias('user'); |
| 72 | $this->add_entity($handler->add_join("LEFT JOIN {user} {$handleralias} ON {$handleralias}.id = {$alias}.handlerid")); |
| 73 | |
| 74 | $this->add_all_from_entities(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Columns of a new report. |
| 79 | * |
| 80 | * @return string[] |
| 81 | */ |
| 82 | public function get_default_columns(): array { |
| 83 | return ['course:fullname', 'student:fullname', 'integritycase:stage', 'integritycase:outcome', |
| 84 | 'integritycase:timecreated']; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Sorting of a new report. |
| 89 | * |
| 90 | * @return int[] |
| 91 | */ |
| 92 | public function get_default_column_sorting(): array { |
| 93 | return ['integritycase:timecreated' => SORT_DESC]; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Filters of a new report. |
| 98 | * |
| 99 | * @return string[] |
| 100 | */ |
| 101 | public function get_default_filters(): array { |
| 102 | return ['integritycase:stage', 'integritycase:outcome', 'course:fullname']; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Conditions of a new report. |
| 107 | * |
| 108 | * @return string[] |
| 109 | */ |
| 110 | public function get_default_conditions(): array { |
| 111 | return ['integritycase:stage']; |
| 112 | } |
| 113 | } |