class PrivatemsgMessageController

  1. 7-1 privatemsg.module PrivatemsgMessageController
  2. 7-2 privatemsg.module PrivatemsgMessageController

Private message controller, loads private messages.

Hierarchy

Expanded class hierarchy of PrivatemsgMessageController

1 string reference to 'PrivatemsgMessageController'
privatemsg_entity_info in ./privatemsg.module
Implements hook_entity_info().

File

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

View source
class PrivatemsgMessageController extends DrupalDefaultEntityController {

  protected $account = NULL;

  protected function attachLoad(&$messages, $revision_id = FALSE) {
    global $user;
    foreach ($messages as $message) {
      $message->user = $this->account ? $this->account : $user;
      // Load author of message.
      if (!($message->author = user_load($message->author))) {
        // If user does not exist, load anonymous user.
        $message->author = user_load(0);
      }
    }
    parent::attachLoad($messages, $revision_id);
  }

  protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
    // Remove account from conditions.
    if (isset($conditions['account'])) {
      $this->account = $conditions['account'];
      unset($conditions['account']);
    }

    $query = parent::buildQuery($ids, $conditions, $revision_id);
    $query->fields('pmi', array('is_new', 'thread_id'));
    if ($this->account) {
      $query->condition('pmi.recipient', $this->account->uid)->condition('pmi.type', array('hidden', 'user'));
    }
    else {
      // If no account is given, at least limit the result to a single row per
      // message.
      $query->distinct();
    }
    $query->join('pm_index', 'pmi', "base.mid = pmi.mid");
    return $query;
  }
}

Members

Contains filters are case sensitive