function merci_get_available_bucket_count in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.2
Same name and namespace in other branches
- 6.2 includes/database.inc \merci_get_available_bucket_count()
- 6 merci.module \merci_get_available_bucket_count()
Calculates the total number of available bucket items for a reservation.
Parameters
$content_type: The bucket content type.
$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
The number of available bucket items.
2 calls to merci_get_available_bucket_count()
- merci_build_reservable_items in includes/
api.inc - Builds the list of all currently reservable items, filtered by date.
- merci_validate_merci_selected_items in includes/
api.inc - @file MERCI - Managed Equipment Reservation Checkout and Inventory
File
- includes/
database.inc, line 677 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_get_available_bucket_count($content_type, $start = NULL, $end = NULL, $reservation = NULL) {
//if there are no dates, return the active total
$reserved_items = 0;
if (!$start) {
//if user is admin/manager and merci template is installed
$count = db_query("SELECT COUNT(n.nid) as total FROM {node} n\n LEFT JOIN {merci_bucket_node} mbn ON n.vid = mbn.vid\n WHERE n.type = :type AND n.status = :status\n AND mbn.merci_default_availability = :merci_default_availability", array(
':type' => $content_type,
':status' => 1,
':merci_default_availability' => 1,
))
->fetchField();
return $count;
}
$total_items_array = merci_reserved_bucket_items($content_type, $start, $end, $reservation);
foreach ($total_items_array as $item_nid => $reservations) {
if (!empty($reservations)) {
$reserved_items++;
}
}
return sizeof($total_items_array) - $reserved_items;
}