function fp_load_user
Search API
7.x db.inc | fp_load_user($user_id) |
6.x db.inc | fp_load_user($user_id) |
4.x db.inc | fp_load_user($user_id) |
5.x db.inc | fp_load_user($user_id) |
Returns back a user object for this user_id. If the user is not found in the users table, it will return NULL. If the user_id requested is 0, the anonymous user object is returned.
24 calls to fp_load_user()
- alerts_advisees_alerts_form in modules/
alerts/ alerts.module - Displays alerts for our various advisees.
- calendar_confirm_cancel_appointment_form_submit in modules/
calendar/ calendar.module - calendar_display_schedule_appointment_page in modules/
calendar/ calendar.module - This is the page which lets students schedule an appointment with the faculty member supplied in the user_id.
- calendar_find_and_remind_notify_upcoming_appointments in modules/
calendar/ calendar.module - This function will find appointments approaching within X number of minutes, and send out notifications to all involved.
- calendar_schedule_appointment_confirm_form in modules/
calendar/ calendar.module - The confirmation form the user will see once they have made their schedule selections.
File
- includes/
db.inc, line 395 - This file contains mostly db shortcuts.
Code
function fp_load_user($user_id) {
$rtn = new stdClass();
if ($user_id <= 0) {
// Return the anonymous user.
$rtn->id = 0;
$rtn->name = t("Anonymous");
$rtn->roles = array(1 => "anonymous user");
$rtn->permissions = fp_get_permissions_for_role(1);
$rtn->email = '';
$rtn->school_id = 0;
$rtn->is_student = FALSE;
$rtn->is_faculty = FALSE;
$rtn->is_disabled = FALSE;
return $rtn;
}
$res = db_query("SELECT * FROM users WHERE user_id = ? ", $user_id);
if (db_num_rows($res) == 0) {
return NULL;
}
$cur = db_fetch_object($res);
$rtn->id = $cur->user_id;
$rtn->name = $cur->user_name;
$rtn->f_name = $cur->f_name;
$rtn->l_name = $cur->l_name;
$rtn->school_id = intval($cur->school_id);
$rtn->email = trim(strtolower($cur->email));
$rtn->cwid = $cur->cwid;
$rtn->is_student = (bool) $cur->is_student;
$rtn->is_faculty = (bool) $cur->is_faculty;
$rtn->is_disabled = (bool) $cur->is_disabled;
$rtn->last_login = (int) $cur->last_login;
$rtn->roles = array();
$rtn->permissions = array();
// Load the user's roles and
$res = db_query("SELECT * FROM user_roles a,
roles c
WHERE a.user_id = ?
AND a.rid = c.rid ", array($user_id));
while ($cur = db_fetch_array($res)) {
if (!isset($rtn->roles [$cur ['rid']])) {
$rtn->roles [$cur ["rid"]] = $cur ["name"];
}
}
// Let's make sure we get the authenticated user role as well, #2.
$rtn->roles [2] = "authenticated user";
// Go through each role and add in the permissions for each role.
foreach ($rtn->roles as $rid => $val) {
$perms = fp_get_permissions_for_role($rid);
// Merge the arrays while KEEPING the original's key. So don't
// use array_merge, use the + operator.
$rtn->permissions = $rtn->permissions + $perms;
}
// Load settings from the user_settings table (if any exist)
$rtn->settings = array();
$res = db_query("SELECT * FROM user_settings WHERE user_id = ?", array($user_id));
while ($cur = db_fetch_array($res)) {
$rtn->settings [$cur ['name']] = $cur ['value'];
}
// Set the user image url...
// See if there are any other modules which might be overriding how we look up user images.
$image_url = @$cur->settings ['image_url'];
$type = 'student';
if ($rtn->is_faculty) {
$type = 'faculty';
}
$modules = invoke_hook("get_user_image_url", array($rtn->cwid, $type));
// Although there might be several modules which will return an image url, we will only use the last one (even if it's blank or FALSE, meaning no picture).
foreach ($modules as $val) {
$image_url = trim($val);
}
$rtn->settings ['image_url'] = $image_url;
// load attributes from user_attributes table (if any exist)
$rtn->attributes = array();
$res = db_query("SELECT * FROM user_attributes WHERE user_id = ?", array($user_id));
while ($cur = db_fetch_array($res)) {
$rtn->attributes [$cur ['name']] = $cur ['value'];
}
return $rtn;
}