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 * Defines various library functions.
20 * @package core_badges
21 * @copyright 2015 onwards Ankit Agarwal
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
28 * Add nodes to myprofile page.
30 * @param \core_user\output\myprofile\tree $tree Tree object
31 * @param stdClass $user user object
32 * @param bool $iscurrentuser
33 * @param stdClass $course Course object
37 function core_badges_myprofile_navigation(\core_user\output\myprofile\tree
$tree, $user, $iscurrentuser, $course) {
38 global $CFG, $PAGE, $USER, $SITE;
39 require_once($CFG->dirroot
. '/badges/renderer.php');
40 if (empty($CFG->enablebadges
) ||
(!empty($course) && empty($CFG->badges_allowcoursebadges
))) {
41 // Y U NO LIKE BADGES ?
45 // Add category. This node should appear after 'contact' so that administration block appears towards the end. Refer MDL-49928.
46 $category = new core_user\output\myprofile\
category('badges', get_string('badges', 'badges'), 'contact');
47 $tree->add_category($category);
51 $context = context_user
::instance($USER->id
);
53 $context = context_system
::instance();
55 $courseid = empty($course) ?
0 : $course->id
;
57 if ($USER->id
== $user->id ||
has_capability('moodle/badges:viewotherbadges', $context)) {
58 $records = badges_get_user_badges($user->id
, $courseid, null, null, null, true);
59 $renderer = new core_badges_renderer($PAGE, '');
63 $title = get_string('localbadgesp', 'badges', format_string($SITE->fullname
));
64 $content = $renderer->print_badges_list($records, $user->id
, true);
65 $localnode = $mybadges = new core_user\output\myprofile\node
('badges', 'localbadges', $title, null, null, $content);
66 $tree->add_node($localnode);
70 if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack
)) {
71 $backpack = get_backpack_settings($user->id
);
72 if (isset($backpack->totalbadges
) && $backpack->totalbadges
!== 0) {
73 $title = get_string('externalbadgesp', 'badges');
74 $content = $renderer->print_badges_list($backpack->badges
, $user->id
, true, true);
75 $externalnode = $mybadges = new core_user\output\myprofile\node
('badges', 'externalbadges', $title, null, null,
77 $tree->add_node($externalnode);