function user_variable_get in User variable 6
Same name and namespace in other branches
- 7 user_variable.module \user_variable_get()
Get variable.
Parameters
$name: Variable name.
$common: If TRUE then the variable does not depend on user ID.
$uid: User ID.
$session: Session ID.
Return value
Variable value.
File
- ./
user_variable.module, line 98 - User variable - Creating and working with user variables.
Code
function user_variable_get($name, $common = FALSE, $uid = 0, $session = '') {
global $user_variables_array, $user;
if ($session === TRUE) {
$session = session_id();
}
elseif ($session === FALSE) {
$session = '';
}
if ($common) {
if ($session == '') {
if (isset($user_variables_array['common_session'][$name])) {
return $user_variables_array['common_session'][$name];
}
}
else {
if (isset($user_variables_array['common'][$session][$name])) {
return $user_variables_array['common'][$session][$name];
}
}
//Get from DB
$result = db_fetch_object(db_query_range("SELECT value FROM {user_variable}\n WHERE common = 1 AND name = '%s' AND sid = '%s'", $name, $session, 0, 1));
if ($session == '') {
return $user_variables_array['common_session'][$name] = isset($result->value) && $result->value ? unserialize($result->value) : FALSE;
}
else {
return $user_variables_array['common'][$session][$name] = isset($result->value) && $result->value ? unserialize($result->value) : FALSE;
}
}
else {
// $common = FALSE
if (!$uid) {
$uid = $user->uid;
}
if ($session == '') {
if (isset($user_variables_array['uid_session'][$uid][$name])) {
return $user_variables_array['uid_session'][$uid][$name];
}
}
else {
if (isset($user_variables_array['uid'][$uid][$session][$name])) {
return $user_variables_array['uid'][$uid][$session][$name];
}
}
//Get from DB
$result = db_fetch_object(db_query_range("SELECT value FROM {user_variable}\n WHERE name = '%s' AND common = 0 AND uid = %d AND sid = '%s'", $name, $uid, $session, 0, 1));
if ($session == '') {
return $user_variables_array['uid_session'][$uid][$name] = isset($result->value) && $result->value ? unserialize($result->value) : FALSE;
}
else {
return $user_variables_array['uid'][$uid][$session][$name] = isset($result->value) && $result->value ? unserialize($result->value) : FALSE;
}
}
}