function _privatemsg_generate_user_array in Privatemsg 6
Same name and namespace in other branches
- 6.2 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.
2 calls to _privatemsg_generate_user_array()
- phptemplate_privatemsg_list_field__participants in ./privatemsg.theme.inc 
- Theme the participants field.
- privatemsg_new in ./privatemsg.module 
File
- ./privatemsg.module, line 44 
- Allows users to send private messages to other users.
Code
function _privatemsg_generate_user_array($userstring, $slice = NULL) {
  static $user_cache = array();
  // 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(',', $userstring);
  if (!is_null($slice)) {
    $users = array_slice($users, $slice);
  }
  $participants = array();
  foreach ($users as $uid) {
    if (!array_key_exists($uid, $user_cache)) {
      $user_cache[$uid] = user_load($uid);
    }
    if (is_object($user_cache[$uid])) {
      $participants[$uid] = $user_cache[$uid];
    }
  }
  return $participants;
}