function _privatemsg_generate_user_array

1 privatemsg.module _privatemsg_generate_user_array($userstring, $slice = NULL)
7-1 privatemsg.module _privatemsg_generate_user_array($string, $slice = NULL)
7-2 privatemsg.module _privatemsg_generate_user_array($string, $slice = NULL)
6-2 privatemsg.module _privatemsg_generate_user_array($string, $slice = NULL)

Generate array 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()
privatemsg_new in ./privatemsg.pages.inc
Form builder function; Write a new private message.
theme_privatemsg_list_field__participants in ./privatemsg.theme.inc
Theme the participants field.

File

./privatemsg.module, line 79
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) {
      $user_ids = privatemsg_user_load_multiple(array($uid));
      if ($account = array_shift($user_ids)) {
        $participants[privatemsg_recipient_key($account)] = $account;
      }
    }
    elseif (strpos($uid, '_') !== FALSE) {
      list($type, $id) = explode('_', $uid);
      $type_info = privatemsg_recipient_get_type($type);
      if ($type_info && isset($type_info['load']) && is_callable($type_info['load'])) {
        $temp_load = $type_info['load'](array($id), $type);
        if ($participant = array_shift($temp_load)) {
          $participants[privatemsg_recipient_key($participant)] = $participant;
        }
      }
    }
  }
  return $participants;
}