2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Displays user badges for badges management in own profile
22 * @copyright 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 * @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
27 require_once(dirname(dirname(__FILE__
)) . '/config.php');
28 require_once($CFG->libdir
. '/badgeslib.php');
30 $page = optional_param('page', 0, PARAM_INT
);
31 $search = optional_param('search', '', PARAM_CLEAN
);
32 $clearsearch = optional_param('clearsearch', '', PARAM_TEXT
);
33 $download = optional_param('download', 0, PARAM_INT
);
34 $hash = optional_param('hash', '', PARAM_ALPHANUM
);
35 $downloadall = optional_param('downloadall', false, PARAM_BOOL
);
36 $hide = optional_param('hide', 0, PARAM_INT
);
37 $show = optional_param('show', 0, PARAM_INT
);
41 if (empty($CFG->enablebadges
)) {
42 print_error('badgesdisabled', 'badges');
45 $url = new moodle_url('/badges/mybadges.php');
49 $PAGE->set_context(context_system
::instance());
50 echo $OUTPUT->header();
51 echo $OUTPUT->box(get_string('error:guestuseraccess', 'badges'), 'notifyproblem');
52 echo $OUTPUT->footer();
66 $DB->set_field('badge_issued', 'visible', 0, array('id' => $hide, 'userid' => $USER->id
));
69 $DB->set_field('badge_issued', 'visible', 1, array('id' => $show, 'userid' => $USER->id
));
70 } else if ($download && $hash) {
72 $badge = new badge($download);
73 $name = str_replace(' ', '_', $badge->name
) . '.png';
75 $file = badges_bake($hash, $download);
76 header('Content-Type: image/png');
77 header('Content-Disposition: attachment; filename="'. $name .'"');
80 } else if ($downloadall) {
83 badges_download($USER->id
);
87 $context = context_user
::instance($USER->id
);
88 require_capability('moodle/badges:manageownbadges', $context);
90 $PAGE->set_context($context);
92 $title = get_string('mybadges', 'badges');
93 $PAGE->set_title($title);
94 $PAGE->set_heading($title);
95 $PAGE->set_pagelayout('mydashboard');
97 // Include JS files for backpack support.
98 badges_setup_backpack_js();
100 $output = $PAGE->get_renderer('core', 'badges');
101 $badges = badges_get_user_badges($USER->id
);
103 echo $OUTPUT->header();
104 $totalcount = count($badges);
105 $records = badges_get_user_badges($USER->id
, null, $page, BADGE_PERPAGE
, $search);
107 $userbadges = new badge_user_collection($records, $USER->id
);
108 $userbadges->sort
= 'dateissued';
109 $userbadges->dir
= 'DESC';
110 $userbadges->page
= $page;
111 $userbadges->perpage
= BADGE_PERPAGE
;
112 $userbadges->totalcount
= $totalcount;
113 $userbadges->search
= $search;
115 echo $output->render($userbadges);
117 echo $OUTPUT->footer();