Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.44% covered (success)
94.44%
17 / 18
85.71% covered (warning)
85.71%
6 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
certifications
94.44% covered (success)
94.44%
17 / 18
85.71% covered (warning)
85.71%
6 / 7
7.01
0.00% covered (danger)
0.00%
0 / 1
 get_name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_available
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 initialise
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 get_default_columns
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_default_column_sorting
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_default_filters
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_default_conditions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
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
17namespace local_recertify\reportbuilder\datasource;
18
19use core_reportbuilder\datasource;
20use core_reportbuilder\local\entities\{course, user};
21use local_recertify\reportbuilder\local\entities\certification;
22
23/**
24 * Report source for past certifications across the site, for compliance reporting.
25 *
26 * Only for people with local/recertify:viewall at site level.
27 *
28 * @package    local_recertify
29 * @copyright  2026 DevLMS <contact@devlms.com>
30 * @license    https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 */
32class certifications extends datasource {
33    /**
34     * Source name.
35     *
36     * @return string
37     */
38    public static function get_name(): string {
39        return get_string('certificationsource', 'local_recertify');
40    }
41
42    /**
43     * Only for people allowed to see every learner's history.
44     *
45     * @return bool
46     */
47    public static function is_available(): bool {
48        return has_capability('local/recertify:viewall', \context_system::instance());
49    }
50
51    /**
52     * Join each archived certification to its course and learner.
53     */
54    protected function initialise(): void {
55        $entity = new certification();
56        $alias = $entity->get_table_alias('local_recertify_history');
57        $this->set_main_table('local_recertify_history', $alias);
58        $this->add_entity($entity);
59        $course = new course();
60        $coursealias = $course->get_table_alias('course');
61        $this->add_entity($course->add_join("JOIN {course} {$coursealias} ON {$coursealias}.id = {$alias}.courseid"));
62        $user = new user();
63        $useralias = $user->get_table_alias('user');
64        $this->add_entity($user->add_join("JOIN {user} {$useralias} ON {$useralias}.id = {$alias}.userid"));
65        $this->add_all_from_entities();
66    }
67
68    /**
69     * Columns of a new report.
70     *
71     * @return string[]
72     */
73    public function get_default_columns(): array {
74        return ['course:fullname', 'user:fullname', 'certification:timecompleted', 'certification:timeexpired',
75            'certification:finalgrade'];
76    }
77
78    /**
79     * Sorting of a new report.
80     *
81     * @return int[]
82     */
83    public function get_default_column_sorting(): array {
84        return ['certification:timeexpired' => SORT_DESC];
85    }
86
87    /**
88     * Filters of a new report.
89     *
90     * @return string[]
91     */
92    public function get_default_filters(): array {
93        return ['course:fullname', 'certification:timeexpired'];
94    }
95
96    /**
97     * Conditions of a new report.
98     *
99     * @return string[]
100     */
101    public function get_default_conditions(): array {
102        return ['course:fullname'];
103    }
104}