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_badges\reportbuilder\local\systemreports;
|
|
|
20 |
|
|
|
21 |
use core_badges\reportbuilder\local\entities\badge_issued;
|
|
|
22 |
use core_reportbuilder\local\report\action;
|
|
|
23 |
use core_reportbuilder\system_report;
|
|
|
24 |
use lang_string;
|
|
|
25 |
use moodle_url;
|
|
|
26 |
use pix_icon;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Badge recipients system report class implementation
|
|
|
30 |
*
|
|
|
31 |
* @package core_badges
|
|
|
32 |
* @copyright 2023 David Carrillo <davidmc@moodle.com>
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class recipients 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 |
// Our main entity, it contains all of the column definitions that we need.
|
|
|
42 |
$badgeissuedentity = new badge_issued();
|
|
|
43 |
$entityalias = $badgeissuedentity->get_table_alias('badge_issued');
|
|
|
44 |
|
|
|
45 |
$this->set_main_table('badge_issued', $entityalias);
|
|
|
46 |
$this->add_entity($badgeissuedentity);
|
|
|
47 |
|
|
|
48 |
$userentity = new \core_reportbuilder\local\entities\user();
|
|
|
49 |
$entityuseralias = $userentity->get_table_alias('user');
|
|
|
50 |
$this->add_entity($userentity
|
|
|
51 |
->add_joins($userentity->get_joins())
|
|
|
52 |
->add_join("JOIN {user} {$entityuseralias}
|
|
|
53 |
ON {$entityuseralias}.id = {$entityalias}.userid")
|
|
|
54 |
);
|
|
|
55 |
|
|
|
56 |
$this->add_base_condition_simple('badgeid', $this->get_parameter('badgeid', 0, PARAM_INT));
|
|
|
57 |
|
|
|
58 |
$this->add_base_fields("{$entityalias}.uniquehash");
|
|
|
59 |
|
|
|
60 |
// Now we can call our helper methods to add the content we want to include in the report.
|
|
|
61 |
$this->add_columns();
|
|
|
62 |
$this->add_filters();
|
|
|
63 |
$this->add_actions();
|
|
|
64 |
|
|
|
65 |
// Set if report can be downloaded.
|
|
|
66 |
$this->set_downloadable(false);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Validates access to view this report
|
|
|
71 |
*
|
|
|
72 |
* @return bool
|
|
|
73 |
*/
|
|
|
74 |
protected function can_view(): bool {
|
|
|
75 |
return has_capability('moodle/badges:viewawarded', $this->get_context());
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Adds the columns we want to display in the report
|
|
|
80 |
*
|
|
|
81 |
* They are provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
|
|
82 |
* unique identifier. If custom columns are needed just for this report, they can be defined here.
|
|
|
83 |
*/
|
|
|
84 |
public function add_columns(): void {
|
|
|
85 |
$columns = [
|
|
|
86 |
'user:fullnamewithlink',
|
|
|
87 |
'badge_issued:issued',
|
|
|
88 |
];
|
|
|
89 |
|
|
|
90 |
$this->add_columns_from_entities($columns);
|
|
|
91 |
$this->set_initial_sort_column('badge_issued:issued', SORT_DESC);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Adds the filters we want to display in the report
|
|
|
96 |
*
|
|
|
97 |
* They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
|
|
98 |
* unique identifier
|
|
|
99 |
*/
|
|
|
100 |
protected function add_filters(): void {
|
|
|
101 |
$filters = [
|
|
|
102 |
'user:fullname',
|
|
|
103 |
'badge_issued:issued',
|
|
|
104 |
];
|
|
|
105 |
|
|
|
106 |
$this->add_filters_from_entities($filters);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Add the system report actions. An extra column will be appended to each row, containing all actions added here
|
|
|
111 |
*
|
|
|
112 |
* Note the use of ":uniquehash" placeholder which will be substituted according to actual values in the row
|
|
|
113 |
*/
|
|
|
114 |
protected function add_actions(): void {
|
|
|
115 |
$this->add_action((new action(
|
|
|
116 |
new moodle_url('/badges/badge.php', [
|
|
|
117 |
'hash' => ':uniquehash',
|
|
|
118 |
]),
|
|
|
119 |
new pix_icon('i/search', '', 'core'),
|
|
|
120 |
[],
|
|
|
121 |
false,
|
|
|
122 |
new lang_string('viewbadge', 'badges')
|
|
|
123 |
)));
|
|
|
124 |
}
|
|
|
125 |
}
|