You are here

function privatemsg_message_load_multiple in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg.module \privatemsg_message_load_multiple()
  2. 7.2 privatemsg.module \privatemsg_message_load_multiple()
  3. 7 privatemsg.module \privatemsg_message_load_multiple()

Load multiple messages.

Parameters

$pmids: Array of Message ids, pm.mid field

$account: For which account the message should be loaded. Defaults to the current user.

Related topics

2 calls to privatemsg_message_load_multiple()
privatemsg_message_load in ./privatemsg.module
Load a single message.
privatemsg_thread_load in ./privatemsg.module
Load a thread with all the messages and participants.

File

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

Code

function privatemsg_message_load_multiple($pmids, $account = NULL) {

  // Avoid SQL error that would happen with an empty pm.mid IN () clause.
  if (empty($pmids)) {
    return array();
  }
  $query = _privatemsg_assemble_query('load', $pmids, $account);
  $result = db_query($query['query']);
  $messages = array();
  while ($message = db_fetch_array($result)) {

    // Load author of message.
    if (!($message['author'] = user_load($message['author']))) {

      // If user does not exist, load anonymous user.
      $message['author'] = user_load(array(
        'uid' => 0,
      ));
    }
    $returned = module_invoke_all('privatemsg_message_load', $message);
    if (!empty($returned)) {
      $message = array_merge_recursive($returned, $message);
    }
    $messages[$message['mid']] = $message;
  }
  return $messages;
}