You are here

function privatemsg_user_load in Privatemsg 6.2

Privatemsg wrapper function for user_load() with a static cache.

The function additionaly also adds the privatemsg specific recipient id (uid) and recipient type to the user object.

Parameters

$uids: Which uid, or array of uids to load.

Return value

If $uids is a single uid, the user object with the recipient and type properties. Otherwise, if $user is an array of uids, an array of user objects with the recipient and type properties.

11 calls to privatemsg_user_load()
pm_block_user_list in pm_block_user/pm_block_user.pages.inc
Formbuilder function to build a simple form to block users.
pm_block_user_privatemsg_block_message in pm_block_user/pm_block_user.module
Implements hook_privatemsg_block_message().
pm_email_notify_privatemsg_message_recipient_changed in pm_email_notify/pm_email_notify.module
Implements hook_privatemsg_message_recipient_changed().
privatemsg_devel_generate_new_thread in ./privatemsg.devel_generate.inc
Single Message Generation
privatemsg_link in ./privatemsg.module
Implements hook_link().

... See full list

1 string reference to 'privatemsg_user_load'
privatemsg_privatemsg_recipient_type_info in ./privatemsg.module
Implements hook_privatemsg_recipient_type_info().

File

./privatemsg.module, line 2550
Allows users to send private messages to other users.

Code

function privatemsg_user_load($uids) {
  static $user_cache = array();
  $to_load = $uids;
  if (!is_array($to_load)) {
    $to_load = array(
      $uids,
    );
  }
  foreach ($to_load as $uid) {
    if (!array_key_exists($uid, $user_cache)) {
      $user_cache[$uid] = user_load($uid);
      if (is_object($user_cache[$uid])) {
        $user_cache[$uid]->recipient = $user_cache[$uid]->uid;
        $user_cache[$uid]->type = 'user';
      }
    }
  }
  if (is_array($uids)) {
    return array_intersect_key($user_cache, drupal_map_assoc($uids));
  }
  else {
    return $user_cache[$uids];
  }
}