You are here

function messaging_store_get in Messaging 6.3

Same name and namespace in other branches
  1. 5 messaging.store.inc \messaging_store_get()
  2. 6 messaging.store.inc \messaging_store_get()
  3. 6.2 messaging.store.inc \messaging_store_get()

Retrieve from messaging database storage

Parameters

$params: Array of field value pairs

$order: Optional array of field names to order by

$limit: Optional maximum number of rows to retrieve

$pager: Optional pager element for pager queries

$unpack: Optional fully load stored data

File

./messaging.store.inc, line 114
Database storage for the messaging framework

Code

function messaging_store_get($params, $order = NULL, $limit = NULL, $pager = NULL, $unpack = TRUE) {
  $messages = $where = $args = array();
  list($where, $args) = messaging_store_query($params);
  $sql = 'SELECT * FROM {messaging_store}';
  $sql .= $where ? ' WHERE ' . implode(' AND ', $where) : '';
  $sql .= $order ? ' ORDER BY ' . implode(', ', $order) : '';
  if (!is_null($pager)) {
    $result = pager_query($sql, $limit, $pager, NULL, $args);
  }
  elseif ($limit) {
    $result = db_query_range($sql, $args, 0, $limit);
  }
  else {
    $result = db_query($sql, $args);
  }
  while ($msg = db_fetch_object($result)) {
    if ($unpack) {
      $messages[$msg->mqid] = messaging_store_unpack($msg, 'Messaging_Message');
    }
    else {
      $messages[$msg->mqid] = $msg;
    }
  }
  return $messages;
}