You are here

function library_get_status_item in Library 7

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

Returns the status of an item.

Parameters

array $item: An item array (such as present in a fully loaded node).

Return value

bool An item array or an array with a reference to an item depending on state, or false.

1 call to library_get_status_item()
library_handler_field_library_status::render in includes/views/handlers/library_handler_field_library_status.inc
Implements render().

File

./library.module, line 1460

Code

function library_get_status_item($item) {
  if (isset($item)) {
    $unavailable = array();
    $reference = array();
    if ($item['in_circulation'] == LIBRARY_CIRCULATION && $item['library_status'] == LIBRARY_ITEM_AVAILABLE) {
      return $item;
    }
    elseif ($item['in_circulation'] == LIBRARY_CIRCULATION && $item['library_status'] == LIBRARY_ITEM_UNAVAILABLE) {
      if (!empty($item['last_due_date'])) {
        $unavailable[$item['last_due_date']][] = $item;
      }
      else {
        $unavailable[REQUEST_TIME][] = $item;
      }
    }
    else {
      $reference[] = $item;
    }
    if (!empty($reference)) {
      return $reference[0];
    }
    elseif (!empty($unavailable)) {
      foreach ($unavailable as $un_item) {
        return $un_item[0];
      }
    }
  }
  return FALSE;
}