You are here

function library_load_items in Library 6

Same name and namespace in other branches
  1. 5.2 library.module \library_load_items()
  2. 6.2 library.module \library_load_items()

Load Library Item Data for a given node

1 call to library_load_items()
library_nodeapi in ./library.module
Implementation of hook_nodeapi()

File

./library.module, line 837

Code

function library_load_items($node) {
  $result = db_query('SELECT id FROM {library} WHERE nid = %d ORDER BY id', $node->nid);
  $items = array();
  $row = 0;
  if ($result) {
    while ($item = db_fetch_object($result)) {
      $library_item = library_load($item->id);
      $items[$row]['library_status'] = $library_item->library_status ? $library_item->library_status : LIBRARY_ITEM_AVAILABLE;
      $items[$row]['last_patron_id'] = $library_item->last_patron_id ? $library_item->last_patron_id : '';
      $items[$row]['last_due_date'] = $library_item->last_due_date ? $library_item->last_due_date : '';
      $items[$row]['last_transaction_id'] = $library_item->last_transaction_id ? $library_item->last_transaction_id : '';
      $items[$row]['last_transaction_name'] = $library_item->last_transaction_name ? $library_item->last_transaction_name : '';
      $items[$row]['id'] = $item->id;
      $items[$row]['in_circulation'] = $library_item->in_circulation;
      $items[$row]['barcode'] = check_plain($library_item->barcode);
      $items[$row]['notes'] = check_plain($library_item->notes);
      $row++;
    }
  }
  else {
    db_query('INSERT INTO {library} (nid, in_circulation, library_status, created) VALUES (%d, %d, %d, %d)', $node->nid, LIBRARY_CIRCULATION, LIBRARY_ITEM_AVAILABLE, time());
    $items[$row]['id'] = db_last_insert_id('library', 'id');
    $items[$row]['in_circulation'] = LIBRARY_CIRCULATION;
    $items[$row]['library_status'] = LIBRARY_ITEM_AVAILABLE;
  }
  return array(
    'items' => $items,
  );
}