function merci_cron in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.2
Same name and namespace in other branches
- 6.2 merci.module \merci_cron()
- 6 merci.module \merci_cron()
Implementation of hook_cron().
File
- ./
merci.module, line 811 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_cron() {
// 2009-05-22 20:45:00
$time = date('Y-m-j H:i:s');
$nodes = merci_db_reservations_by_status_in_timespan(array(
MERCI_STATUS_UNCONFIRMED,
MERCI_STATUS_PENDING,
), $time, $time);
foreach (array_keys($nodes) as $reservation_nid) {
$reservation = node_load($reservation_nid);
//check child items of that reservations for autocheckout
foreach ($reservation->merci_reservation_items as $item) {
$node = node_load($item['merci_item_nid']);
if (!$node or !$node->merci_autocheckout) {
// skip out to the next reservation.
continue 2;
}
}
//after checking all of the autocheckout settings for all the child items, are they all autocheckout?
watchdog('merci', "Setting node @reservation_nid to checked out", array(
'@reservation_nid' => $reservation_nid,
));
$reservation->merci_reservation_status = MERCI_STATUS_CHECKED_OUT;
node_save($reservation);
}
$nodes = merci_db_reservations_by_status_in_timespan(array(
MERCI_STATUS_CHECKED_OUT,
), NULL, $time, TRUE);
foreach (array_keys($nodes) as $reservation_nid) {
//check child items of that reservations for autocheckin
$reservation = node_load($reservation_nid);
foreach ($reservation->merci_reservation_items as $item) {
$node = node_load($item['merci_item_nid']);
if (!$node or !$node->merci_autocheckin) {
// skip out to the next reservation.
continue 2;
}
}
//after checking all of the autocheckout settings for all the child items, are they all autocheckout?
watchdog('merci', "Setting node @reservation_nid to checked in", array(
'@reservation_nid' => $reservation_nid,
));
$reservation->merci_original_reservation_status = MERCI_STATUS_CHECKED_OUT;
$reservation->merci_reservation_status = MERCI_STATUS_CHECKED_IN;
node_save($reservation);
}
// Give no shows a one hour grace period.
// TODO: move grace period to admin option.
// 2009-05-22 20:45:00
$time = date('Y-m-j H:i:s', time() - 3600);
//find all pending reservations that have started and set their stauts to no show
$nodes = merci_db_reservations_by_status_in_timespan(array(
MERCI_STATUS_PENDING,
), $time, NULL);
foreach (array_keys($nodes) as $reservation_nid) {
watchdog('merci', "Setting node @reservation_nid to no show", array(
'@reservation_nid' => $reservation_nid,
));
$node = node_load($reservation_nid);
$node->merci_reservation_status = MERCI_STATUS_NO_SHOW;
node_save($node);
}
}