function _privatemsg_generate_user_array in Privatemsg 6.2
Same name and namespace in other branches
- 6 privatemsg.module \_privatemsg_generate_user_array()
- 7.2 privatemsg.module \_privatemsg_generate_user_array()
- 7 privatemsg.module \_privatemsg_generate_user_array()
Generate aray of user objects based on a string.
Parameters
$userstring: A string with user id, for example 1,2,4. Returned by the list query
Return value
Array with user objects.
3 calls to _privatemsg_generate_user_array()
- phptemplate_privatemsg_list_field__participants in ./
privatemsg.theme.inc - Theme the participants field.
- privatemsg_new in ./
privatemsg.pages.inc - Form builder function; Write a new private message.
- _privatemsg_service_enhance_participants in privatemsg_service/
privatemsg_service.module - Collect additional information about messages participants.
File
- ./
privatemsg.module, line 48 - Allows users to send private messages to other users.
Code
function _privatemsg_generate_user_array($string, $slice = NULL) {
// Convert user uid list (uid1,uid2,uid3) into an array. If $slice is not NULL
// pass that as argument to array_slice(). For example, -4 will only load the
// last four users.
// This is done to avoid loading user objects that are not displayed, for
// obvious performance reasons.
$users = explode(',', $string);
if (!is_null($slice)) {
$users = array_slice($users, $slice);
}
$participants = array();
foreach ($users as $uid) {
// If it is an integer, it is a user id.
if ((int) $uid > 0 && ($account = privatemsg_user_load($uid))) {
$participants[privatemsg_recipient_key($account)] = $account;
}
elseif (($pos = strrpos($uid, '_')) !== FALSE) {
$type = substr($uid, 0, $pos);
$id = substr($uid, $pos + 1);
$type_info = privatemsg_recipient_get_type($type);
if ($type_info && isset($type_info['load']) && is_callable($type_info['load'])) {
if ($participant = reset($type_info['load'](array(
$id,
)))) {
$participants[privatemsg_recipient_key($participant)] = $participant;
}
}
}
}
return $participants;
}