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 |
namespace report_themeusage\reportbuilder\local\systemreports;
|
|
|
18 |
|
|
|
19 |
use context_system;
|
|
|
20 |
use core_reportbuilder\local\entities\{course, user};
|
|
|
21 |
use core_cohort\reportbuilder\local\entities\cohort;
|
|
|
22 |
use core_course\reportbuilder\local\entities\course_category;
|
|
|
23 |
use core_reportbuilder\local\helpers\database;
|
|
|
24 |
use core_reportbuilder\system_report;
|
|
|
25 |
use core\output\theme_usage;
|
|
|
26 |
use report_themeusage\reportbuilder\local\entities\theme;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Config changes system report class implementation
|
|
|
30 |
*
|
|
|
31 |
* @package report_themeusage
|
|
|
32 |
* @copyright 2023 David Woloszyn <david.woloszyn@moodle.com>
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class theme_usage_report extends system_report {
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Initialise report, we need to set the main table, load our entities and set columns/filters.
|
|
|
39 |
*/
|
|
|
40 |
protected function initialise(): void {
|
|
|
41 |
// Show results depending on the theme and type chosen.
|
|
|
42 |
$themechoice = $this->get_parameter('themechoice', '', PARAM_TEXT);
|
|
|
43 |
$typechoice = $this->get_parameter('typechoice', '', PARAM_TEXT);
|
|
|
44 |
|
|
|
45 |
$themename = get_string('pluginname', 'theme_'.$themechoice);
|
|
|
46 |
|
|
|
47 |
$themeentity = new theme();
|
|
|
48 |
$themealias = $themeentity->get_table_alias('config_plugins');
|
|
|
49 |
$this->set_main_table('config_plugins', $themealias);
|
|
|
50 |
$this->add_entity($themeentity);
|
|
|
51 |
|
|
|
52 |
$param1 = database::generate_param_name();
|
|
|
53 |
$param2 = database::generate_param_name();
|
|
|
54 |
$params = [$param1 => 'theme_' . $themechoice, $param2 => 'version'];
|
|
|
55 |
|
|
|
56 |
$this->add_base_condition_sql("{$themealias}.plugin = :{$param1} AND {$themealias}.name = :{$param2}", $params);
|
|
|
57 |
|
|
|
58 |
switch ($typechoice) {
|
|
|
59 |
|
|
|
60 |
case theme_usage::THEME_USAGE_TYPE_ALL:
|
|
|
61 |
|
|
|
62 |
$this->add_columns_theme();
|
|
|
63 |
$this->set_downloadable(true, get_string('themeusagereportall', 'report_themeusage', $themename));
|
|
|
64 |
|
|
|
65 |
break;
|
|
|
66 |
|
|
|
67 |
case theme_usage::THEME_USAGE_TYPE_USER:
|
|
|
68 |
|
|
|
69 |
$userentity = new user();
|
|
|
70 |
$useralias = $userentity->get_table_alias('user');
|
|
|
71 |
|
|
|
72 |
$this->add_entity($userentity->add_join(
|
|
|
73 |
"JOIN {user} {$useralias}
|
|
|
74 |
ON $useralias.theme = '{$themechoice}'
|
|
|
75 |
AND {$themealias}.plugin = 'theme_{$themechoice}'"));
|
|
|
76 |
|
|
|
77 |
$this->add_columns_user();
|
|
|
78 |
$this->add_filters_user();
|
|
|
79 |
$this->set_downloadable(true, get_string('themeusagereportuser', 'report_themeusage', $themename));
|
|
|
80 |
break;
|
|
|
81 |
|
|
|
82 |
case theme_usage::THEME_USAGE_TYPE_COURSE:
|
|
|
83 |
|
|
|
84 |
$courseentity = new course();
|
|
|
85 |
$coursealias = $courseentity->get_table_alias('course');
|
|
|
86 |
|
|
|
87 |
$this->add_entity($courseentity->add_join(
|
|
|
88 |
"JOIN {course} {$coursealias}
|
|
|
89 |
ON $coursealias.theme = '{$themechoice}'
|
|
|
90 |
AND {$themealias}.plugin = 'theme_{$themechoice}'"));
|
|
|
91 |
|
|
|
92 |
$this->add_columns_course();
|
|
|
93 |
$this->add_filters_course();
|
|
|
94 |
$this->set_downloadable(true, get_string('themeusagereportcourse', 'report_themeusage', $themename));
|
|
|
95 |
break;
|
|
|
96 |
|
|
|
97 |
case theme_usage::THEME_USAGE_TYPE_COHORT:
|
|
|
98 |
|
|
|
99 |
$cohortentity = new cohort();
|
|
|
100 |
$cohortalias = $cohortentity->get_table_alias('cohort');
|
|
|
101 |
|
|
|
102 |
$this->add_entity($cohortentity->add_join(
|
|
|
103 |
"JOIN {cohort} {$cohortalias}
|
|
|
104 |
ON $cohortalias.theme = '{$themechoice}'
|
|
|
105 |
AND {$themealias}.plugin = 'theme_{$themechoice}'"));
|
|
|
106 |
|
|
|
107 |
$this->add_columns_cohort();
|
|
|
108 |
$this->add_filters_cohort();
|
|
|
109 |
$this->set_downloadable(true, get_string('themeusagereportcohort', 'report_themeusage', $themename));
|
|
|
110 |
break;
|
|
|
111 |
|
|
|
112 |
case theme_usage::THEME_USAGE_TYPE_CATEGORY:
|
|
|
113 |
|
|
|
114 |
$categoryentity = new course_category();
|
|
|
115 |
$categoryalias = $categoryentity->get_table_alias('course_categories');
|
|
|
116 |
|
|
|
117 |
$this->add_entity($categoryentity->add_join(
|
|
|
118 |
"JOIN {course_categories} {$categoryalias}
|
|
|
119 |
ON $categoryalias.theme = '{$themechoice}'
|
|
|
120 |
AND {$themealias}.plugin = 'theme_{$themechoice}'"));
|
|
|
121 |
|
|
|
122 |
$this->add_columns_category();
|
|
|
123 |
$this->add_filters_category();
|
|
|
124 |
$this->set_downloadable(true, get_string('themeusagereportcategory', 'report_themeusage', $themename));
|
|
|
125 |
break;
|
|
|
126 |
|
|
|
127 |
default:
|
|
|
128 |
break;
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
/**
|
|
|
133 |
* Validates access to view this report.
|
|
|
134 |
*
|
|
|
135 |
* @return bool
|
|
|
136 |
*/
|
|
|
137 |
protected function can_view(): bool {
|
|
|
138 |
return has_capability('moodle/site:config', context_system::instance());
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
/**
|
|
|
142 |
* Adds the columns we want to display in the report for 'theme'.
|
|
|
143 |
*/
|
|
|
144 |
protected function add_columns_theme(): void {
|
|
|
145 |
$columns = [
|
|
|
146 |
'theme:usagetype',
|
|
|
147 |
'theme:forcetheme',
|
|
|
148 |
];
|
|
|
149 |
|
|
|
150 |
$this->add_columns_from_entities($columns);
|
|
|
151 |
$this->set_initial_sort_column('theme:forcetheme', SORT_ASC);
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* Adds the columns we want to display in the report for 'user'.
|
|
|
156 |
*/
|
|
|
157 |
protected function add_columns_user(): void {
|
|
|
158 |
$columns = [
|
|
|
159 |
'user:firstname',
|
|
|
160 |
'user:lastname',
|
|
|
161 |
'theme:forcetheme',
|
|
|
162 |
];
|
|
|
163 |
|
|
|
164 |
$this->add_columns_from_entities($columns);
|
|
|
165 |
$this->set_initial_sort_column('user:firstname', SORT_ASC);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
/**
|
|
|
169 |
* Adds the filters we want to display in the report for 'user'.
|
|
|
170 |
*/
|
|
|
171 |
protected function add_filters_user(): void {
|
|
|
172 |
$filters = [
|
|
|
173 |
'user:firstname',
|
|
|
174 |
'user:lastname',
|
|
|
175 |
];
|
|
|
176 |
|
|
|
177 |
$this->add_filters_from_entities($filters);
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
/**
|
|
|
181 |
* Adds the columns we want to display in the report for 'course'.
|
|
|
182 |
*/
|
|
|
183 |
protected function add_columns_course(): void {
|
|
|
184 |
$columns = [
|
|
|
185 |
'course:fullname',
|
|
|
186 |
'course:shortname',
|
|
|
187 |
'theme:forcetheme',
|
|
|
188 |
];
|
|
|
189 |
|
|
|
190 |
$this->add_columns_from_entities($columns);
|
|
|
191 |
$this->set_initial_sort_column('course:fullname', SORT_ASC);
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
/**
|
|
|
195 |
* Adds the filters we want to display in the report for 'course'.
|
|
|
196 |
*/
|
|
|
197 |
protected function add_filters_course(): void {
|
|
|
198 |
$filters = [
|
|
|
199 |
'course:fullname',
|
|
|
200 |
'course:shortname',
|
|
|
201 |
];
|
|
|
202 |
|
|
|
203 |
$this->add_filters_from_entities($filters);
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
/**
|
|
|
207 |
* Adds the columns we want to display in the report for 'cohort'.
|
|
|
208 |
*/
|
|
|
209 |
protected function add_columns_cohort(): void {
|
|
|
210 |
$columns = [
|
|
|
211 |
'cohort:name',
|
|
|
212 |
'cohort:context',
|
|
|
213 |
'theme:forcetheme',
|
|
|
214 |
];
|
|
|
215 |
|
|
|
216 |
$this->add_columns_from_entities($columns);
|
|
|
217 |
$this->set_initial_sort_column('cohort:name', SORT_ASC);
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
/**
|
|
|
221 |
* Adds the filters we want to display in the report for 'cohort'.
|
|
|
222 |
*/
|
|
|
223 |
protected function add_filters_cohort(): void {
|
|
|
224 |
$filters = [
|
|
|
225 |
'cohort:name',
|
|
|
226 |
'cohort:context',
|
|
|
227 |
];
|
|
|
228 |
|
|
|
229 |
$this->add_filters_from_entities($filters);
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
/**
|
|
|
233 |
* Adds the columns we want to display in the report for 'category'.
|
|
|
234 |
*/
|
|
|
235 |
protected function add_columns_category(): void {
|
|
|
236 |
$columns = [
|
|
|
237 |
'course_category:name',
|
|
|
238 |
'course_category:coursecount',
|
|
|
239 |
'theme:forcetheme',
|
|
|
240 |
];
|
|
|
241 |
|
|
|
242 |
$this->add_columns_from_entities($columns);
|
|
|
243 |
$this->set_initial_sort_column('course_category:name', SORT_ASC);
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
/**
|
|
|
247 |
* Adds the filters we want to display in the report for 'category'.
|
|
|
248 |
*/
|
|
|
249 |
protected function add_filters_category(): void {
|
|
|
250 |
$filters = [
|
|
|
251 |
'course_category:name',
|
|
|
252 |
];
|
|
|
253 |
|
|
|
254 |
$this->add_filters_from_entities($filters);
|
|
|
255 |
}
|
|
|
256 |
}
|