You are here

function library_renew_action in Library 7

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. 6 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 61
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_uid) && !empty($item_obj->last_due_date) && $item_obj->last_patron_uid == $patron['uid'] && $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(REQUEST_TIME, $clean, $type);
      if ($duedate) {
        db_update('library_transactions')
          ->fields(array(
          'duedate' => $duedate,
        ))
          ->condition('tid', $item_obj->last_transaction_id)
          ->execute();
        watchdog('library', '%name renewed %item [ID: %item_id ].', array(
          '%name' => check_plain($patron['name']),
          '%item' => check_plain($item['title']),
          '%item_id' => $item['id'],
        ));
      }
    }
  }
}