forked from drroad09/moodle-block_credly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmybadges.php
112 lines (90 loc) · 3.46 KB
/
mybadges.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
<?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/>.
/**
* List of a user's badges
*
* @package block_credly
* @copyright 2014-2017 Deds Castillo, MM Development Services (http://michaelmino.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/tablelib.php');
require_once(dirname(__FILE__).'/lib.php');
require_login();
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
$courseid = optional_param('courseid', 0, PARAM_INT);
if ($courseid == SITEID) {
$courseid = 0;
}
if ($courseid) {
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$PAGE->set_course($course);
$PAGE->set_context(context_course::instance($courseid));
} else {
$context = context_system::instance();
$PAGE->set_context($context);
}
$urlparams = array();
$extraparams = '';
if ($courseid) {
$urlparams['courseid'] = $courseid;
$extraparams = '&courseid=' . $courseid;
}
if ($returnurl) {
$urlparams['returnurl'] = $returnurl;
$extraparams = '&returnurl=' . $returnurl;
}
$baseurl = new moodle_url('/blocks/credly/mybadges.php', $urlparams);
$PAGE->set_url($baseurl);
$badges = block_credly_get_member_badges();
$strmy = get_string('mybadges', 'block_credly');
$PAGE->set_pagelayout('standard');
$PAGE->set_title($strmy);
$PAGE->set_heading($strmy);
$PAGE->navbar->add(get_string('blocks'));
$PAGE->navbar->add(get_string('pluginname', 'block_credly'));
$PAGE->navbar->add($strmy, $baseurl);
echo $OUTPUT->header();
echo $OUTPUT->heading($strmy, 2);
$table = new flexible_table('credly-display-badges');
$table->define_columns(array('thumbnail', 'info'));
$table->define_headers(array('', ''));
$table->define_baseurl($baseurl);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'credlybadges');
$table->set_attribute('class', 'generaltable generalbox');
$table->column_class('thumbnail', 'badgethumbnail');
$table->column_class('info', 'info');
$table->setup();
if ($badges) {
foreach ($badges as $badge) {
$badgeimagesrc = str_replace('.png', '_5.png', $badge->image);
$badgeimagestub = html_writer::img($badgeimagesrc, $badge->title, array('title' => $badge->title));
$badgelink = html_writer::link(
'https://credly.com/credit/'.$badge->id,
get_string('viewincredly', 'block_credly'),
array('target' => '_blank')
);
$badgeinfo = html_writer::tag('span', $badge->title, array('class' => 'credly_badge_title'));
$badgeinfo .= html_writer::empty_tag('br');
$badgeinfo .= $badge->description;
$badgeinfo .= html_writer::empty_tag('br');
$badgeinfo .= $badgelink;
$table->add_data(array($badgeimagestub, $badgeinfo));
}
}
$table->print_html();
echo $OUTPUT->footer();