source: moodle/trunk/fuentes/badges/lib.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 3.2 KB
Line 
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
18 * Defines various library functions.
19 *
20 * @package   core_badges
21 * @copyright 2015 onwards Ankit Agarwal
22 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * Add nodes to myprofile page.
29 *
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
34 *
35 * @return bool
36 */
37function 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 ?
42        return true;
43    }
44
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);
48
49    // Determine context.
50    if (isloggedin()) {
51        $context = context_user::instance($USER->id);
52    } else {
53        $context = context_system::instance();
54    }
55    $courseid = empty($course) ? 0 : $course->id;
56
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, '');
60
61        // Local badges.
62        if ($records) {
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);
67        }
68
69        // External badges.
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,
76                    $content);
77                $tree->add_node($externalnode);
78            }
79        }
80    }
81}
Note: See TracBrowser for help on using the repository browser.