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');
59 $DB->set_field('badge_issued', 'visible', 0, array('id' => $hide));
62 $DB->set_field('badge_issued', 'visible', 1, array('id' => $show));
63 } else if ($download && $hash) {
65 $badge = new badge($download);
66 $name = str_replace(' ', '_', $badge->name
) . '.png';
68 $file = badges_bake($hash, $download);
69 header('Content-Type: image/png');
70 header('Content-Disposition: attachment; filename="'. $name .'"');
73 } else if ($downloadall) {
76 badges_download($USER->id
);
80 $context = context_user
::instance($USER->id
);
81 require_capability('moodle/badges:manageownbadges', $context);
83 $url = new moodle_url('/badges/mybadges.php');
86 $PAGE->set_context($context);
88 $title = get_string('mybadges', 'badges');
89 $PAGE->set_title($title);
90 $PAGE->set_heading($title);
91 $PAGE->set_pagelayout('mydashboard');
93 // Include JS files for backpack support.
94 badges_setup_backpack_js();
96 $output = $PAGE->get_renderer('core', 'badges');
97 $badges = badges_get_user_badges($USER->id
);
99 echo $OUTPUT->header();
100 $totalcount = count($badges);
101 $records = badges_get_user_badges($USER->id
, null, $page, BADGE_PERPAGE
, $search);
103 $userbadges = new badge_user_collection($records, $USER->id
);
104 $userbadges->sort
= 'dateissued';
105 $userbadges->dir
= 'DESC';
106 $userbadges->page
= $page;
107 $userbadges->perpage
= BADGE_PERPAGE
;
108 $userbadges->totalcount
= $totalcount;
109 $userbadges->search
= $search;
111 echo $output->render($userbadges);
113 echo $OUTPUT->footer();