Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
59 / 59 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| overview | |
100.00% |
59 / 59 |
|
100.00% |
2 / 2 |
11 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| export_for_template | |
100.00% |
58 / 58 |
|
100.00% |
1 / 1 |
9 | |||
| 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 | use local_doublemark\local\display; |
| 23 | use local_doublemark\local\double_marking; |
| 24 | use local_doublemark\local\reconciler; |
| 25 | |
| 26 | /** |
| 27 | * The lead's view of an assignment: who marks whom, both marks, the gap and what is left to do. |
| 28 | * |
| 29 | * @package local_doublemark |
| 30 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 31 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 32 | */ |
| 33 | class overview implements renderable, templatable { |
| 34 | /** @var array Filter tiles and the statuses each one covers, in display order. */ |
| 35 | public const GROUPS = [ |
| 36 | 'marking' => [double_marking::UNALLOCATED, reconciler::MARKING], |
| 37 | 'reconcile' => [reconciler::RECONCILE], |
| 38 | 'ready' => [reconciler::AGREED, double_marking::RESOLVED], |
| 39 | 'released' => [double_marking::RELEASED], |
| 40 | ]; |
| 41 | |
| 42 | /** @var string Active filter: all or a key of GROUPS. */ |
| 43 | private string $filter; |
| 44 | |
| 45 | /** |
| 46 | * Create the overview. |
| 47 | * |
| 48 | * @param double_marking $dm |
| 49 | * @param string $filter |
| 50 | */ |
| 51 | public function __construct( |
| 52 | /** @var float*/ |
| 53 | private readonly double_marking $dm, |
| 54 | string $filter, |
| 55 | ) { |
| 56 | $this->filter = isset(self::GROUPS[$filter]) ? $filter : 'all'; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Data for local_doublemark/overview. |
| 61 | * |
| 62 | * @param renderer_base $output |
| 63 | * @return array |
| 64 | */ |
| 65 | public function export_for_template(renderer_base $output): array { |
| 66 | $rows = $this->dm->rows(); |
| 67 | $markers = $this->dm->markers(); |
| 68 | $name = fn(int $id) => isset($markers[$id]) ? fullname($markers[$id]) : ''; |
| 69 | $url = fn(array $params) => (new \moodle_url('/local/doublemark/manage.php', ['cmid' => $this->dm->cmid] + $params)) |
| 70 | ->out(false); |
| 71 | |
| 72 | $tiles = []; |
| 73 | foreach (self::GROUPS as $group => $statuses) { |
| 74 | $tiles[] = [ |
| 75 | 'name' => $group, |
| 76 | 'label' => get_string('group:' . $group, 'local_doublemark'), |
| 77 | 'count' => count(array_filter($rows, fn($r) => in_array($r->status, $statuses, true))), |
| 78 | 'url' => $url(['filter' => $this->filter === $group ? 'all' : $group]), |
| 79 | 'active' => $this->filter === $group, |
| 80 | ]; |
| 81 | } |
| 82 | |
| 83 | $shown = $this->filter === 'all' ? $rows |
| 84 | : array_filter($rows, fn($r) => in_array($r->status, self::GROUPS[$this->filter], true)); |
| 85 | $list = []; |
| 86 | foreach ($shown as $row) { |
| 87 | $agreeurl = new \moodle_url('/local/doublemark/agree.php', ['cmid' => $this->dm->cmid, 'userid' => $row->userid]); |
| 88 | $canagree = in_array($row->status, [reconciler::AGREED, reconciler::RECONCILE, double_marking::RESOLVED], true); |
| 89 | $list[] = [ |
| 90 | 'userid' => $row->userid, |
| 91 | 'name' => $row->name, |
| 92 | 'picture' => $row->anonymous ? '' : $output->user_picture($row->user, ['size' => 30, 'link' => false, |
| 93 | 'alttext' => false]), |
| 94 | 'marker1' => $name($row->marker1), |
| 95 | 'marker2' => $name($row->marker2), |
| 96 | 'mark1' => display::grade($row->mark1?->grade), |
| 97 | 'mark2' => display::grade($row->mark2?->grade), |
| 98 | 'gap' => display::grade($row->gap), |
| 99 | 'wide' => $row->gap !== null && $row->gap > $this->dm->tolerance(), |
| 100 | 'agreed' => display::grade($row->agreed), |
| 101 | 'status' => $row->status, |
| 102 | 'statuslabel' => display::status_label($row->status), |
| 103 | 'badge' => display::badge($row->status), |
| 104 | 'needsyou' => $row->status === reconciler::RECONCILE, |
| 105 | 'canagree' => $canagree, |
| 106 | 'agreeurl' => $agreeurl->out(false), |
| 107 | 'gradedoutside' => $row->gradedoutside, |
| 108 | ]; |
| 109 | } |
| 110 | $releasecount = count(array_filter($rows, fn($r) => in_array($r->status, self::GROUPS['ready'], true))); |
| 111 | return [ |
| 112 | 'tiles' => $tiles, |
| 113 | 'rows' => array_values($list), |
| 114 | 'hasrows' => !empty($list), |
| 115 | 'emptymessage' => get_string($rows ? 'emptygroup' : 'nostudents', 'local_doublemark'), |
| 116 | 'rulesummary' => get_string( |
| 117 | 'rulesummary:' . $this->dm->rule(), |
| 118 | 'local_doublemark', |
| 119 | display::grade($this->dm->tolerance()) |
| 120 | ), |
| 121 | 'releasecount' => $releasecount, |
| 122 | 'canrelease' => $releasecount > 0, |
| 123 | 'releaselabel' => get_string('release', 'local_doublemark', $releasecount), |
| 124 | 'releaseurl' => (new \moodle_url('/local/doublemark/manage.php'))->out(false), |
| 125 | 'cmid' => $this->dm->cmid, |
| 126 | 'sesskey' => sesskey(), |
| 127 | ]; |
| 128 | } |
| 129 | } |