You are here

function library_history in Library 7

Same name and namespace in other branches
  1. 5.2 library.pages.inc \library_history()
  2. 6.2 library.pages.inc \library_history()
  3. 6 library.pages.inc \library_history()

A menu callback to show the transaction history of a single node.

Parameters

object $node: A node object.

Return value

string Themed results of the node's items' transactions.

1 string reference to 'library_history'
library_menu in ./library.module
Implements hook_menu().

File

./library.pages.inc, line 389
Functions for generating page displays related to the library module.

Code

function library_history($node) {
  $duedate_enabled = library_duedates_enabled($node->type);
  if (variable_get('library_' . $node->type, LIBRARY_ITEM_NOT_IN_LIBRARY) == LIBRARY_ITEM_IN_LIBRARY) {
    $header = array(
      t('Date'),
      t('Transaction'),
      t('Notes'),
    );
    if (user_access('access user profiles')) {
      $header[] = t('Patron');
    }
    if ($duedate_enabled) {
      $header[] = t('Due Date');
    }
    $header[] = t('Actions');
    $rows = array();
    $transactions = library_get_transactions_by_node($node);
    if (!empty($transactions[0])) {
      foreach ($transactions as $transaction) {
        $last_item = '';
        $detail_link = '';
        $action_link = '';
        $cur_item = $transaction->item_id;
        $created = format_date($transaction->created, 'small');
        if ($duedate_enabled && $cur_item != $last_item && !empty($transaction->duedate)) {
          $duedate = format_date($transaction->duedate, 'small');
        }
        elseif ($duedate_enabled) {
          $duedate = '';
        }
        if (user_access('administer transactions')) {
          $detail_link = l(t('View Details'), 'library-items/transaction/view/' . $transaction->tid);
        }
        if ($cur_item != $last_item) {
          $item = array(
            'id' => $transaction->item_id,
            'library_status' => $transaction->library_status,
            'last_patron_uid' => $transaction->uid,
            'in_circulation' => $transaction->in_circulation,
          );
          $links = library_get_action_links($item);
          if (!empty($links)) {
            $action_link = implode(" | ", $links);
          }
        }
        $temp_array = array(
          $created,
          $transaction->action_name,
          $transaction->notes,
        );
        if (user_access('access user profiles')) {
          $patron_link = l($transaction->username, 'user/' . $transaction->uid);
          $temp_array[] = $patron_link;
        }
        if (isset($duedate)) {
          $temp_array[] = $duedate;
        }
        if (!empty($detail_link) && !empty($action_link)) {
          $temp_array[] = $detail_link . ' | ' . $action_link;
        }
        elseif (!empty($action_link)) {
          $temp_array[] = $action_link;
        }
        elseif (!empty($detail_link)) {
          $temp_array[] = $detail_link;
        }
        else {
          $temp_array[] = '';
        }
        $rows[] = $temp_array;
        $last_item = $cur_item;
      }
      return theme('table', array(
        'header' => $header,
        'rows' => $rows,
      ));
    }
    else {
      return "<p>No actions have been performed on this item.</p>";
    }
  }
  else {
    return "<p>This item type is not part of the library.</p>";
  }
}