当前位置: 首页>>代码示例>>PHP>>正文


PHP badges_get_user_badges函数代码示例

本文整理汇总了PHP中badges_get_user_badges函数的典型用法代码示例。如果您正苦于以下问题:PHP badges_get_user_badges函数的具体用法?PHP badges_get_user_badges怎么用?PHP badges_get_user_badges使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了badges_get_user_badges函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: core_badges_myprofile_navigation

/**
 * 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);
            }
        }
    }
}
开发者ID:evltuma,项目名称:moodle,代码行数:45,代码来源:lib.php

示例2: get_content

 public function get_content()
 {
     global $USER, $PAGE, $CFG;
     if ($this->content !== null) {
         return $this->content;
     }
     if (empty($this->config)) {
         $this->config = new stdClass();
     }
     // Number of badges to display.
     if (empty($this->config->numberofbadges)) {
         $this->config->numberofbadges = 10;
     }
     // Create empty content.
     $this->content = new stdClass();
     $this->content->text = '';
     if (empty($CFG->enablebadges)) {
         $this->content->text .= get_string('badgesdisabled', 'badges');
         return $this->content;
     }
     $courseid = $this->page->course->id;
     if ($courseid == SITEID) {
         $courseid = null;
     }
     if ($badges = badges_get_user_badges($USER->id, $courseid, 0, $this->config->numberofbadges)) {
         $output = $this->page->get_renderer('core', 'badges');
         $this->content->text = $output->print_badges_list($badges, $USER->id, true);
     } else {
         $this->content->text .= get_string('nothingtodisplay', 'block_badges');
     }
     return $this->content;
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:32,代码来源:block_badges.php

示例3: require_sesskey

        } else {
            if ($downloadall) {
                require_sesskey();
                badges_download($USER->id);
            }
        }
    }
}
$context = context_user::instance($USER->id);
require_capability('moodle/badges:manageownbadges', $context);
$PAGE->set_context($context);
$title = get_string('mybadges', 'badges');
$PAGE->set_title($title);
$PAGE->set_heading(fullname($USER));
$PAGE->set_pagelayout('mydashboard');
// Include JS files for backpack support.
badges_setup_backpack_js();
$output = $PAGE->get_renderer('core', 'badges');
$badges = badges_get_user_badges($USER->id);
echo $OUTPUT->header();
$totalcount = count($badges);
$records = badges_get_user_badges($USER->id, null, $page, BADGE_PERPAGE, $search);
$userbadges = new badge_user_collection($records, $USER->id);
$userbadges->sort = 'dateissued';
$userbadges->dir = 'DESC';
$userbadges->page = $page;
$userbadges->perpage = BADGE_PERPAGE;
$userbadges->totalcount = $totalcount;
$userbadges->search = $search;
echo $output->render($userbadges);
echo $OUTPUT->footer();
开发者ID:grug,项目名称:moodle,代码行数:31,代码来源:mybadges.php

示例4: my_badges

 function my_badges($username, $n = 10)
 {
     global $CFG;
     require_once $CFG->libdir . "/badgeslib.php";
     $username = utf8_decode($username);
     $username = strtolower($username);
     $user = get_complete_user_data('username', $username);
     if (!$user) {
         return array();
     }
     $badges = badges_get_user_badges($user->id, NULL, 0, $n);
     $bs = array();
     foreach ($badges as $badge) {
         $b = array();
         $b['name'] = $badge->name;
         $b['hash'] = $badge->uniquehash;
         $context = $badge->type == BADGE_TYPE_SITE ? context_system::instance() : context_course::instance($badge->courseid);
         $image_url = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1', false);
         $b['image_url'] = (string) $image_url;
         $bs[] = $b;
     }
     return $bs;
 }
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:23,代码来源:auth.php

示例5: get_badges_by_username

 /**
  * Get user information
  *
  * @param string $username EBS username, could be 8-digit int or string.
  * @return array An array describing targets (and metadata) for that user for all leapcore_* courses.
  */
 public static function get_badges_by_username($username)
 {
     global $CFG, $DB;
     $params = self::validate_parameters(self::get_badges_by_username_parameters(), array('username' => $username));
     if ($params['username'] == '') {
         header($_SERVER["SERVER_PROTOCOL"] . ' 422 Unprocessable Entity ($params[\'username\'] empty.)', true, 422);
         exit(1);
     }
     // Could do with knowing what this user's {user}.id is.
     $sql = "SELECT id from {user} WHERE username LIKE ?;";
     if (!($user = $DB->get_record_sql($sql, array($params['username'] . '%')))) {
         header($_SERVER["SERVER_PROTOCOL"] . ' 422 Unprocessable Entity ($params[\'username\'] could not be matched against a valid user.)', true, 422);
         exit(1);
     }
     require_once $CFG->libdir . '/badgeslib.php';
     // Get the user's badges.
     $userbadges = badges_get_user_badges($user->id);
     $output = array();
     if (!$userbadges) {
         return $output;
     } else {
         $output = array();
         $count = 0;
         foreach ($userbadges as $hash => $ubadge) {
             $count++;
             $output[$count]['course_id'] = $ubadge->courseid;
             $output[$count]['date_issued'] = $ubadge->dateissued;
             $output[$count]['description'] = $ubadge->description;
             $output[$count]['details_link'] = (string) new moodle_url('/badges/badge.php', array('hash' => $hash));
             $output[$count]['image_url'] = (string) badges_bake($hash, $ubadge->id);
             $output[$count]['name'] = $ubadge->name;
         }
     }
     return $output;
 }
