function merci_db_reservations_by_status_in_timespan in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.2
Same name and namespace in other branches
- 6.2 includes/database.inc \merci_db_reservations_by_status_in_timespan()
@todo Please document this function.
See also
1 call to merci_db_reservations_by_status_in_timespan()
- merci_cron in ./
merci.module - Implementation of hook_cron().
File
- includes/
database.inc, line 303 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_db_reservations_by_status_in_timespan($statuses = array(), $start = NULL, $end = NULL, $older = TRUE) {
// 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 = array();
$args = array();
if (!empty($statuses)) {
$status_where = array();
foreach ($statuses as $i => $status) {
$key = ':merci_reservation_status' . $i;
$status_where[] = 'mr.merci_reservation_status = ' . $key;
$args[$key] = $status;
}
$where[] = '(' . implode(' OR ', $status_where) . ')';
}
if ($start) {
$args[':start'] = $start;
$where[] = "{$column_start_date} <= :start";
}
if ($end) {
$args[':end'] = $end;
// See if we are looking for reservations which have ended.
if ($older and !$start) {
$where[] = "{$column_end_date} < :end";
}
else {
$where[] = "{$column_end_date} > :end";
}
}
$where = count($where) ? 'WHERE ' . implode(' AND ', $where) : '';
// Select reservation nodes where all reserved items and resources are autocheckout.
// TODO Please convert this statement to the D7 database API syntax.
$reservations = db_query("SELECT n.nid FROM {node} AS n\n INNER JOIN {" . $table . "} ct ON ct.revision_id = n.vid\n INNER JOIN {merci_reservation} AS mr ON n.vid = mr.vid\n {$where}", $args);
$nodes = array();
while ($reservation_nid = $reservations
->fetchField()) {
$nodes[$reservation_nid] = $reservation_nid;
}
return $nodes;
}