Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| transcript | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| context | |
100.00% |
18 / 18 |
|
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 | /** |
| 18 | * Turns stored transcript data into template context. |
| 19 | * |
| 20 | * @package local_transcript |
| 21 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 22 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | */ |
| 24 | |
| 25 | namespace local_transcript\output; |
| 26 | |
| 27 | /** |
| 28 | * Template context for local_transcript/transcript. |
| 29 | * |
| 30 | * @package local_transcript |
| 31 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 32 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 33 | */ |
| 34 | class transcript { |
| 35 | /** |
| 36 | * Context for the template, escaped by Mustache. |
| 37 | * |
| 38 | * @param array $data From collector::collect or a stored payload. |
| 39 | * @param string $code Empty for a preview. |
| 40 | * @param int $issued Issue time, 0 for a preview. |
| 41 | * @return array |
| 42 | */ |
| 43 | public static function context(array $data, string $code = '', int $issued = 0): array { |
| 44 | $fmt = get_string('strftimedate', 'langconfig'); |
| 45 | $courses = array_map(fn($c) => [ |
| 46 | 'shortname' => $c['shortname'], |
| 47 | 'fullname' => $c['fullname'], |
| 48 | 'grade' => $c['grade'], |
| 49 | 'completed' => $c['completed'] ? userdate($c['completed'], $fmt) : '', |
| 50 | ], $data['courses'] ?? []); |
| 51 | return [ |
| 52 | 'institution' => $data['institution'] ?? '', |
| 53 | 'fullname' => $data['student']['fullname'] ?? '', |
| 54 | 'idnumber' => $data['student']['idnumber'] ?? '', |
| 55 | 'hasidnumber' => !empty($data['student']['idnumber']), |
| 56 | 'code' => $code, |
| 57 | 'issued' => $issued ? userdate($issued, $fmt) : '', |
| 58 | 'courses' => $courses, |
| 59 | 'hascourses' => !empty($courses), |
| 60 | 'showgrades' => (bool) array_filter(array_column($courses, 'grade'), fn($g) => $g !== ''), |
| 61 | ]; |
| 62 | } |
| 63 | } |