本文整理汇总了PHP中get_all_user_name_fields函数的典型用法代码示例。如果您正苦于以下问题:PHP get_all_user_name_fields函数的具体用法?PHP get_all_user_name_fields怎么用?PHP get_all_user_name_fields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_all_user_name_fields函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: local_loginas_extends_settings_navigation
/**
* Adds module specific settings to the settings block.
*
* @param settings_navigation $settings The settings navigation object
* @param stdClass $context The node context
*/
function local_loginas_extends_settings_navigation(settings_navigation $settings, $context)
{
global $DB, $CFG, $PAGE, $USER;
// Course id and context.
$courseid = !empty($PAGE->course->id) ? $PAGE->course->id : SITEID;
$coursecontext = context_course::instance($courseid);
// Must have the loginas capability.
if (!has_capability('moodle/user:loginas', $coursecontext)) {
return;
}
// Set the settings category.
$loginas = $settings->add(get_string('loginas'));
// Login as list by admin setting.
if (is_siteadmin($USER)) {
// Admin settings page.
$url = new moodle_url('/admin/settings.php', array('section' => 'localsettingloginas'));
$loginas->add(get_string('settings'), $url, $settings::TYPE_SETTING);
// Users list.
$loginasusers = array();
// Since 2.6, use all the required fields.
$ufields = 'id, ' . get_all_user_name_fields(true);
// Get users by id.
if ($configuserids = get_config('local_loginas', 'loginasusers')) {
$userids = explode(',', $configuserids);
if ($users = $DB->get_records_list('user', 'id', $userids, '', $ufields)) {
$loginasusers = $users;
}
}
// Get users by username.
if ($configusernames = get_config('local_loginas', 'loginasusernames')) {
$usernames = explode(',', $configusernames);
if ($users = $DB->get_records_list('user', 'username', $usernames, '', $ufields)) {
$loginasusers = $loginasusers + $users;
}
}
// Add action links for specified users.
if ($loginasusers) {
$params = array('id' => $courseid, 'sesskey' => sesskey());
foreach ($loginasusers as $userid => $lauser) {
$url = new moodle_url('/course/loginas.php', $params);
$url->param('user', $userid);
$loginas->add(fullname($lauser, true), $url, $settings::TYPE_SETTING);
}
}
}
// Course users login as.
if (!($configcourseusers = get_config('local_loginas', 'courseusers'))) {
return;
}
$loggedinas = \core\session\manager::is_loggedinas();
if (!$loggedinas) {
// Ajax link.
$node = $loginas->add(get_string('courseusers', 'local_loginas'), 'javascript:void();', $settings::TYPE_SETTING);
$node->add_class('local_loginas_setting_link');
local_loginas_require_js($PAGE);
}
}
示例2: __construct
/**
* Constructor.
*
* @param string $uniqueid Unique ID.
* @param int $courseid Course ID.
* @param int $groupid Group ID.
*/
public function __construct($uniqueid, $courseid, $groupid)
{
parent::__construct($uniqueid);
$this->courseid = $courseid;
// Define columns.
$this->define_columns(array('time', 'fullname', 'xp', 'eventname'));
$this->define_headers(array(get_string('eventtime', 'block_xp'), get_string('fullname'), get_string('xp', 'block_xp'), get_string('eventname', 'block_xp')));
// Define SQL.
$sqlfrom = '';
$sqlparams = array();
if ($groupid) {
$sqlfrom = '{block_xp_log} x
JOIN {groups_members} gm
ON gm.groupid = :groupid
AND gm.userid = x.userid
LEFT JOIN {user} u
ON x.userid = u.id';
$sqlparams = array('groupid' => $groupid);
} else {
$sqlfrom = '{block_xp_log} x LEFT JOIN {user} u ON x.userid = u.id';
}
// Define SQL.
$this->sql = new stdClass();
$this->sql->fields = 'x.*, ' . get_all_user_name_fields(true, 'u');
$this->sql->from = $sqlfrom;
$this->sql->where = 'courseid = :courseid';
$this->sql->params = array_merge(array('courseid' => $courseid), $sqlparams);
// Define various table settings.
$this->sortable(true, 'time', SORT_DESC);
$this->collapsible(false);
}
示例3: get_comments
/**
* Return comments by pages
*
* @global moodle_database $DB
* @param int $page
* @return array An array of comments
*/
function get_comments($page)
{
global $DB;
if ($page == 0) {
$start = 0;
} else {
$start = $page * $this->perpage;
}
$comments = array();
$usernamefields = get_all_user_name_fields(true, 'u');
$sql = "SELECT c.id, c.contextid, c.itemid, c.component, c.commentarea, c.userid, c.content, {$usernamefields}, c.timecreated\n FROM {comments} c\n JOIN {user} u\n ON u.id=c.userid\n ORDER BY c.timecreated ASC";
$rs = $DB->get_recordset_sql($sql, null, $start, $this->perpage);
$formatoptions = array('overflowdiv' => true);
foreach ($rs as $item) {
// Set calculated fields
$item->fullname = fullname($item);
$item->time = userdate($item->timecreated);
$item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions);
// Unset fields not related to the comment
foreach (get_all_user_name_fields() as $namefield) {
unset($item->{$namefield});
}
unset($item->timecreated);
// Record the comment
$comments[] = $item;
}
$rs->close();
return $comments;
}
示例4: php_report_schedule_export_instance
/**
* Runs and exports, through email, the report instance specified by the
* provided report schedule
*
* @param stdClass $report_schedule The PHP report schedule containing the information
* about the specific report to be exported
*
* @return boolean true on success, otherwise false
*/
function php_report_schedule_export_instance($report_schedule, $now = 0) {
global $CFG, $USER;
if ($now == 0) {
$now = time();
}
$data = unserialize($report_schedule->config);
// Create report to be emailed to recipient
$shortname = $report_schedule->report;
$format = $data['format'];
// Initialize a temp path name
$tmppath = '/temp';
// Create a unique temporary filename to use for this schedule
$filename = tempnam($CFG->dataroot.$tmppath, 'php_report_');
$parameterdata = $data['parameters'];
// Generate the report file
$result = php_report::export_default_instance($shortname, $format, $filename, $parameterdata, $report_schedule->userid, php_report::EXECUTION_MODE_SCHEDULED);
if (!$result) {
//handle failure case
unlink($filename);
return false;
}
// Attach filename to an email - so get recipient...
$recipients_array = explode(',',$data['recipients']);
$from = get_string('noreplyname');
$subject = get_string('email_subject','local_elisreports').$data['label'];
$messagetext = html_to_text($data['message']);
$messagehtml = $data['message'];
$start = strlen($CFG->dataroot);
$attachment = substr($filename,$start);
$attachname = $report_schedule->report.$now.'.'.$data['format'];
// $user->id & all other fields now required by Moodle 2.6+ email_to_user() API which also calls fullname($user)
$user = new stdClass;
$allfields = get_all_user_name_fields();
foreach ($allfields as $field) {
$user->$field = null;
}
$user->id = $USER->id; // let's just use this user as default (TBD)
$user->mailformat = 1;
// Attach the file to the recipients
foreach ($recipients_array as $recipient) {
$user->email = trim($recipient);
email_to_user($user, $from, $subject, $messagetext, $messagehtml, $attachment, $attachname);
}
// Remove the file that was created for this report
unlink($filename);
return true;
}
示例5: get_required_fields
public function get_required_fields()
{
$allnames = get_all_user_name_fields();
$requiredfields = array();
foreach ($allnames as $allname) {
$requiredfields[] = 'um.' . $allname . ' AS modifier' . $allname;
}
return $requiredfields;
}
示例6: get_required_fields
public function get_required_fields()
{
$allnames = get_all_user_name_fields();
$requiredfields = array();
foreach ($allnames as $allname) {
$requiredfields[] = 'uc.' . $allname . ' AS creator' . $allname;
}
$requiredfields[] = 'q.timecreated';
return $requiredfields;
}
示例7: __construct
/**
* Constructor.
*
* @param int $currentuserid The current user we are wanting to view messages for
* @param int $otheruserid The other user we are wanting to view messages for
* @param array $messages
*/
public function __construct($currentuserid, $otheruserid, $messages)
{
$ufields = 'id, ' . get_all_user_name_fields(true) . ', lastaccess';
$this->currentuserid = $currentuserid;
if ($otheruserid) {
$this->otheruserid = $otheruserid;
$this->otheruser = \core_user::get_user($otheruserid, $ufields, MUST_EXIST);
}
$this->messages = $messages;
}
示例8: local_hub_create_contact_user
/**
* Construct an object to supply to email_to_user()
*
* @param string $email the required email address
* @param string $firstname The desired user first name
* @return stdClass An object that can be supplied to email_to_user()
*/
function local_hub_create_contact_user($email, $firstname)
{
$contactuser = new stdClass();
// Need an id, can't use id=0. would rather not use id=1, lets fool the api while we're still trying to use a fake user to send to.
$contactuser->id = 2;
// Used to retrieve the mailcharset user preference which defaults to 0.
$contactuser->email = $email;
$contactuser->firstname = $firstname;
$contactuser->lastname = '';
foreach (get_all_user_name_fields() as $namefield) {
if (!isset($contactuser->{$namefield})) {
$contactuser->{$namefield} = '';
}
}
return $contactuser;
}
示例9: __construct
/**
* Constructor.
*
* @param string $uniqueid Unique ID.
*/
public function __construct($uniqueid, $courseid)
{
parent::__construct($uniqueid);
$this->courseid = $courseid;
// Define columns.
$this->define_columns(array('time', 'fullname', 'xp', 'eventname', 'actions'));
$this->define_headers(array(get_string('eventtime', 'block_xp'), get_string('fullname'), get_string('xp', 'block_xp'), get_string('eventname', 'block_xp'), ''));
// Define SQL.
$this->sql = new stdClass();
$this->sql->fields = 'x.*, ' . get_all_user_name_fields(true, 'u');
$this->sql->from = '{block_xp_log} x LEFT JOIN {user} u ON x.userid = u.id';
$this->sql->where = 'courseid = :courseid';
$this->sql->params = array('courseid' => $courseid);
// Define various table settings.
$this->sortable(true, 'time', SORT_DESC);
$this->collapsible(false);
}
示例10: get_content
function get_content()
{
global $CFG, $USER, $DB;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass();
// get all the mentees, i.e. users you have a direct assignment to
$allusernames = get_all_user_name_fields(true, 'u');
if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, {$allusernames}\n FROM {role_assignments} ra, {context} c, {user} u\n WHERE ra.userid = ?\n AND ra.contextid = c.id\n AND c.instanceid = u.id\n AND c.contextlevel = " . CONTEXT_USER, array($USER->id))) {
$this->content->text = '<ul>';
foreach ($usercontexts as $usercontext) {
$this->content->text .= '<li><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $usercontext->instanceid . '&course=' . SITEID . '">' . fullname($usercontext) . '</a></li>';
}
$this->content->text .= '</ul>';
}
$this->content->footer = '';
return $this->content;
}
示例11: definition
public function definition()
{
global $COURSE;
$context = context_course::instance($COURSE->id);
$namefields = get_all_user_name_fields(true, 'u');
$students = get_enrolled_users($context, 'mod/attendance:canbelisted', 0, 'u.id,' . $namefields . ',u.email', 'u.lastname, u.firstname', 0, 0, true);
$partarray = array();
foreach ($students as $student) {
$partarray[$student->id] = fullname($student) . ' (' . $student->email . ')';
}
$mform = $this->_form;
$description = $this->_customdata['description'];
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'userid', 0);
$mform->setType('userid', PARAM_INT);
$mform->addElement('header', 'attheader', get_string('tempusermerge', 'attendance'));
$mform->addElement('static', 'description', get_string('tempuser', 'attendance'), $description);
$mform->addElement('select', 'participant', get_string('participant', 'attendance'), $partarray);
$mform->addElement('static', 'requiredentries', '', get_string('requiredentries', 'attendance'));
$mform->addHelpButton('requiredentries', 'requiredentry', 'attendance');
$this->add_action_buttons(true, get_string('mergeuser', 'attendance'));
}
示例12: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $DB;
// Generate new password emails for users - ppl expect these generated asap.
if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
mtrace('Creating passwords for new users...');
$usernamefields = get_all_user_name_fields(true, 'u');
$newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.auth, u.deleted,\n u.suspended, u.emailstop, u.mnethostid, u.mailformat,\n {$usernamefields}, u.username, u.lang,\n p.id as prefid\n FROM {user} u\n JOIN {user_preferences} p ON u.id=p.userid\n WHERE p.name='create_password' AND p.value='1' AND\n u.email !='' AND u.suspended = 0 AND\n u.auth != 'nologin' AND u.deleted = 0");
// Note: we can not send emails to suspended accounts.
foreach ($newusers as $newuser) {
// Use a low cost factor when generating bcrypt hash otherwise
// hashing would be slow when emailing lots of users. Hashes
// will be automatically updated to a higher cost factor the first
// time the user logs in.
if (setnew_password_and_mail($newuser, true)) {
unset_user_preference('create_password', $newuser);
set_user_preference('auth_forcepasswordchange', 1, $newuser);
} else {
trigger_error("Could not create and mail new user password!");
}
}
$newusers->close();
}
}
示例13: get_role_users
/**
* Gets all the users assigned this role in this context or higher
*
* @param int $roleid (can also be an array of ints!)
* @param context $context
* @param bool $parent if true, get list of users assigned in higher context too
* @param string $fields fields from user (u.) , role assignment (ra) or role (r.)
* @param string $sort sort from user (u.) , role assignment (ra.) or role (r.).
* null => use default sort from users_order_by_sql.
* @param bool $all true means all, false means limit to enrolled users
* @param string $group defaults to ''
* @param mixed $limitfrom defaults to ''
* @param mixed $limitnum defaults to ''
* @param string $extrawheretest defaults to ''
* @param array $whereorsortparams any paramter values used by $sort or $extrawheretest.
* @return array
*/
function get_role_users($roleid, context $context, $parent = false, $fields = '',
$sort = null, $all = true, $group = '',
$limitfrom = '', $limitnum = '', $extrawheretest = '', $whereorsortparams = array()) {
global $DB;
if (empty($fields)) {
$allnames = get_all_user_name_fields(true, 'u');
$fields = 'u.id, u.confirmed, u.username, '. $allnames . ', ' .
'u.maildisplay, u.mailformat, u.maildigest, u.email, u.emailstop, u.city, '.
'u.country, u.picture, u.idnumber, u.department, u.institution, '.
'u.lang, u.timezone, u.lastaccess, u.mnethostid, r.name AS rolename, r.sortorder, '.
'r.shortname AS roleshortname, rn.name AS rolecoursealias';
}
$parentcontexts = '';
if ($parent) {
$parentcontexts = substr($context->path, 1); // kill leading slash
$parentcontexts = str_replace('/', ',', $parentcontexts);
if ($parentcontexts !== '') {
$parentcontexts = ' OR ra.contextid IN ('.$parentcontexts.' )';
}
}
if ($roleid) {
list($rids, $params) = $DB->get_in_or_equal($roleid, SQL_PARAMS_NAMED, 'r');
$roleselect = "AND ra.roleid $rids";
} else {
$params = array();
$roleselect = '';
}
if ($coursecontext = $context->get_course_context(false)) {
$params['coursecontext'] = $coursecontext->id;
} else {
$params['coursecontext'] = 0;
}
if ($group) {
$groupjoin = "JOIN {groups_members} gm ON gm.userid = u.id";
$groupselect = " AND gm.groupid = :groupid ";
$params['groupid'] = $group;
} else {
$groupjoin = '';
$groupselect = '';
}
$params['contextid'] = $context->id;
if ($extrawheretest) {
$extrawheretest = ' AND ' . $extrawheretest;
}
if ($whereorsortparams) {
$params = array_merge($params, $whereorsortparams);
}
if (!$sort) {
list($sort, $sortparams) = users_order_by_sql('u');
$params = array_merge($params, $sortparams);
}
if ($all === null) {
// Previously null was used to indicate that parameter was not used.
$all = true;
}
if (!$all and $coursecontext) {
// Do not use get_enrolled_sql() here for performance reasons.
$ejoin = "JOIN {user_enrolments} ue ON ue.userid = u.id
JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :ecourseid)";
$params['ecourseid'] = $coursecontext->instanceid;
} else {
$ejoin = "";
}
$sql = "SELECT DISTINCT $fields, ra.roleid
FROM {role_assignments} ra
JOIN {user} u ON u.id = ra.userid
JOIN {role} r ON ra.roleid = r.id
$ejoin
LEFT JOIN {role_names} rn ON (rn.contextid = :coursecontext AND rn.roleid = r.id)
$groupjoin
WHERE (ra.contextid = :contextid $parentcontexts)
$roleselect
//.........这里部分代码省略.........
示例14: tempuser_to_user
protected static function tempuser_to_user($tempuser)
{
$ret = (object) array('id' => $tempuser->studentid, 'firstname' => $tempuser->fullname, 'email' => $tempuser->email, 'username' => '', 'enrolmentstatus' => 0, 'enrolmentstart' => 0, 'enrolmentend' => 0, 'picture' => 0, 'type' => 'temporary');
foreach (get_all_user_name_fields() as $namefield) {
if (!isset($ret->{$namefield})) {
$ret->{$namefield} = '';
}
}
return $ret;
}
示例15: forum_get_recent_mod_activity
/**
* Returns all forum posts since a given time in specified forum.
*
* @todo Document this functions args
* @global object
* @global object
* @global object
* @global object
*/
function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid = 0, $groupid = 0)
{
global $CFG, $COURSE, $USER, $DB;
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = $DB->get_record('course', array('id' => $courseid));
}
$modinfo = get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
$params = array($timestart, $cm->instance);
if ($userid) {
$userselect = "AND u.id = ?";
$params[] = $userid;
} else {
$userselect = "";
}
if ($groupid) {
$groupselect = "AND d.groupid = ?";
$params[] = $groupid;
} else {
$groupselect = "";
}
$allnames = get_all_user_name_fields(true, 'u');
if (!($posts = $DB->get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,\n d.timestart, d.timeend, d.userid AS duserid,\n {$allnames}, u.email, u.picture, u.imagealt, u.email\n FROM {forum_posts} p\n JOIN {forum_discussions} d ON d.id = p.discussion\n JOIN {forum} f ON f.id = d.forum\n JOIN {user} u ON u.id = p.userid\n WHERE p.created > ? AND f.id = ?\n {$userselect} {$groupselect}\n ORDER BY p.id ASC", $params))) {
// order by initial posting date
return;
}
$groupmode = groups_get_activity_groupmode($cm, $course);
$cm_context = context_module::instance($cm->id);
$viewhiddentimed = has_capability('mod/forum:viewhiddentimedposts', $cm_context);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$printposts = array();
foreach ($posts as $post) {
if (!empty($CFG->forum_enabletimedposts) and $USER->id != $post->duserid and ($post->timestart > 0 and $post->timestart > time() or $post->timeend > 0 and $post->timeend < time())) {
if (!$viewhiddentimed) {
continue;
}
}
if ($groupmode) {
if ($post->groupid == -1 or $groupmode == VISIBLEGROUPS or $accessallgroups) {
// oki (Open discussions have groupid -1)
} else {
// separate mode
if (isguestuser()) {
// shortcut
continue;
}
if (!in_array($post->groupid, $modinfo->get_groups($cm->groupingid))) {
continue;
}
}
}
$printposts[] = $post;
}
if (!$printposts) {
return;
}
$aname = format_string($cm->name, true);
foreach ($printposts as $post) {
$tmpactivity = new stdClass();
$tmpactivity->type = 'forum';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->sectionnum = $cm->sectionnum;
$tmpactivity->timestamp = $post->modified;
$tmpactivity->content = new stdClass();
$tmpactivity->content->id = $post->id;
$tmpactivity->content->discussion = $post->discussion;
$tmpactivity->content->subject = format_string($post->subject);
$tmpactivity->content->parent = $post->parent;
$tmpactivity->user = new stdClass();
$additionalfields = array('id' => 'userid', 'picture', 'imagealt', 'email');
$additionalfields = explode(',', user_picture::fields());
$tmpactivity->user = username_load_fields_from_object($tmpactivity->user, $post, null, $additionalfields);
$tmpactivity->user->id = $post->userid;
$activities[$index++] = $tmpactivity;
}
return;
}