You are here

function library_renew_action in Library 6

Same name and namespace in other branches
  1. 5.2 library.actions.inc \library_renew_action()
  2. 6.2 library.actions.inc \library_renew_action()
  3. 7 library.actions.inc \library_renew_action()

Implementation of a Drupal action. Renews a library item if it is checked out and due dates are enabled.

File

./library.actions.inc, line 72
Hooks into core Drupal actions module

Code

function library_renew_action(&$object, $context = array()) {
  $patron = $context['patron'];
  $item = $context['item'];
  $item_obj = library_load($item['id']);
  if ($item_obj && !empty($item_obj->last_transaction_id) && !empty($item_obj->last_transaction_name) && !empty($item_obj->last_patron_id) && !empty($item_obj->last_due_date) && $item_obj->last_patron_id == $patron['nid'] && $item_obj->in_circulation == LIBRARY_CIRCULATION && $item_obj->library_status == LIBRARY_ITEM_UNAVAILABLE) {
    $type = $item_obj->type;
    $clean = library_clean_action_name($item_obj->last_transaction_name);
    $period = variable_get('library_period_for_' . $type . '_' . $clean, 0);
    if ($period > 0) {
      $duedate = library_get_due_date(time(), $clean, $type);
      if ($duedate) {
        db_query("UPDATE {library_transactions} SET duedate = %d WHERE tid = %d", $duedate, $item_obj->last_transaction_id);
        watchdog('library', '%name renewed %item [ID: %item_id ].', array(
          '%name' => check_plain($patron['name']),
          '%item' => check_plain($item['title']),
          '%item_id' => $item['id'],
        ));
      }
    }
  }
}