Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
34 / 34 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| allocation | |
100.00% |
34 / 34 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| export_for_template | |
100.00% |
33 / 33 |
|
100.00% |
1 / 1 |
6 | |||
| 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_doublemark\output; |
| 18 | |
| 19 | use core\output\renderable; |
| 20 | use core\output\renderer_base; |
| 21 | use core\output\templatable; |
| 22 | |
| 23 | /** |
| 24 | * Who marks whom: a first and second marker per student, and the markers to share students out to. |
| 25 | * |
| 26 | * @package local_doublemark |
| 27 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 28 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 29 | */ |
| 30 | class allocation implements renderable, templatable { |
| 31 | /** |
| 32 | * Create the view. |
| 33 | * |
| 34 | * @param \local_doublemark\local\double_marking $dm |
| 35 | */ |
| 36 | public function __construct( |
| 37 | /** @var \local_doublemark\local\double_marking Double marking of the assignment. */ |
| 38 | private readonly \local_doublemark\local\double_marking $dm, |
| 39 | ) { |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Data for local_doublemark/allocation. |
| 44 | * |
| 45 | * @param renderer_base $output |
| 46 | * @return array |
| 47 | */ |
| 48 | public function export_for_template(renderer_base $output): array { |
| 49 | $markers = $this->dm->markers(); |
| 50 | $options = fn(int $chosen) => array_values(array_map(fn($m) => [ |
| 51 | 'id' => (int) $m->id, |
| 52 | 'name' => fullname($m), |
| 53 | 'selected' => (int) $m->id === $chosen, |
| 54 | ], $markers)); |
| 55 | $rows = []; |
| 56 | $unallocated = 0; |
| 57 | foreach ($this->dm->rows() as $row) { |
| 58 | $missing = !$row->marker1 || !$row->marker2; |
| 59 | $unallocated += $missing ? 1 : 0; |
| 60 | $rows[] = [ |
| 61 | 'userid' => $row->userid, |
| 62 | 'name' => $row->name, |
| 63 | 'label1' => get_string('firstmarkerfor', 'local_doublemark', $row->name), |
| 64 | 'label2' => get_string('secondmarkerfor', 'local_doublemark', $row->name), |
| 65 | 'picture' => $row->anonymous ? '' : $output->user_picture($row->user, ['size' => 30, 'link' => false, |
| 66 | 'alttext' => false]), |
| 67 | 'options1' => $options($row->marker1), |
| 68 | 'options2' => $options($row->marker2), |
| 69 | 'missing' => $missing, |
| 70 | // Once a mark is in, changing who marks would orphan it. |
| 71 | 'locked' => $row->mark1 !== null || $row->mark2 !== null, |
| 72 | ]; |
| 73 | } |
| 74 | return [ |
| 75 | 'rows' => $rows, |
| 76 | 'hasrows' => !empty($rows), |
| 77 | 'unallocated' => $unallocated, |
| 78 | 'markers' => array_values(array_map(fn($m) => ['id' => (int) $m->id, 'name' => fullname($m)], $markers)), |
| 79 | 'enoughmarkers' => count($markers) >= 2, |
| 80 | 'cmid' => $this->dm->cmid, |
| 81 | 'sesskey' => sesskey(), |
| 82 | 'actionurl' => (new \moodle_url('/local/doublemark/manage.php'))->out(false), |
| 83 | ]; |
| 84 | } |
| 85 | } |