function merci_db_reservations_by_status_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_db_reservations_by_status_in_timespan()
1 call to merci_db_reservations_by_status_in_timespan()
- merci_cron in ./
merci.module - Implementation of hook_cron().
File
- includes/
database.inc, line 266 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_db_reservations_by_status_in_timespan($statuses = array(), $start = NULL, $end = NULL, $older = FALSE) {
// 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'];
$where = array();
$args = array();
if (!empty($statuses)) {
$status_where = array();
foreach ($statuses as $status) {
$status_where[] = 'mr.merci_reservation_status = %d';
$args[] = $status;
}
$where[] = '(' . implode(' OR ', $status_where) . ')';
}
if ($start) {
$args[] = $start;
$where[] = "{$column_start_date} <= '%s'";
}
if ($end) {
$args[] = $end;
// See if we are looking for reservations which have ended.
if ($older and !$start) {
$where[] = "{$column_end_date} < '%s'";
}
else {
$where[] = "{$column_end_date} > '%s'";
}
}
$where = count($where) ? 'WHERE ' . implode(' AND ', $where) : '';
// Select reservation nodes where all reserved items and resources are autocheckout.
$reservations = db_query("SELECT n.nid FROM {node} AS n\n INNER JOIN {" . $table . "} ct ON ct.vid = n.vid\n INNER JOIN {merci_reservation} AS mr ON n.vid = mr.vid\n {$where}", $args);
$nodes = array();
while ($reservation_nid = db_result($reservations)) {
$nodes[$reservation_nid] = $reservation_nid;
}
return $nodes;
}