| Línea 16... |
Línea 16... |
| 16 |
|
16 |
|
| Línea 17... |
Línea 17... |
| 17 |
declare(strict_types=1);
|
17 |
declare(strict_types=1);
|
| Línea -... |
Línea 18... |
| - |
|
18 |
|
| 18 |
|
19 |
namespace core_badges\reportbuilder\local\systemreports;
|
| 19 |
namespace core_badges\reportbuilder\local\systemreports;
|
20 |
|
| - |
|
21 |
use core\context\system;
|
| 20 |
|
22 |
use core_badges\reportbuilder\local\entities\badge;
|
| 21 |
use core_badges\reportbuilder\local\entities\badge;
|
23 |
use core_badges\reportbuilder\local\entities\badge_issued;
|
| 22 |
use core_badges\reportbuilder\local\entities\badge_issued;
|
24 |
use core_reportbuilder\local\helpers\database;
|
| 23 |
use core_reportbuilder\system_report;
|
25 |
use core_reportbuilder\system_report;
|
| 24 |
use lang_string;
|
26 |
use lang_string;
|
| Línea 35... |
Línea 37... |
| 35 |
* Course badges system report class implementation
|
37 |
* Course badges system report class implementation
|
| 36 |
*
|
38 |
*
|
| 37 |
* @package core_badges
|
39 |
* @package core_badges
|
| 38 |
* @copyright 2023 David Carrillo <davidmc@moodle.com>
|
40 |
* @copyright 2023 David Carrillo <davidmc@moodle.com>
|
| 39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
41 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| - |
|
42 |
* @deprecated since 4.5. Use badges system_report instead.
|
| - |
|
43 |
* @todo MDL-82383 This class will be deleted in Moodle 6.0.
|
| 40 |
*/
|
44 |
*/
|
| 41 |
class course_badges extends system_report {
|
45 |
class course_badges extends system_report {
|
| Línea 42... |
Línea 46... |
| 42 |
|
46 |
|
| 43 |
/**
|
47 |
/**
|
| - |
|
48 |
* Initialise report, we need to set the main table, load our entities and set columns/filters
|
| - |
|
49 |
*
|
| 44 |
* Initialise report, we need to set the main table, load our entities and set columns/filters
|
50 |
* @deprecated since 4.5. Use badges system_report instead.
|
| - |
|
51 |
*/
|
| 45 |
*/
|
52 |
#[\core\attribute\deprecated('course_badges::initialise', since: '4.5', mdl: 'MDL-82503')]
|
| - |
|
53 |
protected function initialise(): void {
|
| 46 |
protected function initialise(): void {
|
54 |
\core\deprecation::emit_deprecation([$this, __FUNCTION__]);
|
| 47 |
global $USER;
|
55 |
global $USER;
|
| 48 |
// Our main entity, it contains all of the column definitions that we need.
|
56 |
// Our main entity, it contains all of the column definitions that we need.
|
| 49 |
$badgeentity = new badge();
|
57 |
$badgeentity = new badge();
|
| Línea 50... |
Línea 58... |
| 50 |
$entityalias = $badgeentity->get_table_alias('badge');
|
58 |
$entityalias = $badgeentity->get_table_alias('badge');
|
| 51 |
|
59 |
|
| Línea 52... |
Línea 60... |
| 52 |
$this->set_main_table('badge', $entityalias);
|
60 |
$this->set_main_table('badge', $entityalias);
|
| 53 |
$this->add_entity($badgeentity);
|
61 |
$this->add_entity($badgeentity);
|
| - |
|
62 |
|
| - |
|
63 |
$paramtype = database::generate_param_name();
|
| - |
|
64 |
$context = $this->get_context();
|
| - |
|
65 |
if ($context instanceof system) {
|
| - |
|
66 |
$type = BADGE_TYPE_SITE;
|
| - |
|
67 |
$this->add_base_condition_sql("{$entityalias}.type = :$paramtype", [$paramtype => $type]);
|
| - |
|
68 |
} else {
|
| - |
|
69 |
$type = BADGE_TYPE_COURSE;
|
| - |
|
70 |
$paramcourseid = database::generate_param_name();
|
| Línea 54... |
Línea -... |
| 54 |
|
- |
|
| 55 |
$type = $this->get_parameter('type', 0, PARAM_INT);
|
- |
|
| 56 |
$courseid = $this->get_parameter('courseid', 0, PARAM_INT);
|
71 |
$this->add_base_condition_sql("{$entityalias}.type = :$paramtype AND {$entityalias}.courseid = :$paramcourseid",
|
| 57 |
|
72 |
[$paramtype => $type, $paramcourseid => $context->instanceid]);
|
| Línea 58... |
Línea 73... |
| 58 |
$this->add_base_condition_simple('type', $type);
|
73 |
}
|
| 59 |
$this->add_base_condition_simple('courseid', $courseid);
|
74 |
|
| 60 |
$this->add_base_condition_sql("({$entityalias}.status = " . BADGE_STATUS_ACTIVE .
|
75 |
$this->add_base_condition_sql("({$entityalias}.status = " . BADGE_STATUS_ACTIVE .
|
| Línea 68... |
Línea 83... |
| 68 |
);
|
83 |
);
|
| Línea 69... |
Línea 84... |
| 69 |
|
84 |
|
| Línea 70... |
Línea 85... |
| 70 |
$this->add_base_fields("{$badgeissuedalias}.uniquehash");
|
85 |
$this->add_base_fields("{$badgeissuedalias}.uniquehash");
|
| 71 |
|
86 |
|
| 72 |
// Now we can call our helper methods to add the content we want to include in the report.
|
87 |
// Now we can call our helper methods to add the content we want to include in the report.
|
| Línea -... |
Línea 88... |
| - |
|
88 |
$this->add_columns();
|
| - |
|
89 |
$this->add_filters();
|
| - |
|
90 |
|
| 73 |
$this->add_columns($badgeissuedalias);
|
91 |
$this->set_initial_sort_column('badge:name', SORT_ASC);
|
| 74 |
$this->add_filters();
|
92 |
$this->set_default_no_results_notice(new lang_string('nomatchingbadges', 'core_badges'));
|
| 75 |
|
93 |
|
| Línea 76... |
Línea 94... |
| 76 |
// Set if report can be downloaded.
|
94 |
// Set if report can be downloaded.
|
| 77 |
$this->set_downloadable(false);
|
95 |
$this->set_downloadable(false);
|
| 78 |
}
|
96 |
}
|
| 79 |
|
97 |
|
| - |
|
98 |
/**
|
| 80 |
/**
|
99 |
* Validates access to view this report
|
| - |
|
100 |
*
|
| 81 |
* Validates access to view this report
|
101 |
* @return bool
|
| - |
|
102 |
* @deprecated since 4.5. Use badges system_report instead.
|
| 82 |
*
|
103 |
*/
|
| 83 |
* @return bool
|
104 |
#[\core\attribute\deprecated('course_badges::can_view', since: '4.5', mdl: 'MDL-82503')]
|
| Línea 84... |
Línea 105... |
| 84 |
*/
|
105 |
protected function can_view(): bool {
|
| 85 |
protected function can_view(): bool {
|
106 |
\core\deprecation::emit_deprecation([$this, __FUNCTION__]);
|
| 86 |
return has_capability('moodle/badges:viewbadges', $this->get_context());
|
107 |
return has_capability('moodle/badges:viewbadges', $this->get_context());
|
| 87 |
}
|
108 |
}
|
| 88 |
|
109 |
|
| 89 |
/**
|
110 |
/**
|
| 90 |
* Adds the columns we want to display in the report
|
111 |
* Adds the columns we want to display in the report
|
| - |
|
112 |
*
|
| 91 |
*
|
113 |
* They are provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
| - |
|
114 |
* unique identifier. If custom columns are needed just for this report, they can be defined here.
|
| 92 |
* They are provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
115 |
*
|
| - |
|
116 |
* @param string $badgeissuedalias
|
| - |
|
117 |
* @deprecated since 4.5. Use badges system_report instead.
|
| - |
|
118 |
*/
|
| 93 |
* unique identifier. If custom columns are needed just for this report, they can be defined here.
|
119 |
#[\core\attribute\deprecated('course_badges::add_columns', since: '4.5', mdl: 'MDL-82503')]
|
| 94 |
*
|
120 |
protected function add_columns(): void {
|
| 95 |
* @param string $badgeissuedalias
|
121 |
\core\deprecation::emit_deprecation([$this, __FUNCTION__]);
|
| 96 |
*/
|
122 |
$badgeissuedalias = $this->get_entity('badge_issued')->get_table_alias('badge_issued');
|
| 97 |
public function add_columns(string $badgeissuedalias): void {
|
123 |
|
| 98 |
$columns = [
|
124 |
$this->add_columns_from_entities([
|
| 99 |
'badge:image',
|
125 |
'badge:image',
|
| 100 |
'badge:name',
|
- |
|
| Línea 101... |
Línea 126... |
| 101 |
'badge:description',
|
126 |
'badge:name',
|
| 102 |
'badge:criteria',
|
127 |
'badge:description',
|
| 103 |
'badge_issued:issued',
|
128 |
'badge:criteria',
|
| 104 |
];
|
129 |
'badge_issued:issued',
|
| Línea 117... |
Línea 142... |
| 117 |
$date = $value ? userdate($value, $format) : '';
|
142 |
$date = $value ? userdate($value, $format) : '';
|
| 118 |
$badgeurl = new moodle_url('/badges/badge.php', ['hash' => $row->uniquehash]);
|
143 |
$badgeurl = new moodle_url('/badges/badge.php', ['hash' => $row->uniquehash]);
|
| 119 |
$icon = new pix_icon('i/valid', get_string('dateearned', 'badges', $date));
|
144 |
$icon = new pix_icon('i/valid', get_string('dateearned', 'badges', $date));
|
| 120 |
return $OUTPUT->action_icon($badgeurl, $icon, null, null, true);
|
145 |
return $OUTPUT->action_icon($badgeurl, $icon, null, null, true);
|
| 121 |
});
|
146 |
});
|
| 122 |
|
- |
|
| 123 |
$this->set_initial_sort_column('badge:name', SORT_ASC);
|
- |
|
| 124 |
}
|
147 |
}
|
| Línea 125... |
Línea 148... |
| 125 |
|
148 |
|
| 126 |
/**
|
149 |
/**
|
| 127 |
* Adds the filters we want to display in the report
|
150 |
* Adds the filters we want to display in the report
|
| 128 |
*
|
151 |
*
|
| 129 |
* They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
152 |
* They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
| - |
|
153 |
* unique identifier
|
| - |
|
154 |
*
|
| 130 |
* unique identifier
|
155 |
* @deprecated since 4.5. Use badges system_report instead.
|
| - |
|
156 |
*/
|
| 131 |
*/
|
157 |
#[\core\attribute\deprecated('course_badges::add_filters', since: '4.5', mdl: 'MDL-82503')]
|
| - |
|
158 |
protected function add_filters(): void {
|
| 132 |
protected function add_filters(): void {
|
159 |
\core\deprecation::emit_deprecation([$this, __FUNCTION__]);
|
| 133 |
$filters = [
|
160 |
$this->add_filters_from_entities([
|
| 134 |
'badge:name',
|
161 |
'badge:name',
|
| 135 |
'badge_issued:issued',
|
162 |
'badge_issued:issued',
|
| 136 |
];
|
- |
|
| 137 |
|
- |
|
| 138 |
$this->add_filters_from_entities($filters);
|
163 |
]);
|
| 139 |
}
|
164 |
}
|