Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
declare(strict_types=1);
18
 
19
namespace core_role\reportbuilder\datasource;
20
 
21
use core\reportbuilder\local\entities\context;
22
use core_reportbuilder\datasource;
23
use core_reportbuilder\local\entities\user;
24
use core_role\reportbuilder\local\entities\{role, role_assignment};
25
 
26
/**
27
 * Roles datasource
28
 *
29
 * @package     core_role
30
 * @copyright   2024 Paul Holden <paulh@moodle.com>
31
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class roles extends datasource {
34
 
35
    /**
36
     * Return user friendly name of the report source
37
     *
38
     * @return string
39
     */
40
    public static function get_name(): string {
41
        return get_string('roles', 'core_role');
42
    }
43
 
44
    /**
45
     * Initialise report
46
     */
47
    protected function initialise(): void {
48
        $contextentity = new context();
49
        $contextalias = $contextentity->get_table_alias('context');
50
 
51
        $roleentity = new role();
52
        $rolealias = $roleentity->get_table_alias('role');
53
 
54
        // Role table.
55
        $this->add_entity($roleentity->set_table_alias('context', $contextalias));
56
        $this->set_main_table('role', $rolealias);
57
 
58
        // Join role assignments.
59
        $roleassignmententity = new role_assignment();
60
        $roleassignmentalias = $roleassignmententity->get_table_alias('role_assignments');
61
        $this->add_entity($roleassignmententity);
62
        $this->add_join("JOIN {role_assignments} {$roleassignmentalias} ON {$roleassignmentalias}.roleid = {$rolealias}.id");
63
 
64
        // Join context.
65
        $this->add_entity($contextentity);
66
        $this->add_join("LEFT JOIN {context} {$contextalias} ON {$contextalias}.id = {$roleassignmentalias}.contextid");
67
 
68
        // Join user.
69
        $userentity = new user();
70
        $useralias = $userentity->get_table_alias('user');
71
        $this->add_entity($userentity
72
            ->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$roleassignmentalias}.userid"));
73
 
74
        $this->add_all_from_entities();
75
    }
76
 
77
    /**
78
     * Return the columns that will be added to the report upon creation
79
     *
80
     * @return string[]
81
     */
82
    public function get_default_columns(): array {
83
        return [
84
            'context:link',
85
            'role:originalname',
86
            'user:fullnamewithlink',
87
        ];
88
    }
89
 
90
    /**
91
     * Return the column sorting that will be added to the report upon creation
92
     *
93
     * @return int[]
94
     */
95
    public function get_default_column_sorting(): array {
96
        return [
97
            'context:link' => SORT_ASC,
98
            'role:originalname' => SORT_ASC,
99
            'user:fullnamewithlink' => SORT_ASC,
100
        ];
101
    }
102
 
103
    /**
104
     * Return the filters that will be added to the report upon creation
105
     *
106
     * @return string[]
107
     */
108
    public function get_default_filters(): array {
109
        return [
110
            'context:level',
111
            'role:name',
112
            'user:fullname',
113
        ];
114
    }
115
 
116
    /**
117
     * Return the conditions that will be added to the report upon creation
118
     *
119
     * @return string[]
120
     */
121
    public function get_default_conditions(): array {
122
        return [];
123
    }
124
}