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 |
declare(strict_types=1);
|
|
|
18 |
|
|
|
19 |
namespace core_competency\reportbuilder\datasource;
|
|
|
20 |
|
|
|
21 |
use core\reportbuilder\local\entities\context;
|
|
|
22 |
use core_cohort\reportbuilder\local\entities\cohort;
|
|
|
23 |
use core_competency\reportbuilder\local\entities\{competency, framework, usercompetency};
|
|
|
24 |
use core_reportbuilder\datasource;
|
|
|
25 |
use core_reportbuilder\local\entities\user;
|
|
|
26 |
use core_reportbuilder\local\filters\boolean_select;
|
|
|
27 |
use core_reportbuilder\local\helpers\database;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Competencies datasource
|
|
|
31 |
*
|
|
|
32 |
* @package core_competency
|
|
|
33 |
* @copyright 2024 Paul Holden <paulh@moodle.com>
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class competencies extends datasource {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Return user friendly name of the report source
|
|
|
40 |
*
|
|
|
41 |
* @return string
|
|
|
42 |
*/
|
|
|
43 |
public static function get_name(): string {
|
|
|
44 |
return get_string('competencies', 'core_competency');
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Initialise report
|
|
|
49 |
*/
|
|
|
50 |
protected function initialise(): void {
|
|
|
51 |
$frameworkentity = new framework();
|
|
|
52 |
$frameworkalias = $frameworkentity->get_table_alias('competency_framework');
|
|
|
53 |
|
|
|
54 |
$contextentity = new context();
|
|
|
55 |
$contextalias = $contextentity->get_table_alias('context');
|
|
|
56 |
|
|
|
57 |
$this->set_main_table('competency_framework', $frameworkalias);
|
|
|
58 |
|
|
|
59 |
// Join context entity (unconditionally, as table also used by both framework/competency entities).
|
|
|
60 |
$this->add_join("LEFT JOIN {context} {$contextalias} ON {$contextalias}.id = {$frameworkalias}.contextid");
|
|
|
61 |
$this->add_entity($contextentity);
|
|
|
62 |
|
|
|
63 |
$this->add_entity($frameworkentity
|
|
|
64 |
->set_table_join_alias('context', $contextalias)
|
|
|
65 |
);
|
|
|
66 |
|
|
|
67 |
// Join competency entity.
|
|
|
68 |
$competencyentity = new competency();
|
|
|
69 |
$competencyalias = $competencyentity->get_table_alias('competency');
|
|
|
70 |
$this->add_entity($competencyentity
|
|
|
71 |
->set_table_join_alias('context', $contextalias)
|
|
|
72 |
->add_join("LEFT JOIN {competency} {$competencyalias}
|
|
|
73 |
ON {$competencyalias}.competencyframeworkid = {$frameworkalias}.id")
|
|
|
74 |
);
|
|
|
75 |
|
|
|
76 |
// Join user competency entity.
|
|
|
77 |
$usercompetencyentity = new usercompetency();
|
|
|
78 |
$usercompetencyalias = $usercompetencyentity->get_table_alias('competency_usercomp');
|
|
|
79 |
$this->add_entity($usercompetencyentity
|
|
|
80 |
->add_joins($competencyentity->get_joins())
|
|
|
81 |
->add_join("LEFT JOIN {competency_usercomp} {$usercompetencyalias}
|
|
|
82 |
ON {$usercompetencyalias}.competencyid = {$competencyalias}.id")
|
|
|
83 |
);
|
|
|
84 |
|
|
|
85 |
// Join user entity.
|
|
|
86 |
$userentity = new user();
|
|
|
87 |
$useralias = $userentity->get_table_alias('user');
|
|
|
88 |
$this->add_entity($userentity
|
|
|
89 |
->add_joins($usercompetencyentity->get_joins())
|
|
|
90 |
->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$usercompetencyalias}.userid")
|
|
|
91 |
);
|
|
|
92 |
|
|
|
93 |
// Join cohort entity.
|
|
|
94 |
$cohortentity = new cohort();
|
|
|
95 |
$cohortalias = $cohortentity->get_table_alias('cohort');
|
|
|
96 |
$cohortmemberalias = database::generate_alias();
|
|
|
97 |
$this->add_entity($cohortentity
|
|
|
98 |
->add_joins($userentity->get_joins())
|
|
|
99 |
->add_joins([
|
|
|
100 |
"LEFT JOIN {cohort_members} {$cohortmemberalias} ON {$cohortmemberalias}.userid = {$useralias}.id",
|
|
|
101 |
"LEFT JOIN {cohort} {$cohortalias} ON {$cohortalias}.id = {$cohortmemberalias}.cohortid",
|
|
|
102 |
])
|
|
|
103 |
);
|
|
|
104 |
|
|
|
105 |
// Add report elements from each of the entities we added to the report.
|
|
|
106 |
$this->add_all_from_entities([
|
|
|
107 |
$contextentity->get_entity_name(),
|
|
|
108 |
$frameworkentity->get_entity_name(),
|
|
|
109 |
$competencyentity->get_entity_name(),
|
|
|
110 |
$usercompetencyentity->get_entity_name(),
|
|
|
111 |
$userentity->get_entity_name(),
|
|
|
112 |
]);
|
|
|
113 |
|
|
|
114 |
$this->add_all_from_entity(
|
|
|
115 |
$cohortentity->get_entity_name(),
|
|
|
116 |
['name', 'idnumber', 'description', 'customfield*'],
|
|
|
117 |
['cohortselect', 'name', 'idnumber', 'customfield*'],
|
|
|
118 |
['cohortselect', 'name', 'idnumber', 'customfield*'],
|
|
|
119 |
);
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
* Return the columns that will be added to the report upon creation
|
|
|
124 |
*
|
|
|
125 |
* @return string[]
|
|
|
126 |
*/
|
|
|
127 |
public function get_default_columns(): array {
|
|
|
128 |
return [
|
|
|
129 |
'framework:name',
|
|
|
130 |
'competency:name',
|
|
|
131 |
'user:fullname',
|
|
|
132 |
'usercompetency:proficient',
|
|
|
133 |
];
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
/**
|
|
|
137 |
* Return the column sorting that will be added to the report upon creation
|
|
|
138 |
*
|
|
|
139 |
* @return int[]
|
|
|
140 |
*/
|
|
|
141 |
public function get_default_column_sorting(): array {
|
|
|
142 |
return [
|
|
|
143 |
'framework:name' => SORT_ASC,
|
|
|
144 |
'competency:name' => SORT_ASC,
|
|
|
145 |
'user:fullname' => SORT_ASC,
|
|
|
146 |
];
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* Return the filters that will be added to the report upon creation
|
|
|
151 |
*
|
|
|
152 |
* @return string[]
|
|
|
153 |
*/
|
|
|
154 |
public function get_default_filters(): array {
|
|
|
155 |
return [
|
|
|
156 |
'competency:name',
|
|
|
157 |
'user:fullname',
|
|
|
158 |
];
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
/**
|
|
|
162 |
* Return the conditions that will be added to the report upon creation
|
|
|
163 |
*
|
|
|
164 |
* @return string[]
|
|
|
165 |
*/
|
|
|
166 |
public function get_default_conditions(): array {
|
|
|
167 |
return [
|
|
|
168 |
'framework:visible',
|
|
|
169 |
];
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/**
|
|
|
173 |
* Return the condition values that will be added to the report upon creation
|
|
|
174 |
*
|
|
|
175 |
* @return array
|
|
|
176 |
*/
|
|
|
177 |
public function get_default_condition_values(): array {
|
|
|
178 |
return [
|
|
|
179 |
'framework:visible_operator' => boolean_select::CHECKED,
|
|
|
180 |
];
|
|
|
181 |
}
|
|
|
182 |
}
|