function library_get_last_transaction_by_item in Library 7
Same name and namespace in other branches
- 5.2 library.module \library_get_last_transaction_by_item()
- 6.2 library.module \library_get_last_transaction_by_item()
- 6 library.module \library_get_last_transaction_by_item()
Retrieve last transaction for an item.
Parameters
object $item: The item object to fetch transactions for.
null|int $type: The action type of the transaction.
Return value
null|object First matching transaction object.
2 calls to library_get_last_transaction_by_item()
- library_load in ./library.module 
- Menu callback; loads a library object.
- library_node_load in ./library.module 
- Implements hook_node_load().
File
- ./library.module, line 974 
Code
function library_get_last_transaction_by_item($item, $type = NULL) {
  $transactions = library_get_transactions_by_item($item);
  if (isset($transactions)) {
    foreach ($transactions as $transaction) {
      if ($type && $type == $transaction->status_change) {
        return $transaction;
      }
      else {
        // Only return transactions that changed the status of the item.
        switch ($transaction->status_change) {
          case LIBRARY_ACTION_TYPE_UNAVAILABLE:
            return $transaction;
          case LIBRARY_ACTION_TYPE_AVAILABLE:
            return $transaction;
          default:
            break;
        }
      }
    }
    return NULL;
  }
}