Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
16
 
17
namespace core_ai\reportbuilder\local\systemreports;
18
 
19
use core_ai\reportbuilder\local\entities\ai_policy_register;
20
use core_reportbuilder\system_report;
21
use core_reportbuilder\local\entities\user;
22
 
23
/**
24
 * AI policy acceptance system report.
25
 *
26
 * @package    core_ai
27
 * @copyright  2024 David Woloszyn <david.woloszyn@moodle.com>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class policy_acceptance extends system_report {
31
 
32
    #[\Override]
33
    protected function initialise(): void {
34
        $entitymain = new ai_policy_register();
35
        $entitymainalias = $entitymain->get_table_alias('ai_policy_register');
36
 
37
        $this->set_main_table('ai_policy_register', $entitymainalias);
38
        $this->add_entity($entitymain);
39
 
40
        // Join the 'user' entity to our main entity.
41
        $entityuser = new user();
42
        $entituseralias = $entityuser->get_table_alias('user');
43
        $this->add_entity($entityuser->add_join(
44
            "LEFT JOIN {user} {$entituseralias} ON {$entituseralias}.id = {$entitymainalias}.userid"
45
        ));
46
 
47
        // Any columns required by actions should be defined here to ensure they're always available.
48
        $this->add_base_fields("{$entitymainalias}.id, {$entitymainalias}.userid");
49
 
50
        // Now we can call our helper methods to add the content we want to include in the report.
51
        $this->add_columns();
52
        $this->add_filters();
53
 
54
        // Set if report can be downloaded.
55
        $this->set_downloadable(true, get_string('aipolicyacceptance', 'core_ai'));
56
    }
57
 
58
    #[\Override]
59
    protected function can_view(): bool {
60
        return has_capability('moodle/ai:viewaipolicyacceptancereport', $this->get_context());
61
    }
62
 
63
    #[\Override]
64
    public static function get_name(): string {
65
        return get_string('aipolicyacceptance', 'core_ai');
66
    }
67
 
68
    /**
69
     * Adds the columns we want to display in the report.
70
     *
71
     * They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
72
     * unique identifier.
73
     */
74
    public function add_columns(): void {
75
        $columns = [
76
            'user:fullnamewithlink',
77
            'ai_policy_register:timeaccepted',
78
        ];
79
 
80
        $this->add_columns_from_entities($columns);
81
 
82
        // It's possible to set a default initial sort direction for one column.
83
        $this->set_initial_sort_column('ai_policy_register:timeaccepted', SORT_DESC);
84
    }
85
 
86
    /**
87
     * Adds the filters we want to display in the report.
88
     *
89
     * They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
90
     * unique identifier.
91
     */
92
    protected function add_filters(): void {
93
        $filters = [
94
            'user:fullname',
95
            'ai_policy_register:timeaccepted',
96
        ];
97
 
98
        $this->add_filters_from_entities($filters);
99
    }
100
}