Bug 18913: Allow symbolic link in /etc/koha/sites
[koha.git] / Koha / Hold.pm
index 5c6d000..949770d 100644 (file)
@@ -32,6 +32,7 @@ use Koha::Biblios;
 use Koha::Items;
 use Koha::Libraries;
 use Koha::Old::Holds;
+use Koha::Calendar;
 
 use base qw(Koha::Object);
 
@@ -45,6 +46,34 @@ Koha::Hold - Koha Hold object class
 
 =cut
 
+=head3 age
+
+returns the number of days since a hold was placed, optionally
+using the calendar
+
+my $age = $hold->age( $use_calendar );
+
+=cut
+
+sub age {
+    my ( $self, $use_calendar ) = @_;
+
+    my $today = dt_from_string;
+    my $age;
+
+    if ( $use_calendar ) {
+        my $calendar = Koha::Calendar->new( branchcode => $self->branchcode );
+        $age = $calendar->days_between( dt_from_string( $self->reservedate ), $today );
+    }
+    else {
+        $age = $today->delta_days( dt_from_string( $self->reservedate ) );
+    }
+
+    $age = $age->in_units( 'days' );
+
+    return $age;
+}
+
 =head3 suspend_hold
 
 my $hold = $hold->suspend_hold( $suspend_until_dt );
@@ -276,6 +305,7 @@ Returns the related Koha::Patron object for this Hold
 
 =cut
 
+# FIXME Should be renamed with ->patron
 sub borrower {
     my ($self) = @_;
 
@@ -316,7 +346,7 @@ sub cancel {
             $self->cancellationdate(dt_from_string);
             $self->priority(0);
             $self->_move_to_old;
-            $self->delete;
+            $self->SUPER::delete(); # Do not add a DELETE log
 
             # now fix the priority on the others....
             C4::Reserves::_FixPriority({ biblionumber => $self->biblionumber });