Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
83 / 83 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| integritycase | |
100.00% |
83 / 83 |
|
100.00% |
5 / 5 |
16 | |
100.00% |
1 / 1 |
| get_default_tables | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_default_entity_title | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| initialise | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| get_all_columns | |
100.00% |
37 / 37 |
|
100.00% |
1 / 1 |
8 | |||
| get_all_filters | |
100.00% |
39 / 39 |
|
100.00% |
1 / 1 |
3 | |||
| 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\local\entities; |
| 18 | |
| 19 | use core_reportbuilder\local\entities\base; |
| 20 | use core_reportbuilder\local\filters\{date, select}; |
| 21 | use core_reportbuilder\local\report\{column, filter}; |
| 22 | use lang_string; |
| 23 | use local_integritycase\local\case_manager; |
| 24 | use local_integritycase\local\workflow; |
| 25 | |
| 26 | /** |
| 27 | * Report builder entity for integrity cases. |
| 28 | * |
| 29 | * @package local_integritycase |
| 30 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 31 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 32 | */ |
| 33 | class integritycase extends base { |
| 34 | /** |
| 35 | * Tables used by the entity. |
| 36 | * |
| 37 | * @return string[] |
| 38 | */ |
| 39 | protected function get_default_tables(): array { |
| 40 | return ['local_integritycase']; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Entity title. |
| 45 | * |
| 46 | * @return lang_string |
| 47 | */ |
| 48 | protected function get_default_entity_title(): lang_string { |
| 49 | return new lang_string('entitycase', 'local_integritycase'); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Add the columns, filters and conditions. |
| 54 | * |
| 55 | * @return base |
| 56 | */ |
| 57 | public function initialise(): base { |
| 58 | foreach ($this->get_all_columns() as $column) { |
| 59 | $this->add_column($column); |
| 60 | } |
| 61 | foreach ($this->get_all_filters() as $filter) { |
| 62 | $this->add_filter($filter)->add_condition($filter); |
| 63 | } |
| 64 | return $this; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Columns. |
| 69 | * |
| 70 | * @return column[] |
| 71 | */ |
| 72 | protected function get_all_columns(): array { |
| 73 | $alias = $this->get_table_alias('local_integritycase'); |
| 74 | $columns = []; |
| 75 | $columns[] = (new column('stage', new lang_string('stage', 'local_integritycase'), $this->get_entity_name())) |
| 76 | ->add_joins($this->get_joins()) |
| 77 | ->set_type(column::TYPE_TEXT) |
| 78 | ->add_field("{$alias}.stage") |
| 79 | ->set_is_sortable(true) |
| 80 | ->add_callback(static fn(?string $stage): string => $stage === null ? '' : case_manager::stage_name($stage)); |
| 81 | $columns[] = (new column('outcome', new lang_string('outcome', 'local_integritycase'), $this->get_entity_name())) |
| 82 | ->add_joins($this->get_joins()) |
| 83 | ->set_type(column::TYPE_TEXT) |
| 84 | ->add_field("{$alias}.outcome") |
| 85 | ->set_is_sortable(true) |
| 86 | ->add_callback(static fn(?string $outcome): string => $outcome && workflow::is_outcome($outcome) |
| 87 | ? get_string("outcome:$outcome", 'local_integritycase') : ''); |
| 88 | foreach (['timecreated', 'timemodified', 'timeclosed'] as $name) { |
| 89 | $field = $name; |
| 90 | $columns[] = (new column($name, new lang_string( |
| 91 | $name === 'timeclosed' ? 'timeclosed' : $name, |
| 92 | $name === 'timeclosed' ? 'local_integritycase' : 'core_reportbuilder' |
| 93 | ), $this->get_entity_name())) |
| 94 | ->add_joins($this->get_joins()) |
| 95 | ->set_type(column::TYPE_TIMESTAMP) |
| 96 | ->add_field("{$alias}.{$field}") |
| 97 | ->set_is_sortable(true) |
| 98 | ->add_callback(static fn(?int $value): string => $value ? userdate($value) : ''); |
| 99 | } |
| 100 | $columns[] = (new column( |
| 101 | 'studentvisible', |
| 102 | new lang_string('studentvisible', 'local_integritycase'), |
| 103 | $this->get_entity_name() |
| 104 | )) |
| 105 | ->add_joins($this->get_joins()) |
| 106 | ->set_type(column::TYPE_BOOLEAN) |
| 107 | ->add_field("{$alias}.studentvisible") |
| 108 | ->set_is_sortable(true) |
| 109 | ->add_callback([\core_reportbuilder\local\helpers\format::class, 'boolean_as_text']); |
| 110 | return $columns; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Filters, also used as conditions. |
| 115 | * |
| 116 | * @return filter[] |
| 117 | */ |
| 118 | protected function get_all_filters(): array { |
| 119 | $alias = $this->get_table_alias('local_integritycase'); |
| 120 | $filters = []; |
| 121 | $filters[] = (new filter( |
| 122 | select::class, |
| 123 | 'stage', |
| 124 | new lang_string('stage', 'local_integritycase'), |
| 125 | $this->get_entity_name(), |
| 126 | "{$alias}.stage" |
| 127 | )) |
| 128 | ->add_joins($this->get_joins()) |
| 129 | ->set_options_callback(static function (): array { |
| 130 | $options = []; |
| 131 | foreach (workflow::stages() as $stage) { |
| 132 | $options[$stage] = case_manager::stage_name($stage); |
| 133 | } |
| 134 | return $options; |
| 135 | }); |
| 136 | $filters[] = (new filter( |
| 137 | select::class, |
| 138 | 'outcome', |
| 139 | new lang_string('outcome', 'local_integritycase'), |
| 140 | $this->get_entity_name(), |
| 141 | "{$alias}.outcome" |
| 142 | )) |
| 143 | ->add_joins($this->get_joins()) |
| 144 | ->set_options_callback(static function (): array { |
| 145 | $options = []; |
| 146 | foreach (workflow::outcomes() as $outcome) { |
| 147 | $options[$outcome] = get_string("outcome:$outcome", 'local_integritycase'); |
| 148 | } |
| 149 | return $options; |
| 150 | }); |
| 151 | $filters[] = (new filter( |
| 152 | date::class, |
| 153 | 'timecreated', |
| 154 | new lang_string('timecreated', 'core_reportbuilder'), |
| 155 | $this->get_entity_name(), |
| 156 | "{$alias}.timecreated" |
| 157 | )) |
| 158 | ->add_joins($this->get_joins()); |
| 159 | return $filters; |
| 160 | } |
| 161 | } |