function merci_overdue_items in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.2
Same name and namespace in other branches
- 6.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 464 - 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 = field_info_field('field_merci_date');
$table = key($field['storage']['details']['sql']['FIELD_LOAD_CURRENT']);
$column_start_date = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT'][$table]['value'];
$column_end_date = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT'][$table]['value2'];
$where = '';
// 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(
':end' => $start,
':type' => $content_type,
':merci_item_status' => 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.entity_id <> :reservation_nid';
$args[':reservation_nid'] = $reservation_nid;
}
// TODO Please convert this statement to the D7 database API syntax.
$reserved_nodes = db_query("\n SELECT ct.entity_id as 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.revision_id = md.vid\n INNER JOIN {merci_{$merci_type}_node} m on md.merci_placeholder_nid = m.nid\n INNER JOIN {node} ctn on ct.revision_id = ctn.vid\n INNER JOIN {node} mn on m.vid = mn.vid\n WHERE ({$column_end_date} <= :end)\n AND mn.type = :type\n AND md.merci_item_nid !=0\n AND md.merci_item_status = :merci_item_status\n {$where}", $args);
// Use up items for assigned nodes.
foreach ($reserved_nodes as $node) {
//$node = (array) $node;
$total_items_array[$node->merci_item_nid][$node->nid] = $node;
}
return isset($total_items_array) ? $total_items_array : NULL;
}