You are here

function library_get_status_items in Library 7

Gets the status of multiple items in a node.

Parameters

object $node: Node object to parse.

Return value

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

1 call to library_get_status_items()
library_get_table_row in ./library.module
Returns one table for an item table.

File

./library.module, line 1416

Code

function library_get_status_items($node) {
  if ($node->library_items) {
    $unavailable = array();
    $reference = array();
    foreach ($node->library_items as $item) {
      if ($item['in_circulation'] == LIBRARY_CIRCULATION && $item['library_status'] == LIBRARY_ITEM_AVAILABLE) {

        // @todo This is probably a bug, library_get_status_item() tries to do
        // this correctly.
        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;
}