Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
33 / 33
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
certification
100.00% covered (success)
100.00%
33 / 33
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 get_default_tables
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_default_entity_title
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 initialise
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
1 / 1
4
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\local\entities;
18
19use core_reportbuilder\local\entities\base;
20use core_reportbuilder\local\filters\date;
21use core_reportbuilder\local\filters\number;
22use core_reportbuilder\local\report\{column, filter};
23use lang_string;
24
25/**
26 * Report builder entity for archived certifications.
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 certification extends base {
33    /**
34     * Tables used by the entity.
35     *
36     * @return string[]
37     */
38    protected function get_default_tables(): array {
39        return ['local_recertify_history'];
40    }
41
42    /**
43     * Entity title.
44     *
45     * @return lang_string
46     */
47    protected function get_default_entity_title(): lang_string {
48        return new lang_string('entitycertification', 'local_recertify');
49    }
50
51    /**
52     * Add the columns, filters and conditions.
53     *
54     * @return base
55     */
56    public function initialise(): base {
57        $alias = $this->get_table_alias('local_recertify_history');
58        foreach (['timecompleted' => 'completed', 'timeexpired' => 'expired'] as $field => $label) {
59            $this->add_column((new column($field, new lang_string($label, 'local_recertify'), $this->get_entity_name()))
60                ->add_joins($this->get_joins())
61                ->set_type(column::TYPE_TIMESTAMP)
62                ->add_field("{$alias}.{$field}")
63                ->set_is_sortable(true)
64                ->add_callback(static fn(?int $value): string => $value ? userdate($value) : ''));
65            $filter = (new filter(
66                date::class,
67                $field,
68                new lang_string($label, 'local_recertify'),
69                $this->get_entity_name(),
70                "{$alias}.{$field}"
71            ))->add_joins($this->get_joins());
72            $this->add_filter($filter)->add_condition($filter);
73        }
74        $this->add_column((new column('finalgrade', new lang_string('finalgrade', 'local_recertify'), $this->get_entity_name()))
75            ->add_joins($this->get_joins())
76            ->set_type(column::TYPE_FLOAT)
77            ->add_field("{$alias}.finalgrade")
78            ->set_is_sortable(true)
79            ->add_callback(static fn(?float $value): string => $value === null ? '' : format_float($value, 2)));
80        $filter = (new filter(
81            number::class,
82            'finalgrade',
83            new lang_string('finalgrade', 'local_recertify'),
84            $this->get_entity_name(),
85            "{$alias}.finalgrade"
86        ))->add_joins($this->get_joins());
87        $this->add_filter($filter)->add_condition($filter);
88        return $this;
89    }
90}