Пример #1
0
/**
 * Add nodes to myprofile page.
 *
 * @param \core_user\output\myprofile\tree $tree Tree object
 * @param stdClass $user user object
 * @param bool $iscurrentuser
 * @param stdClass $course Course object
 *
 * @return bool
 */
function core_badges_myprofile_navigation(\core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course)
{
    global $CFG, $PAGE, $USER, $SITE;
    require_once $CFG->dirroot . '/badges/renderer.php';
    if (empty($CFG->enablebadges) || !empty($course) && empty($CFG->badges_allowcoursebadges)) {
        // Y U NO LIKE BADGES ?
        return true;
    }
    // Add category. This node should appear after 'contact' so that administration block appears towards the end. Refer MDL-49928.
    $category = new core_user\output\myprofile\category('badges', get_string('badges', 'badges'), 'contact');
    $tree->add_category($category);
    $context = context_user::instance($user->id);
    $courseid = empty($course) ? 0 : $course->id;
    if ($USER->id == $user->id || has_capability('moodle/badges:viewotherbadges', $context)) {
        $records = badges_get_user_badges($user->id, $courseid, null, null, null, true);
        $renderer = new core_badges_renderer($PAGE, '');
        // Local badges.
        if ($records) {
            $title = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
            $content = $renderer->print_badges_list($records, $user->id, true);
            $localnode = $mybadges = new core_user\output\myprofile\node('badges', 'localbadges', $title, null, null, $content);
            $tree->add_node($localnode);
        }
        // External badges.
        if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
            $backpack = get_backpack_settings($user->id);
            if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
                $title = get_string('externalbadgesp', 'badges');
                $content = $renderer->print_badges_list($backpack->badges, $user->id, true, true);
                $externalnode = $mybadges = new core_user\output\myprofile\node('badges', 'externalbadges', $title, null, null, $content);
                $tree->add_node($externalnode);
            }
        }
    }
}
Пример #2
0
/**
 * Print badges on user profile page.
 *
 * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
 * @param int $userid User ID.
 * @param int $courseid Course if we need to filter badges (optional).
 */
function profile_display_badges($userid, $courseid = 0)
{
    global $CFG, $PAGE, $USER, $SITE;
    require_once $CFG->dirroot . '/badges/renderer.php';
    debugging('profile_display_badges() is deprecated.', DEBUG_DEVELOPER);
    // Determine context.
    if (isloggedin()) {
        $context = context_user::instance($USER->id);
    } else {
        $context = context_system::instance();
    }
    if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) {
        $records = badges_get_user_badges($userid, $courseid, null, null, null, true);
        $renderer = new core_badges_renderer($PAGE, '');
        // Print local badges.
        if ($records) {
            $left = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
            $right = $renderer->print_badges_list($records, $userid, true);
            echo html_writer::tag('dt', $left);
            echo html_writer::tag('dd', $right);
        }
        // Print external badges.
        if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
            $backpack = get_backpack_settings($userid);
            if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
                $left = get_string('externalbadgesp', 'badges');
                $right = $renderer->print_badges_list($backpack->badges, $userid, true, true);
                echo html_writer::tag('dt', $left);
                echo html_writer::tag('dd', $right);
            }
        }
    }
}
Пример #3
0
function display_badges($userid = 0, $courseid = 0, $since = 0, $print = true)
{
    global $CFG, $PAGE, $USER, $SITE;
    require_once $CFG->dirroot . '/badges/renderer.php';
    // Determine context.
    if (isloggedin()) {
        $context = context_user::instance($USER->id);
    } else {
        $context = context_system::instance();
    }
    if ($userid == 0) {
        if ($since == 0) {
            $records = get_badges($courseid, null, null, null);
        } else {
            $records = get_badges_since($courseid, $since, false);
            // globale Badges
            // if ($courseid != 0) {
            // $records = array_merge(get_badges_since($courseid, $since, true), $records);
            // }
        }
        $renderer = new core_badges_renderer($PAGE, '');
        // Print local badges.
        if ($records) {
            //$right = $renderer->print_badges_list($records, $userid, true);
            if ($since == 0) {
                print_badges($records);
            } else {
                print_badges($records, true);
            }
        }
    } elseif ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) {
        $records = badges_get_user_badges($userid, $courseid, null, null, null, true);
        $renderer = new core_badges_renderer($PAGE, '');
        // Print local badges.
        if ($records) {
            $right = $renderer->print_badges_list($records, $userid, true);
            if ($print) {
                echo html_writer::tag('dd', $right);
                //print_badges($records);
            } else {
                return html_writer::tag('dd', $right);
            }
        }
    }
}