本文整理汇总了PHP中user_picture::get_url方法的典型用法代码示例。如果您正苦于以下问题:PHP user_picture::get_url方法的具体用法?PHP user_picture::get_url怎么用?PHP user_picture::get_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user_picture
的用法示例。
在下文中一共展示了user_picture::get_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_other_values
protected function get_other_values(renderer_base $output)
{
global $PAGE, $CFG;
// Add user picture.
$userpicture = new \user_picture($this->data);
$userpicture->size = 1;
// Size f1.
$profileimageurl = $userpicture->get_url($PAGE)->out(false);
$userpicture->size = 0;
// Size f2.
$profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);
$profileurl = (new moodle_url('/user/profile.php', array('id' => $this->data->id)))->out(false);
$identityfields = array_flip(explode(',', $CFG->showuseridentity));
$data = $this->data;
foreach ($identityfields as $field => $index) {
if (!empty($data->{$field})) {
$identityfields[$field] = $data->{$field};
} else {
unset($identityfields[$field]);
}
}
$identity = implode(', ', $identityfields);
return array('fullname' => fullname($this->data), 'profileimageurl' => $profileimageurl, 'profileimageurlsmall' => $profileimageurlsmall, 'profileurl' => $profileurl, 'identity' => $identity);
}
示例2: test_update_user_profile_image
/**
* Test the update user profile image function.
*/
public function test_update_user_profile_image()
{
global $DB, $CFG;
// Set the profile image.
\enrol_lti\helper::update_user_profile_image($this->user1->id, $this->getExternalTestFileUrl('/test.jpg'));
// Get the new user record.
$this->user1 = $DB->get_record('user', array('id' => $this->user1->id));
// Set the page details.
$page = new moodle_page();
$page->set_url('/user/profile.php');
$page->set_context(context_system::instance());
$renderer = $page->get_renderer('core');
$usercontext = context_user::instance($this->user1->id);
// Get the user's profile picture and make sure it is correct.
$userpicture = new user_picture($this->user1);
$this->assertSame($CFG->wwwroot . '/pluginfile.php/' . $usercontext->id . '/user/icon/clean/f2?rev=' . $this->user1->picture, $userpicture->get_url($page, $renderer)->out(false));
}
示例3: dialogue_add_user_picture_fields
/**
* Adds the extra fields to user object required for
* displaying user avatar.
*
* @global moodle_page $PAGE
* @param stdClass $user
*/
function dialogue_add_user_picture_fields(stdClass &$user)
{
global $PAGE;
$user->fullname = fullname($user);
$userpic = new user_picture($user);
$imageurl = $userpic->get_url($PAGE);
$user->imageurl = $imageurl->out();
if (empty($user->imagealt)) {
$user->imagealt = get_string('pictureof', '', $user->fullname);
}
return;
}
示例4: test_mod_forum_get_forum_discussions_paginated
/**
* Test get forum discussions paginated
*/
public function test_mod_forum_get_forum_discussions_paginated()
{
global $USER, $CFG, $DB, $PAGE;
$this->resetAfterTest(true);
// Set the CFG variable to allow track forums.
$CFG->forum_trackreadposts = true;
// Create a user who can track forums.
$record = new stdClass();
$record->trackforums = true;
$user1 = self::getDataGenerator()->create_user($record);
// Create a bunch of other users to post.
$user2 = self::getDataGenerator()->create_user();
$user3 = self::getDataGenerator()->create_user();
$user4 = self::getDataGenerator()->create_user();
// Set the first created user to the test user.
self::setUser($user1);
// Create courses to add the modules.
$course1 = self::getDataGenerator()->create_course();
// First forum with tracking off.
$record = new stdClass();
$record->course = $course1->id;
$record->trackingtype = FORUM_TRACKING_OFF;
$forum1 = self::getDataGenerator()->create_module('forum', $record);
// Add discussions to the forums.
$record = new stdClass();
$record->course = $course1->id;
$record->userid = $user1->id;
$record->forum = $forum1->id;
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Add three replies to the discussion 1 from different users.
$record = new stdClass();
$record->discussion = $discussion1->id;
$record->parent = $discussion1->firstpost;
$record->userid = $user2->id;
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
$record->parent = $discussion1reply1->id;
$record->userid = $user3->id;
$discussion1reply2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
$record->userid = $user4->id;
$discussion1reply3 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
// Enrol the user in the first course.
$enrol = enrol_get_plugin('manual');
// We don't use the dataGenerator as we need to get the $instance2 to unenrol later.
$enrolinstances = enrol_get_instances($course1->id, true);
foreach ($enrolinstances as $courseenrolinstance) {
if ($courseenrolinstance->enrol == "manual") {
$instance1 = $courseenrolinstance;
break;
}
}
$enrol->enrol_user($instance1, $user1->id);
// Delete one user.
delete_user($user4);
// Assign capabilities to view discussions for forum 1.
$cm = get_coursemodule_from_id('forum', $forum1->cmid, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
$newrole = create_role('Role 2', 'role2', 'Role 2 description');
$this->assignUserCapability('mod/forum:viewdiscussion', $context->id, $newrole);
// Create what we expect to be returned when querying the forums.
$post1 = $DB->get_record('forum_posts', array('id' => $discussion1->firstpost), '*', MUST_EXIST);
// User pictures are initially empty, we should get the links once the external function is called.
$expecteddiscussions = array('id' => $discussion1->firstpost, 'name' => $discussion1->name, 'groupid' => $discussion1->groupid, 'timemodified' => $discussion1reply3->created, 'usermodified' => $discussion1reply3->userid, 'timestart' => $discussion1->timestart, 'timeend' => $discussion1->timeend, 'discussion' => $discussion1->id, 'parent' => 0, 'userid' => $discussion1->userid, 'created' => $post1->created, 'modified' => $post1->modified, 'mailed' => $post1->mailed, 'subject' => $post1->subject, 'message' => $post1->message, 'messageformat' => $post1->messageformat, 'messagetrust' => $post1->messagetrust, 'attachment' => $post1->attachment, 'totalscore' => $post1->totalscore, 'mailnow' => $post1->mailnow, 'userfullname' => fullname($user1), 'usermodifiedfullname' => fullname($user4), 'userpictureurl' => '', 'usermodifiedpictureurl' => '', 'numreplies' => 3, 'numunread' => 0, 'pinned' => FORUM_DISCUSSION_UNPINNED);
// Call the external function passing forum id.
$discussions = mod_forum_external::get_forum_discussions_paginated($forum1->id);
$discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$expectedreturn = array('discussions' => array($expecteddiscussions), 'warnings' => array());
// Wait the theme to be loaded (the external_api call does that) to generate the user profiles.
$userpicture = new user_picture($user1);
$userpicture->size = 1;
// Size f1.
$expectedreturn['discussions'][0]['userpictureurl'] = $userpicture->get_url($PAGE)->out(false);
$userpicture = new user_picture($user4);
$userpicture->size = 1;
// Size f1.
$expectedreturn['discussions'][0]['usermodifiedpictureurl'] = $userpicture->get_url($PAGE)->out(false);
$this->assertEquals($expectedreturn, $discussions);
// Call without required view discussion capability.
$this->unassignUserCapability('mod/forum:viewdiscussion', $context->id, $newrole);
try {
mod_forum_external::get_forum_discussions_paginated($forum1->id);
$this->fail('Exception expected due to missing capability.');
} catch (moodle_exception $e) {
$this->assertEquals('noviewdiscussionspermission', $e->errorcode);
}
// Unenrol user from second course.
$enrol->unenrol_user($instance1, $user1->id);
// Call for the second course we unenrolled the user from, make sure exception thrown.
try {
mod_forum_external::get_forum_discussions_paginated($forum1->id);
$this->fail('Exception expected due to being unenrolled from the course.');
} catch (moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
}
示例5: update_picture
/**
* Update or delete the user picture in the site
*
* @param int $draftitemid id of the user draft file to use as image
* @param bool $delete if we should delete the user picture
* @param int $userid id of the user, 0 for current user
* @return array warnings and success status
* @since Moodle 3.2
* @throws moodle_exception
*/
public static function update_picture($draftitemid, $delete = false, $userid = 0)
{
global $CFG, $USER, $PAGE;
$params = self::validate_parameters(self::update_picture_parameters(), array('draftitemid' => $draftitemid, 'delete' => $delete, 'userid' => $userid));
$context = context_system::instance();
self::validate_context($context);
if (!empty($CFG->disableuserimages)) {
throw new moodle_exception('userimagesdisabled', 'admin');
}
if (empty($params['userid']) or $params['userid'] == $USER->id) {
$user = $USER;
require_capability('moodle/user:editownprofile', $context);
} else {
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
$personalcontext = context_user::instance($user->id);
require_capability('moodle/user:editprofile', $personalcontext);
if (is_siteadmin($user) and !is_siteadmin($USER)) {
// Only admins may edit other admins.
throw new moodle_exception('useradmineditadmin');
}
}
// Load the appropriate auth plugin.
$userauth = get_auth_plugin($user->auth);
if (is_mnet_remote_user($user) or !$userauth->can_edit_profile() or $userauth->edit_profile_url()) {
throw new moodle_exception('noprofileedit', 'auth');
}
$filemanageroptions = array('maxbytes' => $CFG->maxbytes, 'subdirs' => 0, 'maxfiles' => 1, 'accepted_types' => 'web_image');
$user->deletepicture = $params['delete'];
$user->imagefile = $params['draftitemid'];
$success = core_user::update_picture($user, $filemanageroptions);
$result = array('success' => $success, 'warnings' => array());
if ($success) {
$userpicture = new user_picture(core_user::get_user($user->id));
$userpicture->size = 1;
// Size f1.
$result['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);
}
return $result;
}
示例6: create_contact
/**
* Helper function for creating a contact object.
*
* @param \stdClass $contact
* @param string $prefix
* @return \stdClass
*/
public static function create_contact($contact, $prefix = '')
{
global $PAGE;
// Create the data we are going to pass to the renderable.
$userfields = \user_picture::unalias($contact, array('lastaccess'), $prefix . 'id', $prefix);
$data = new \stdClass();
$data->userid = $userfields->id;
$data->useridfrom = null;
$data->fullname = fullname($userfields);
// Get the user picture data.
$userpicture = new \user_picture($userfields);
$userpicture->size = 1;
// Size f1.
$data->profileimageurl = $userpicture->get_url($PAGE)->out(false);
$userpicture->size = 0;
// Size f2.
$data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);
// Store the message if we have it.
$data->ismessaging = false;
$data->lastmessage = null;
$data->messageid = null;
if (isset($contact->smallmessage)) {
$data->ismessaging = true;
// Strip the HTML tags from the message for displaying in the contact area.
$data->lastmessage = clean_param($contact->smallmessage, PARAM_NOTAGS);
$data->useridfrom = $contact->useridfrom;
if (isset($contact->messageid)) {
$data->messageid = $contact->messageid;
}
}
// Check if the user is online.
$data->isonline = self::is_online($userfields->lastaccess);
$data->isblocked = isset($contact->blocked) ? (bool) $contact->blocked : false;
$data->isread = isset($contact->isread) ? (bool) $contact->isread : false;
$data->unreadcount = isset($contact->unreadcount) ? $contact->unreadcount : null;
return $data;
}
示例7: render_user_picture
/**
* Internal implementation of user image rendering.
*
* @param user_picture $userpicture
* @return string
*/
protected function render_user_picture(user_picture $userpicture) {
global $CFG, $DB;
$user = $userpicture->user;
if ($userpicture->alttext) {
if (!empty($user->imagealt)) {
$alt = $user->imagealt;
} else {
$alt = get_string('pictureof', '', fullname($user));
}
} else {
$alt = '';
}
if (empty($userpicture->size)) {
$size = 35;
} else if ($userpicture->size === true or $userpicture->size == 1) {
$size = 100;
} else {
$size = $userpicture->size;
}
$class = $userpicture->class;
if ($user->picture == 0) {
$class .= ' defaultuserpic';
}
$src = $userpicture->get_url($this->page, $this);
$attributes = array('src'=>$src, 'alt'=>$alt, 'title'=>$alt, 'class'=>$class, 'width'=>$size, 'height'=>$size);
if (!$userpicture->visibletoscreenreaders) {
$attributes['role'] = 'presentation';
}
// get the image html output fisrt
$output = html_writer::empty_tag('img', $attributes);
// then wrap it in link if needed
if (!$userpicture->link) {
return $output;
}
if (empty($userpicture->courseid)) {
$courseid = $this->page->course->id;
} else {
$courseid = $userpicture->courseid;
}
if ($courseid == SITEID) {
$url = new moodle_url('/user/profile.php', array('id' => $user->id));
} else {
$url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid));
}
$attributes = array('href'=>$url);
if (!$userpicture->visibletoscreenreaders) {
$attributes['tabindex'] = '-1';
$attributes['aria-hidden'] = 'true';
}
if ($userpicture->popup) {
$id = html_writer::random_id('userpicture');
$attributes['id'] = $id;
$this->add_action_handler(new popup_action('click', $url), $id);
}
return html_writer::tag('a', $output, $attributes);
}
示例8: get_chat_users
/**
* Get the list of users in the given chat session.
*
* @param int $chatsid the chat session id
* @return array of warnings and the user lists
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function get_chat_users($chatsid)
{
global $DB, $PAGE;
$params = self::validate_parameters(self::get_chat_users_parameters(), array('chatsid' => $chatsid));
$warnings = array();
// Request and permission validation.
if (!($chatuser = $DB->get_record('chat_users', array('sid' => $params['chatsid'])))) {
throw new moodle_exception('notlogged', 'chat');
}
$chat = $DB->get_record('chat', array('id' => $chatuser->chatid), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($chat, 'chat');
$context = context_module::instance($cm->id);
self::validate_context($context);
require_capability('mod/chat:chat', $context);
// First, delete old users from the chats.
chat_delete_old_users();
$users = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid);
$returnedusers = array();
foreach ($users as $user) {
$userpicture = new user_picture($user);
$userpicture->size = 1;
// Size f1.
$profileimageurl = $userpicture->get_url($PAGE)->out(false);
$returnedusers[] = array('id' => $user->id, 'fullname' => fullname($user), 'profileimageurl' => $profileimageurl);
}
$result = array();
$result['users'] = $returnedusers;
$result['warnings'] = $warnings;
return $result;
}
示例9: get_site_info
/**
* Return user information including profile picture + basic site information
* Note:
* - no capability checking because we return only known information about logged user
*
* @param array $serviceshortnames - DEPRECATED PARAMETER - values will be ignored -
* it was an original design error, we keep for backward compatibility.
* @return array site info
* @since Moodle 2.2
*/
public static function get_site_info($serviceshortnames = array())
{
global $USER, $SITE, $CFG, $DB, $PAGE;
$params = self::validate_parameters(self::get_site_info_parameters(), array('serviceshortnames' => $serviceshortnames));
$context = context_user::instance($USER->id);
$userpicture = new user_picture($USER);
$userpicture->size = 1;
// Size f1.
$profileimageurl = $userpicture->get_url($PAGE);
// Site information.
$siteinfo = array('sitename' => $SITE->fullname, 'siteurl' => $CFG->wwwroot, 'username' => $USER->username, 'firstname' => $USER->firstname, 'lastname' => $USER->lastname, 'fullname' => fullname($USER), 'lang' => current_language(), 'userid' => $USER->id, 'userpictureurl' => $profileimageurl->out(false));
// Retrieve the service and functions from the web service linked to the token
// If you call this function directly from external (not a web service call),
// then it will still return site info without information about a service
// Note: wsusername/wspassword ws authentication is not supported.
$functions = array();
if ($CFG->enablewebservices) {
// No need to check token if web service are disabled and not a ws call.
$token = optional_param('wstoken', '', PARAM_ALPHANUM);
if (!empty($token)) {
// No need to run if not a ws call.
// Retrieve service shortname.
$servicesql = 'SELECT s.*
FROM {external_services} s, {external_tokens} t
WHERE t.externalserviceid = s.id AND token = ? AND t.userid = ? AND s.enabled = 1';
$service = $DB->get_record_sql($servicesql, array($token, $USER->id));
$siteinfo['downloadfiles'] = $service->downloadfiles;
$siteinfo['uploadfiles'] = $service->uploadfiles;
if (!empty($service)) {
// Return the release and version number for web service users only.
$siteinfo['release'] = $CFG->release;
$siteinfo['version'] = $CFG->version;
// Retrieve the functions.
$functionssql = "SELECT f.*\n FROM {external_functions} f, {external_services_functions} sf\n WHERE f.name = sf.functionname AND sf.externalserviceid = ?";
$functions = $DB->get_records_sql($functionssql, array($service->id));
} else {
throw new coding_exception('No service found in get_site_info: something is buggy, \\
it should have fail at the ws server authentication layer.');
}
}
}
// Build up the returned values of the list of functions.
$componentversions = array();
$availablefunctions = array();
foreach ($functions as $function) {
$functioninfo = array();
$functioninfo['name'] = $function->name;
if ($function->component == 'moodle' || $function->component == 'core') {
$version = $CFG->version;
// Moodle version.
} else {
$versionpath = core_component::get_component_directory($function->component) . '/version.php';
if (is_readable($versionpath)) {
// We store the component version once retrieved (so we don't load twice the version.php).
if (!isset($componentversions[$function->component])) {
$plugin = new stdClass();
include $versionpath;
$componentversions[$function->component] = $plugin->version;
$version = $plugin->version;
} else {
$version = $componentversions[$function->component];
}
} else {
// Function component should always have a version.php,
// otherwise the function should have been described with component => 'moodle'.
throw new moodle_exception('missingversionfile', 'webservice', '', $function->component);
}
}
$functioninfo['version'] = $version;
$availablefunctions[] = $functioninfo;
}
$siteinfo['functions'] = $availablefunctions;
// Mobile CSS theme and alternative login url.
$siteinfo['mobilecssurl'] = $CFG->mobilecssurl;
// Retrieve some advanced features. Only enable/disable ones (bool).
$advancedfeatures = array("usecomments", "usetags", "enablenotes", "messaging", "enableblogs", "enablecompletion", "enablebadges");
foreach ($advancedfeatures as $feature) {
if (isset($CFG->{$feature})) {
$siteinfo['advancedfeatures'][] = array('name' => $feature, 'value' => (int) $CFG->{$feature});
}
}
// Special case mnet_dispatcher_mode.
$siteinfo['advancedfeatures'][] = array('name' => 'mnet_dispatcher_mode', 'value' => $CFG->mnet_dispatcher_mode == 'strict' ? 1 : 0);
// User can manage own files.
$siteinfo['usercanmanageownfiles'] = has_capability('moodle/user:manageownfiles', $context);
// User quota. 0 means user can ignore the quota.
$siteinfo['userquota'] = 0;
if (!has_capability('moodle/user:ignoreuserquota', $context)) {
$siteinfo['userquota'] = $CFG->userquota;
}
//.........这里部分代码省略.........
示例10: user_menu
/**
Function to build the user's menu for the top navigation bar
@param bool $withlinks - not sure if we want this
@return string HTML fragment
**/
public function user_menu($user = NULL, $withlinks = NULL)
{
global $USER, $CFG, $DB, $SESSION, $PAGE;
// if we are during install return an empty string
if (during_initial_install()) {
return '';
}
$course = $this->page->course;
// at certain times - i.e. installation course id will be empty or null
if (empty($course->id)) {
return '';
}
// this is the login page so return nothing
$loginurl = get_login_url();
if ((string) $this->page->url === $loginurl) {
return '';
}
// user not logged in so return login link
if (!isloggedin()) {
return "<li><a href=\"{$loginurl}\">" . get_string('login') . '</a></li>';
}
// begin building the user's display name
$user_string = "";
// check if the user is logged in as someone else
#if (session_is_loggedinas()) {
# $realuser = session_get_realuser();
if (\core\session\manager::is_loggedinas()) {
$realuser = \core\session\manager::get_realuser();
$user_string = fullname($realuser, true) . " pretending to be ";
}
$user_string .= fullname($USER, true);
$role_switched = false;
if (is_role_switched($course->id)) {
// Has switched roles
$context = context_course::instance($course->id);
$role_switched = true;
$rolename = '';
if ($role = $DB->get_record('role', array('id' => $USER->access['rsw'][$context->path]))) {
$rolename = ': ' . role_get_name($role, $context);
}
$user_string .= $rolename;
}
$user_picture = new user_picture($USER);
$userimgsrc = $user_picture->get_url($PAGE);
$user_menu = array("<li class='dropdown'>");
$user_menu[] = "<a class='dropdown-toggle' data-toggle='dropdown' href='#' style='min-height: 50px'>";
$user_menu[] = "<img class='nav-avatar' src='" . $userimgsrc . "'>";
$user_menu[] = "<span class='hidden-xs'>" . $user_string . "</span>";
$user_menu[] = "</a>";
$user_menu[] = "<ul class='dropdown-menu dropdown-menu-right'>";
if ($role_switched) {
$url = new moodle_url('/course/switchrole.php', array('id' => $course->id, 'sesskey' => sesskey(), 'switchrole' => 0, 'returnurl' => $this->page->url->out_as_local_url(false)));
$user_menu[] = "<li><a href='" . $url . "'>" . get_string('switchrolereturn') . "</a></li>";
}
$user_menu[] = "<li><a href='" . $CFG->wwwroot . "/user/profile.php?id=" . $USER->id . "'>My Profile</a></li>";
$user_menu[] = "<li class='menu-item-resources'><a href='/'>My Modules</a></li>";
$user_menu[] = "<li id='student-email-link' style='display: none'><a href='http://studentmail.falmouth.ac.uk/'>My Email</a></li>";
$user_menu[] = "<li id='staff-email-link' style='display: none'><a href='http://mailspace.falmouth.ac.uk/'>My Email</a></li>";
$user_menu[] = "<li><a href='http://mytimetable.falmouth.ac.uk/'>My Timetable</a></li>";
$user_menu[] = "<li class='divider'></li>";
$user_menu[] = "<li><a href='" . $CFG->wwwroot . "/login/logout.php?sesskey=" . sesskey() . "'>" . get_string('logout') . '</a></li>';
$user_menu[] = "</ul></li>";
return implode("", $user_menu);
}
示例11: get_item_ratings
/**
* Retrieve a list of ratings for a given item (forum post etc)
*
* @param string $contextlevel course, module, user...
* @param int $instanceid the instance if for the context element
* @param string $component the name of the component
* @param string $ratingarea rating area
* @param int $itemid the item id
* @param int $scaleid the scale id
* @param string $sort sql order (firstname, rating or timemodified)
* @return array Result and possible warnings
* @throws moodle_exception
* @since Moodle 2.9
*/
public static function get_item_ratings($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $sort)
{
global $USER, $PAGE;
$warnings = array();
$arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid, 'sort' => $sort);
// Validate and normalize parameters.
$params = self::validate_parameters(self::get_item_ratings_parameters(), $arrayparams);
$context = self::get_context_from_params($params);
self::validate_context($context);
// Minimal capability required.
$callbackparams = array('contextid' => $context->id, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid);
if (!has_capability('moodle/rating:view', $context) || !component_callback($component, 'rating_can_see_item_ratings', array($callbackparams), true)) {
throw new moodle_exception('noviewrate', 'rating');
}
list($context, $course, $cm) = get_context_info_array($context->id);
// Can we see all ratings?
$canviewallratings = has_capability('moodle/rating:viewall', $context);
// Create the Sql sort order string.
switch ($params['sort']) {
case 'firstname':
$sqlsort = "u.firstname ASC";
break;
case 'rating':
$sqlsort = "r.rating ASC";
break;
default:
$sqlsort = "r.timemodified ASC";
}
$ratingoptions = new stdClass();
$ratingoptions->context = $context;
$ratingoptions->component = $params['component'];
$ratingoptions->ratingarea = $params['ratingarea'];
$ratingoptions->itemid = $params['itemid'];
$ratingoptions->sort = $sqlsort;
$rm = new rating_manager();
$ratings = $rm->get_all_ratings_for_item($ratingoptions);
$scalemenu = make_grades_menu($params['scaleid']);
// If the scale was changed after ratings were submitted some ratings may have a value above the current maximum.
// We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0.
$maxrating = max(array_keys($scalemenu));
$results = array();
foreach ($ratings as $rating) {
if ($canviewallratings || $USER->id == $rating->userid) {
if ($rating->rating > $maxrating) {
$rating->rating = $maxrating;
}
// The rating object has all the required fields for generating the picture url.
$userpicture = new user_picture($rating);
$userpicture->size = 1;
// Size f1.
$profileimageurl = $userpicture->get_url($PAGE)->out(false);
$result = array();
$result['id'] = $rating->id;
$result['userid'] = $rating->userid;
$result['userpictureurl'] = $profileimageurl;
$result['userfullname'] = fullname($rating);
$result['rating'] = $scalemenu[$rating->rating];
$result['timemodified'] = $rating->timemodified;
$results[] = $result;
}
}
return array('ratings' => $results, 'warnings' => $warnings);
}
示例12: api_update_attendee
/**
* Update attendee.
*
* @throws \coding_exception
*/
protected function api_update_attendee()
{
$sessionid = $this->collaborate->sessionid;
if (has_capability('mod/collaborate:moderate', $this->context)) {
$role = 'moderator';
} else {
if (has_capability('mod/collaborate:participate', $this->context)) {
$role = 'participant';
} else {
return new \moodle_url('/mod/collaborate/view.php', ['id' => $this->cm->id]);
}
}
$attendee = new HtmlAttendee($this->user->id, $role);
$attendee->setDisplayName(\core_text::substr(fullname($this->user), 0, 80));
$avatar = new \user_picture($this->user);
// Note, we get the avatar url for the site instance and don't use the $PAGE object so that this function is
// unit testable.
$page = new \moodle_page();
$page->set_context(\context_system::instance());
$avatarurl = $avatar->get_url($page);
$attendee->setAvatarUrl(new \SoapVar('<ns1:avatarUrl><![CDATA[' . $avatarurl . ']]></ns1:avatarUrl>', XSD_ANYXML));
$satts = new UpdateHtmlSessionAttendee($sessionid, $attendee);
$result = $this->api->UpdateHtmlSessionAttendee($satts);
if (!$result || !method_exists($result, 'getUrl')) {
return false;
}
$url = $result->getUrl();
return $url;
}
示例13: anon_user_picture
function anon_user_picture(stdClass $userin)
{
global $PAGE;
$user = clone $userin;
$user->imagealt = '';
$user->picture = '';
$userpicture = new user_picture($user);
if (empty($userpicture->size)) {
$size = 35;
} else {
if ($userpicture->size === true or $userpicture->size == 1) {
$size = 100;
} else {
$size = $userpicture->size;
}
}
$class = 'user_picture';
if ($user->picture == 0) {
$class .= '';
}
$src = $userpicture->get_url($PAGE, null);
$attributes = array('src' => $src, 'class' => $class, 'width' => $size, 'height' => $size);
// get the image html output fisrt
return html_writer::empty_tag('img', $attributes);
}
示例14: fetch_user_picture
public static function fetch_user_picture($user, $size = 35)
{
global $CFG, $PAGE;
//we ignore size these days Justin 20120705
$upic = new \user_picture($user);
if ($upic) {
return $upic->get_url($PAGE);
} else {
return "";
}
}
示例15: get_choice_results
/**
* Returns user's results for a specific choice
* and a list of those users that did not answered yet.
*
* @param int $choiceid the choice instance id
* @return array of responses details
* @since Moodle 3.0
*/
public static function get_choice_results($choiceid)
{
global $USER, $PAGE;
$params = self::validate_parameters(self::get_choice_results_parameters(), array('choiceid' => $choiceid));
if (!($choice = choice_get_choice($params['choiceid']))) {
throw new moodle_exception("invalidcoursemodule", "error");
}
list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice');
$context = context_module::instance($cm->id);
self::validate_context($context);
$groupmode = groups_get_activity_groupmode($cm);
// Check if we have to include responses from inactive users.
$onlyactive = $choice->includeinactive ? false : true;
$users = choice_get_response_data($choice, $cm, $groupmode, $onlyactive);
// Show those who haven't answered the question.
if (!empty($choice->showunanswered)) {
$choice->option[0] = get_string('notanswered', 'choice');
$choice->maxanswers[0] = 0;
}
$results = prepare_choice_show_results($choice, $course, $cm, $users);
$options = array();
$fullnamecap = has_capability('moodle/site:viewfullnames', $context);
foreach ($results->options as $optionid => $option) {
$userresponses = array();
$numberofuser = 0;
$percentageamount = 0;
if (property_exists($option, 'user') and (has_capability('mod/choice:readresponses', $context) or choice_can_view_results($choice))) {
$numberofuser = count($option->user);
$percentageamount = (double) $numberofuser / (double) $results->numberofuser * 100.0;
if ($choice->publish) {
foreach ($option->user as $userresponse) {
$response = array();
$response['userid'] = $userresponse->id;
$response['fullname'] = fullname($userresponse, $fullnamecap);
$userpicture = new user_picture($userresponse);
$userpicture->size = 1;
// Size f1.
$response['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);
// Add optional properties.
foreach (array('answerid', 'timemodified') as $field) {
if (property_exists($userresponse, 'answerid')) {
$response[$field] = $userresponse->{$field};
}
}
$userresponses[] = $response;
}
}
}
$options[] = array('id' => $optionid, 'text' => external_format_string($option->text, $context->id), 'maxanswer' => $option->maxanswer, 'userresponses' => $userresponses, 'numberofuser' => $numberofuser, 'percentageamount' => $percentageamount);
}
$warnings = array();
return array('options' => $options, 'warnings' => $warnings);
}