function merci_get_reservable_items in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 6 merci.module \merci_get_reservable_items()
- 7.2 includes/database.inc \merci_get_reservable_items()
Pulls an array of items that are reservable for the content type and date range.
Parameters
$content_type: The content type name of the bucket/resource.
$start: Start time in DATETIME format UTC timezone.
$end: End time in DATETIME format UTC timezone.
$reservation_nid: (Optional) A reservation nid to exclude from the reserved items.
Return value
An array of reservable items, in select option format.
3 calls to merci_get_reservable_items()
- merci_build_reservable_items in includes/
api.inc - Builds the list of all currently reservable items, filtered by date.
- merci_get_available_bucket_items in includes/
api.inc - Pulls items available to assign to a bucket for a reservation.
- merci_views_handler_filter_reserved_item_nid::allowed_values in handlers/
merci_views_handler_filter_reserved_item_nid.inc
File
- includes/
database.inc, line 332 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_get_reservable_items($content_type, $start = NULL, $end = NULL, $reservation_nid = NULL, $overdue = TRUE) {
$merci_type = merci_type_setting($content_type);
// Pull reservable items. This query takes the following into consideration:
// 1. Pulls all all item nodes of the content type that are in an available or checked in state,
// 2. Excludes all item nodes that have associated reservations in the date range
// of the this reservation where the item is in an already reserved or checked out state.
// 3. Allows a reservation to be excluded from the exclusions if necessary (this
// is usually used to allow an already assigned item to not conflict with itself.
// 4. Exclude items from past reservations where the item is in a checked out state.
$query = "SELECT n.nid, n.title FROM {node} n\n INNER JOIN {merci_reservation_item_node} m ON n.vid = m.vid\n WHERE m.merci_default_availability IN (%d, %d)\n AND n.type = '%s'\n AND m.merci_sub_type = %d\n ";
$args = array(
MERCI_AVA_F,
MERCI_AVA_T,
$content_type,
MERCI_SUB_TYPE_ITEM,
);
if ($start) {
// 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'];
$args = array_merge($args, array(
$start,
$end,
$start,
$end,
$start,
$end,
MERCI_ITEM_STATUS_AVAILABLE,
));
// If there's an already selected bucket item, then we need to make sure we
// include it in the list of available items.
$query .= "\n AND n.nid NOT IN\n (SELECT md2.merci_item_nid FROM {" . $table . "} ct\n INNER JOIN {merci_reservation_detail} md2 ON ct.vid = md2.vid\n INNER JOIN {merci_reservation_item_node} m2 ON md2.merci_item_nid = m2.nid\n INNER JOIN {node} ctn ON ctn.vid = ct.vid\n INNER JOIN {node} m2n ON m2.vid = m2n.vid\n WHERE (\n (\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 AND NOT md2.merci_item_status <= %d\n ) ";
if ($reservation_nid) {
$where = ' AND md2.nid <> %d';
$args[] = $reservation_nid;
}
else {
$where = '';
}
$query .= "\n )\n {$where}\n )\n ";
}
$query .= " ORDER BY n.title";
$items = db_query($query, $args);
$options = array();
while ($item = db_fetch_object($items)) {
$options[$item->nid] = $item->title;
}
if ($overdue) {
$overdue_items_array = merci_overdue_items($content_type, $start, $reservation_nid);
if (!empty($overdue_items_array)) {
foreach ($options as $item_nid => $title) {
if (array_key_exists($item_nid, $overdue_items_array)) {
unset($options[$item_nid]);
}
}
}
}
return $options;
}