Bug 19926: Add the Koha::Object->unblessed_all_relateds method
[koha-ffzg.git] / Koha / Biblio.pm
index f0c8308..d226304 100644 (file)
@@ -21,7 +21,7 @@ use Modern::Perl;
 
 use Carp;
 
-use C4::Biblio qw( GetRecordValue GetMarcBiblio GetFrameworkCode );
+use C4::Biblio qw();
 
 use Koha::Database;
 use Koha::DateUtils qw( dt_from_string );
@@ -45,6 +45,20 @@ Koha::Biblio - Koha Biblio Object class
 
 =cut
 
+=head3 store
+
+Overloaded I<store> method to set default values
+
+=cut
+
+sub store {
+    my ( $self ) = @_;
+
+    $self->datecreated( dt_from_string ) unless $self->datecreated;
+
+    return $self->SUPER::store;
+}
+
 =head3 subtitles
 
 my @subtitles = $biblio->subtitles();
@@ -58,7 +72,11 @@ Keyword to MARC mapping for subtitle must be set for this method to return any p
 sub subtitles {
     my ( $self ) = @_;
 
-    return map { $_->{subfield} } @{ GetRecordValue( 'subtitle', GetMarcBiblio( $self->id ), $self->frameworkcode ) };
+    return map { $_->{subfield} } @{
+        C4::Biblio::GetRecordValue(
+            'subtitle',
+            C4::Biblio::GetMarcBiblio({ biblionumber => $self->id }),
+            $self->frameworkcode ) };
 }
 
 =head3 can_article_request
@@ -314,6 +332,28 @@ sub subscriptions {
     return $self->{_subscriptions};
 }
 
+=head3 has_items_waiting_or_intransit
+
+my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit
+
+Tells if this bibliographic record has items waiting or in transit.
+
+=cut
+
+sub has_items_waiting_or_intransit {
+    my ( $self ) = @_;
+
+    if ( Koha::Holds->search({ biblionumber => $self->id,
+                               found => ['W', 'T'] })->count ) {
+        return 1;
+    }
+
+    foreach my $item ( $self->items ) {
+        return 1 if $item->get_transfer;
+    }
+
+    return 0;
+}
 
 =head3 type