You are here

function library_get_transactions_by_patron in Library 6

Same name and namespace in other branches
  1. 5.2 library.module \library_get_transactions_by_patron()
1 call to library_get_transactions_by_patron()
library_get_transactions_by_node in ./library.module

File

./library.module, line 1037

Code

function library_get_transactions_by_patron($node) {
  $result = db_query('SELECT lt.created, lt.tid, la.aid, la.name as "action_name", la.status_change, lt.patron_id, lt.item_id, lt.duedate, lt.notes, n.title as "item_name", n.nid FROM {library_transactions} lt, {library_actions} la, {node} n WHERE la.aid = lt.action_aid AND n.nid = lt.nid AND lt.patron_id = %d ORDER BY lt.created DESC', $node->nid);
  $items_result = db_query('SELECT DISTINCT item_id FROM {library_transactions} WHERE patron_id = %d', $node->nid);
  $statuses = array();
  $barcodes = array();
  $circulation = array();
  while ($instance = db_fetch_object($items_result)) {
    $item = library_load($instance->item_id);
    $barcodes[$item->id] = $item->barcode;
    $statuses[$item->id] = $item->library_status;
    $circulation[$item->id] = $item->in_circulation;
  }
  $transactions = array();
  while ($transaction = db_fetch_object($result)) {
    $transaction->library_status = $statuses[$transaction->item_id];
    $transaction->barcode = $barcodes[$transaction->item_id];
    $transaction->in_circulation = $circulation[$transaction->item_id];
    $transactions[] = $transaction;
  }
  if (!empty($transactions)) {
    return $transactions;
  }
  else {
    return NULL;
  }
}