You are here

function library_get_action_links in Library 7

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

Returns the actions available for an item.

Parameters

array $item: An item array containing id, last_patron_uid, circulation and status.

Return value

array Formatted list of action links.

4 calls to library_get_action_links()
library_history in ./library.pages.inc
A menu callback to show the transaction history of a single node.
library_history_single_user in ./library.pages.inc
The menu callback to show the transaction history of a single user.
library_overdue_items in ./library.pages.inc
Computes all overdue items.
theme_library_items in ./library.theme.inc
Theme library items.

File

./library.module, line 1079

Code

function library_get_action_links($item) {
  $aids = array();
  $secondary_aids = array();
  $actions = array();
  $secondary_actions = array();
  if ($item['in_circulation'] == LIBRARY_REFERENCE_ONLY) {
    $reference_actions = variable_get('library_links_display_reference', array());
    foreach ($reference_actions as $aid) {
      $aids[] = $aid;
    }
  }
  elseif ($item['library_status'] == LIBRARY_ITEM_AVAILABLE) {
    $available_actions = variable_get('library_links_display_available', array());
    foreach ($available_actions as $aid) {
      $aids[] = $aid;
    }
  }
  else {
    $unavailable_actions = variable_get('library_links_display_unavailable', array());
    foreach ($unavailable_actions as $aid) {
      $aids[] = $aid;
    }
  }
  $actions = library_actions($aids, FALSE);
  $action_links = array();
  $patron_uid = '';
  $librarian = user_access('administer transactions') && user_access('access user profiles');
  if (!$librarian) {
    global $user;
    $patron_uid = $user->uid;
  }
  foreach ($actions as $aid => $action) {
    if (($action['status_change'] == LIBRARY_ACTION_TYPE_AVAILABLE || $item['library_status'] == LIBRARY_ITEM_UNAVAILABLE) && !empty($item['last_patron_uid'])) {
      if (empty($patron_uid) || $item['last_patron_uid'] == $patron_uid) {
        $action_links[] = l($action['name'], 'library-items/transaction/' . $aid . '/' . $item['id'] . '/' . $item['last_patron_uid']);
      }
    }
    else {
      $action_links[] = l($action['name'], 'library-items/transaction/' . $aid . '/' . $item['id']);
    }
  }
  return $action_links;
}