-
Notifications
You must be signed in to change notification settings - Fork 3
/
courseuserbadges.php
117 lines (96 loc) · 4.36 KB
/
courseuserbadges.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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Page for displaying the badges of course participants.
*
* @package local_obf
* @copyright 2013-2020, Open Badge Factory Oy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use classes\obf_assertion;
use classes\obf_badge;
use classes\obf_client;
require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/classes/badge.php');
require_once(__DIR__ . '/classes/event.php');
$clientid = optional_param('clientid', null, PARAM_ALPHANUM);
obf_client::connect($clientid, '*');
$badgeid = optional_param('id', '', PARAM_ALPHANUM);
$courseid = optional_param('courseid', 1, PARAM_INT);
$action = optional_param('action', 'badges', PARAM_ALPHANUM);
$url = new moodle_url('/local/obf/courseuserbadges.php',
array('courseid' => $courseid, 'action' => $action));
$currpage = optional_param('page', '0', PARAM_INT);
$context = context_course::instance($courseid);
$onlydetailstab = 1;
require_login($courseid);
$PAGE->set_context($context);
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
$badge = empty($badgeid) ? null : obf_badge::get_instance($badgeid);
switch ($action) {
// Display badge info.
case 'show':
require_capability('local/obf:viewdetails', $context);
$client = obf_client::get_instance();
$show = optional_param('show', 'details', PARAM_ALPHANUM);
$coursebadgeurl = new moodle_url('/local/obf/courseuserbadges.php',
array('action' => 'show', 'id' => $badgeid));
$PAGE->navbar->add(get_string('siteadmin', 'local_obf'),
new moodle_url('/admin/search.php'));
$PAGE->navbar->add(get_string('obf', 'local_obf'),
new moodle_url('/admin/category.php', array('category' => 'obf')));
$PAGE->navbar->add(get_string('badgelist', 'local_obf'),
new moodle_url('/local/obf/badge.php', array('action' => 'list')));
$PAGE->navbar->add($badge->get_name(), $coursebadgeurl);
$content = $PAGE->get_renderer('local_obf')->render_badge_heading($badge,
$context);
switch ($show) {
// Badge details.
case 'details':
$content .= $PAGE->get_renderer('local_obf')->page_badgedetails(
$client, $badge, $context, $show, null, null, $onlydetailstab);
}
break;
case 'badges':
require_capability('local/obf:seeparticipantbadges', $context);
$participants = get_enrolled_users($context, 'local/obf:earnbadge', 0, 'u.*', null, 0, 0, true);
$content = $PAGE->get_renderer('local_obf')->render_course_participants($courseid, $participants);
break;
case 'history':
require_capability('local/obf:viewhistory', $context);
$client = obf_client::get_instance();
$search = optional_param('search', null, PARAM_TEXT);
$searchparams = array(
'api_consumer_id' => OBF_API_CONSUMER_ID,
'log_entry' => '"course_id":"' . $courseid . '"',
'count_only' => 1,
'query' => $search
);
$res = $client->get_assertions(null, null, $searchparams);
$historysize = $res[0]['result_count'];
$searchparams['count_only'] = 0;
$searchparams['limit'] = 10;
$searchparams['offset'] = $currpage * 10;
$searchparams['order_by'] = 'asc';
$history = obf_assertion::get_assertions($client, null, null, -1, false, $searchparams);
$content = $PAGE->get_renderer('local_obf')->render_client_selector($url, $clientid);
$content .= $PAGE->get_renderer('local_obf')->print_issuing_history($client, $context, $historysize, $currpage, $history);
break;
}
echo $OUTPUT->header();
$content .= $OUTPUT->footer();
echo $content;