use Carp;
-use C4::Biblio qw( GetRecordValue GetMarcBiblio GetFrameworkCode );
+use C4::Biblio qw();
use Koha::Database;
+use Koha::DateUtils qw( dt_from_string );
use base qw(Koha::Object);
use Koha::ArticleRequests;
use Koha::ArticleRequest::Status;
use Koha::IssuingRules;
+use Koha::Subscriptions;
=head1 NAME
=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();
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
=cut
sub holds {
- my ( $self ) = @_;
+ my ( $self, $params, $attributes ) = @_;
+ $attributes->{order_by} = 'priority' unless exists $attributes->{order_by};
+ my $hold_rs = $self->_result->reserves->search( $params, $attributes );
+ return Koha::Holds->_new_from_dbic($hold_rs);
+}
+
+=head3 current_holds
+
+my $holds = $biblio->current_holds
+
+Return the holds placed on this bibliographic record.
+It does not include future holds.
+
+=cut
- my $holds_rs = $self->_result->reserves;
- return Koha::Holds->_new_from_dbic( $holds_rs );
+sub current_holds {
+ my ($self) = @_;
+ my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+ return $self->holds(
+ { reservedate => { '<=' => $dtf->format_date(dt_from_string) } } );
}
=head3 biblioitem
return $self->{_biblioitem};
}
+=head3 subscriptions
+
+my $subscriptions = $self->subscriptions
+
+Returns the related Koha::Subscriptions object for this Biblio object
+
+=cut
+
+sub subscriptions {
+ my ($self) = @_;
+
+ $self->{_subscriptions} ||= Koha::Subscriptions->search( { biblionumber => $self->biblionumber } );
+
+ 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
=cut