You are here

function merci_overdue_items in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2

Same name and namespace in other branches
  1. 7.2 includes/database.inc \merci_overdue_items()
3 calls to merci_overdue_items()
merci_get_reservable_items in includes/database.inc
Pulls an array of items that are reservable for the content type and date range.
merci_reserved_bucket_items in includes/database.inc
merci_validate_merci_selected_items in includes/api.inc
@file MERCI - Managed Equipment Reservation Checkout and Inventory

File

includes/database.inc, line 416
MERCI - Managed Equipment Reservation Checkout and Inventory

Code

function merci_overdue_items($content_type, $start, $reservation_nid = NULL) {

  // Determine CCK table and columns the date data is stored in.
  $field = content_fields('field_merci_date');
  $db_info = content_database_info($field);
  $table = $db_info['table'];
  $column_start_date = $db_info['columns']['value']['column'];
  $column_end_date = $db_info['columns']['value2']['column'];

  // pull reservations in the past which are still checked out.
  $start = date_create($start, timezone_open("UTC")) >= date_create("now") ? gmdate("Y-m-d H:i:s") : $start;
  $args = array(
    $start,
    $content_type,
    MERCI_ITEM_STATUS_CHECKED_OUT,
  );
  $merci_type = merci_type_setting($content_type);

  // If we're checking an existing reservation, exclude it from the
  // reserved items.
  if (isset($reservation_nid)) {
    $where = ' AND ct.nid <> %d';
    $args[] = $reservation_nid;
  }
  else {
    $where = '';
  }
  $reserved_nodes = db_query("\n    SELECT ct.nid,{$column_start_date} AS field_merci_date_value, {$column_end_date} AS field_merci_date_value2 ,md.merci_item_nid FROM {" . $table . "} ct\n    INNER JOIN {merci_reservation_detail} md on ct.vid = md.vid\n    INNER JOIN {merci_{$merci_type}_node} m on md.merci_placeholder_nid = m.nid\n    INNER JOIN {node} ctn on ct.vid = ctn.vid\n    INNER JOIN {node} mn on m.vid = mn.vid\n    WHERE ({$column_end_date} <= '%s')\n    AND mn.type = '%s'\n    AND md.merci_item_nid !=0\n    AND md.merci_item_status = %d\n    {$where}", $args);

  // Use up items for assigned nodes.
  while ($node = db_fetch_object($reserved_nodes)) {
    $total_items_array[$node->merci_item_nid][$node->nid] = $node;
  }
  return isset($total_items_array) ? $total_items_array : array();
}