-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderable.php
148 lines (121 loc) · 5.56 KB
/
renderable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* ReportBadges report renderable.
*
* @package report_reportbadges
* @copyright 2014 Andraž Prinčič <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/report/reportbadges/classes/report_reportbadges_list_users_badges_number.php');
require_once($CFG->dirroot . '/report/reportbadges/classes/report_reportbadges_list_users_badges.php');
require_once($CFG->dirroot . '/report/reportbadges/classes/report_reportbadges_list_badges_users_number.php');
class report_reportbadges implements renderable {
/** @var moodle_url url of report page */
public $url;
/** @var string selected report list to display */
public $reporttype = null;
public $courseid;
public $table;
public $reportyear;
private $whereOptions = array();
private $whereParameters = array();
/**
* Constructor.
*
* @param moodle_url|string $url (optional) page url.
* @param string $reporttype (optional) which report list to display.
*/
public function __construct($courseid = NULL, $url = "", $reporttype = "", $reportyear = "") {
global $PAGE;
$this->whereOptions[] = 't.criteriatype <> 0';
$this->courseid = $courseid;
$this->whereOptions[] = 'en.courseid = :courseid';
$this->whereParameters['courseid'] = $courseid;
$this->whereOptions[] = 'd.visible = 1';
// Use page url if empty.
if (empty($url)) {
$this->url = new moodle_url($PAGE->url);
} else {
$this->url = new moodle_url($url);
}
if (empty($reporttype)) {
$rtypes = $this->getAvailablereports();
if (!empty($rtypes)) {
reset($rtypes);
$reporttype = key($rtypes);
} else {
$reporttype = null;
}
}
if (empty($reportyear) || $reportyear == 0) {
$this->reportyear = '';
} else {
$this->reportyear = $reportyear;
$this->whereOptions[] = 'YEAR(FROM_UNIXTIME(d.dateissued)) = :reportyear';
$this->whereParameters['reportyear'] = $reportyear;
}
$this->reporttype = $reporttype;
}
public function getAvailablereports() {
return array(
1 => get_string('listusersandbadgescount', 'report_reportbadges'),
2 => get_string('listusersandbadges', 'report_reportbadges'),
3 => get_string('listbadgesanduserscount', 'report_reportbadges'),
);
}
public function show_table_list_badges_users_number() {
global $CFG;
$fields = 'b.id, b.name AS badgename, COUNT(u.username) AS userscount';
if (file_exists($CFG->dirroot . '/local/badgecerts/lib.php')) {
$fields .= ', b.certid';
}
$this->table = new list_badges_users_number('report_log');
$this->table->set_sql($fields,
"{badge_issued} AS d
JOIN {badge} AS b ON d.badgeid = b.id
JOIN {user} AS u ON d.userid = u.id
JOIN {user_enrolments} AS ue ON ue.userid = u.id
JOIN {enrol} AS en ON en.id = ue.enrolid
JOIN {badge_criteria} AS t ON b.id = t.badgeid", implode(' AND ', $this->whereOptions),
$this->whereParameters);
$this->table->define_baseurl($this->url);
$this->table->is_downloadable(false);
$this->table->show_download_buttons_at(array(TABLE_P_BOTTOM));
$this->table->out(25, true);
}
public function show_table_list_users_badges() {
global $CFG;
$fields = 'u.id, ' . get_all_user_name_fields(true, 'u') . ', CONCAT(u.firstname, \' \', u.lastname) AS fullname, u.username, GROUP_CONCAT(CONCAT(b.name) SEPARATOR \';\') AS badgename, GROUP_CONCAT(CONCAT(b.id) SEPARATOR \';\') AS badgenameid ';
if (file_exists($CFG->dirroot . '/local/badgecerts/lib.php')) {
$fields .= ', b.certid';
}
$this->table = new list_users_badges('list_users_badges');
$this->table->set_sql($fields,
"{badge_issued} AS d
JOIN {badge} AS b ON d.badgeid = b.id
JOIN {user} AS u ON d.userid = u.id
JOIN {user_enrolments} AS ue ON ue.userid = u.id
JOIN {enrol} AS en ON en.id = ue.enrolid
JOIN {badge_criteria} AS t ON b.id = t.badgeid", implode(' AND ', $this->whereOptions), $this->whereParameters);
$this->table->define_baseurl($this->url);
$this->table->is_downloadable(false);
$this->table->show_download_buttons_at(array(TABLE_P_BOTTOM));
$this->table->out(25, true);
}
public function show_table_list_users_badges_number() {
$this->table = new list_users_badges_number('report_log');
$this->table->set_sql('u.id, ' . get_all_user_name_fields(true, 'u') . ', CONCAT(u.firstname, \' \', u.lastname) AS fullname, u.username, COUNT(*) AS badgescount',
"{badge_issued} AS d
JOIN {badge} AS b ON d.badgeid = b.id
JOIN {user} AS u ON d.userid = u.id
JOIN {user_enrolments} AS ue ON ue.userid = u.id
JOIN {enrol} AS en ON en.id = ue.enrolid
JOIN {badge_criteria} AS t ON b.id = t.badgeid", implode(' AND ', $this->whereOptions),
$this->whereParameters);
$this->table->define_baseurl($this->url);
$this->table->is_downloadable(false);
$this->table->show_download_buttons_at(array(TABLE_P_BOTTOM));
$this->table->out(25, true);
}
}