function merci_load_reservations_for_node_in_timespan in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 7.2 includes/database.inc \merci_load_reservations_for_node_in_timespan()
Builds an array representing reservations for a Resource within a given timespan
Return value
An associative array with keys as times (in MySQL datetime format) and values as number of reservations.
2 calls to merci_load_reservations_for_node_in_timespan()
- merci_is_item_reservable in includes/
database.inc - template_preprocess_merci_conflict_grid in theme/
theme.inc - @file MERCI - Managed Equipment Reservation Checkout and Inventory
File
- includes/
database.inc, line 658 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_load_reservations_for_node_in_timespan($item_nid, $type, $start_date, $end_date, $exclude_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'];
/*
*/
$type_settings = merci_type_setting($type);
if ($type_settings == 'bucket' and empty($item_nid)) {
return merci_reserved_bucket_items($type, $start_date, $end_date, $exclude_nid, FALSE);
}
else {
$sql = "SELECT r.nid, {$column_start_date} AS field_merci_date_value, {$column_end_date} AS field_merci_date_value2, merci_item_nid\n FROM {node} n\n JOIN {merci_reservation_detail} d ON n.nid = d.merci_item_nid\n JOIN {" . $table . "} r ON d.vid = r.vid\n JOIN {node} rn ON rn.vid = r.vid\n WHERE n.nid = %d\n AND NOT d.merci_item_status <= %d\n AND\n (({$column_start_date} >= '%s' AND {$column_start_date} <= '%s')\n OR ({$column_end_date} >= '%s' AND {$column_end_date} <= '%s')\n OR ({$column_start_date} <= '%s' AND {$column_end_date} >= '%s'))\n ";
}
$args = array(
$item_nid,
MERCI_ITEM_STATUS_AVAILABLE,
$start_date,
$end_date,
$start_date,
$end_date,
$start_date,
$end_date,
);
// If we're checking an existing reservation, exclude it from the
// reserved items.
if ($exclude_nid) {
$sql .= " AND d.nid <> %d";
$args[] = $exclude_nid;
}
$sql .= " ORDER BY {$column_start_date} ";
$reservations = db_query($sql, $args);
while ($reservation = db_fetch_object($reservations)) {
$return[$item_nid][$reservation->nid] = $reservation;
}
return isset($return) ? $return : NULL;
}