开发者ID:kevtufc,项目名称:leap,代码行数:41,代码来源:externallib.php

示例6: profile_display_badges

/**
 * 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);
            }
        }
    }
}
开发者ID:speciwoman,项目名称:moodle,代码行数:40,代码来源:deprecatedlib.php

示例7: test_badges_get_user_badges

 /**
  * Test the {@link badges_get_user_badges()} function in lib/badgeslib.php
  */
 public function test_badges_get_user_badges()
 {
     global $DB;
     // Messaging is not compatible with transactions.
     $this->preventResetByRollback();
     $badges = array();
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     // Record the current time, we need to be precise about a couple of things.
     $now = time();
     // Create 11 badges with which to test.
     for ($i = 1; $i <= 11; $i++) {
         // Mock up a badge.
         $badge = new stdClass();
         $badge->id = null;
         $badge->name = "Test badge {$i}";
         $badge->description = "Testing badges {$i}";
         $badge->timecreated = $now - 12;
         $badge->timemodified = $now - 12;
         $badge->usercreated = $user1->id;
         $badge->usermodified = $user1->id;
         $badge->issuername = "Test issuer";
         $badge->issuerurl = "http://issuer-url.domain.co.nz";
         $badge->issuercontact = "issuer@example.com";
         $badge->expiredate = null;
         $badge->expireperiod = null;
         $badge->type = BADGE_TYPE_SITE;
         $badge->courseid = null;
         $badge->messagesubject = "Test message subject for badge {$i}";
         $badge->message = "Test message body for badge {$i}";
         $badge->attachment = 1;
         $badge->notification = 0;
         $badge->status = BADGE_STATUS_INACTIVE;
         $badgeid = $DB->insert_record('badge', $badge, true);
         $badges[$badgeid] = new badge($badgeid);
         $badges[$badgeid]->issue($user2->id, true);
         // Check it all actually worked.
         $this->assertCount(1, $badges[$badgeid]->get_awards());
         // Hack the database to adjust the time each badge was issued.
         // The alternative to this is sleep which is a no-no in unit tests.
         $DB->set_field('badge_issued', 'dateissued', $now - 11 + $i, array('userid' => $user2->id, 'badgeid' => $badgeid));
     }
     // Make sure the first user has no badges.
     $result = badges_get_user_badges($user1->id);
     $this->assertInternalType('array', $result);
     $this->assertCount(0, $result);
     // Check that the second user has the expected 11 badges.
     $result = badges_get_user_badges($user2->id);
     $this->assertCount(11, $result);
     // Test pagination.
     // Ordering is by time issued desc, so things will come out with the last awarded badge first.
     $result = badges_get_user_badges($user2->id, 0, 0, 4);
     $this->assertCount(4, $result);
     $lastbadgeissued = reset($result);
     $this->assertSame('Test badge 11', $lastbadgeissued->name);
     // Page 2. Expecting 4 results again.
     $result = badges_get_user_badges($user2->id, 0, 1, 4);
     $this->assertCount(4, $result);
     $lastbadgeissued = reset($result);
     $this->assertSame('Test badge 7', $lastbadgeissued->name);
     // Page 3. Expecting just three results here.
     $result = badges_get_user_badges($user2->id, 0, 2, 4);
     $this->assertCount(3, $result);
     $lastbadgeissued = reset($result);
     $this->assertSame('Test badge 3', $lastbadgeissued->name);
     // Page 4.... there is no page 4.
     $result = badges_get_user_badges($user2->id, 0, 3, 4);
     $this->assertCount(0, $result);
     // Test search.
     $result = badges_get_user_badges($user2->id, 0, 0, 0, 'badge 1');
     $this->assertCount(3, $result);
     $lastbadgeissued = reset($result);
     $this->assertSame('Test badge 11', $lastbadgeissued->name);
     // The term Totara doesn't appear anywhere in the badges.
     $result = badges_get_user_badges($user2->id, 0, 0, 0, 'Totara');
     $this->assertCount(0, $result);
     // Issue a user with a course badge and verify its returned based on if
     // coursebadges are enabled or disabled.
     $sitebadgeid = key($badges);
     $badges[$sitebadgeid]->issue($this->user->id, true);
     $badge = new stdClass();
     $badge->id = null;
     $badge->name = "Test course badge";
     $badge->description = "Testing course badge";
     $badge->timecreated = $now;
     $badge->timemodified = $now;
     $badge->usercreated = $user1->id;
     $badge->usermodified = $user1->id;
     $badge->issuername = "Test issuer";
     $badge->issuerurl = "http://issuer-url.domain.co.nz";
     $badge->issuercontact = "issuer@example.com";
     $badge->expiredate = null;
     $badge->expireperiod = null;
     $badge->type = BADGE_TYPE_COURSE;
     $badge->courseid = $this->course->id;
     $badge->messagesubject = "Test message subject for course badge";
     $badge->message = "Test message body for course badge";
//.........这里部分代码省略.........
开发者ID:lucaboesch,项目名称:moodle,代码行数:101,代码来源:badgeslib_test.php

示例8: get_user_badges

 /**
  * Returns the list of badges awarded to a user.
  *
  * @param int $userid       user id
  * @param int $courseid     course id
  * @param int $page         page of records to return
  * @param int $perpage      number of records to return per page
  * @param string  $search   a simple string to search for
  * @param bool $onlypublic  whether to return only public badges
  * @return array array containing warnings and the awarded badges
  * @since  Moodle 3.1
  * @throws moodle_exception
  */
 public static function get_user_badges($userid = 0, $courseid = 0, $page = 0, $perpage = 0, $search = '', $onlypublic = false)
 {
     global $CFG, $USER;
     $warnings = array();
     $params = array('userid' => $userid, 'courseid' => $courseid, 'page' => $page, 'perpage' => $perpage, 'search' => $search, 'onlypublic' => $onlypublic);
     $params = self::validate_parameters(self::get_user_badges_parameters(), $params);
     if (empty($CFG->enablebadges)) {
         throw new moodle_exception('badgesdisabled', 'badges');
     }
     if (empty($CFG->badges_allowcoursebadges) && $params['courseid'] != 0) {
         throw new moodle_exception('coursebadgesdisabled', 'badges');
     }
     // Default value for userid.
     if (empty($params['userid'])) {
         $params['userid'] = $USER->id;
     }
     // Validate the user.
     $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
     core_user::require_active_user($user);
     $usercontext = context_user::instance($user->id);
     self::validate_context($usercontext);
     if ($USER->id != $user->id) {
         require_capability('moodle/badges:viewotherbadges', $usercontext);
         // We are looking other user's badges, we must retrieve only public badges.
         $params['onlypublic'] = true;
     }
     $userbadges = badges_get_user_badges($user->id, $params['courseid'], $params['page'], $params['perpage'], $params['search'], $params['onlypublic']);
     $result = array();
     $result['badges'] = array();
     $result['warnings'] = $warnings;
     foreach ($userbadges as $badge) {
         $context = $badge->type == BADGE_TYPE_SITE ? context_system::instance() : context_course::instance($badge->courseid);
         $badge->badgeurl = moodle_url::make_webservice_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1')->out(false);
         // Return all the information if we are requesting our own badges.
         // Or, if we have permissions for configuring badges in the badge context.
         if ($USER->id == $user->id or has_capability('moodle/badges:configuredetails', $context)) {
             $result['badges'][] = (array) $badge;
         } else {
             $result['badges'][] = array('name' => $badge->name, 'description' => $badge->description, 'badgeurl' => $badge->badgeurl, 'issuername' => $badge->issuername, 'issuerurl' => $badge->issuerurl, 'issuercontact' => $badge->issuercontact, 'uniquehash' => $badge->uniquehash, 'dateissued' => $badge->dateissued, 'dateexpire' => $badge->dateexpire);
         }
     }
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:56,代码来源:external.php

示例9: get_badges_list

function get_badges_list($userid, $courseid = 0)
{
    global $CFG, $USER;
    require_once $CFG->dirroot . '/badges/renderer.php';
    if ($courseid == 0) {
        $context = context_system::instance();
    } else {
        $context = context_course::instance($courseid);
    }
    if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) {
        if ($courseid == 0) {
            $records = get_global_user_badges($userid);
        } else {
            $records = badges_get_user_badges($userid, $courseid, null, null, null, true);
        }
        // Print local badges.
        if ($records) {
            $out = '';
            foreach ($records as $record) {
                $imageurl = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $record->id, '/', 'f1', false);
                $image = html_writer::empty_tag('img', array('src' => $imageurl, 'class' => 'badge-image', 'style' => 'width: 30px; height: 30px;'));
                $url = new moodle_url('/badges/badge.php', array('hash' => $record->uniquehash));
                $link = html_writer::link($url, $image, array('title' => $record->name));
                $out .= $link;
            }
            return $out;
        }
    }
}
开发者ID:oncampus,项目名称:mooin_block_oc_mooc_nav,代码行数:29,代码来源:locallib.php


注:本文中的badges_get_user_badges函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。