Bug 19086: Fix Stored XSS in members/member.pl
[koha.git] / Koha / Biblio.pm
index b33a863..f4e5e2f 100644 (file)
@@ -21,17 +21,19 @@ 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 );
 
 use base qw(Koha::Object);
 
-use C4::Circulation qw(GetIssuingRule);
 use Koha::Items;
 use Koha::Biblioitems;
 use Koha::ArticleRequests;
 use Koha::ArticleRequest::Status;
+use Koha::IssuingRules;
+use Koha::Subscriptions;
 
 =head1 NAME
 
@@ -56,7 +58,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
@@ -121,9 +127,10 @@ sub article_request_type_for_bib {
     my $borrowertype = $borrower->categorycode;
     my $itemtype     = $self->itemtype();
 
-    my $rules        = C4::Circulation::GetIssuingRule( $borrowertype, $itemtype );
+    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowertype, itemtype => $itemtype });
 
-    return $rules->{article_requests} || q{};
+    return q{} unless $issuing_rule;
+    return $issuing_rule->article_requests || q{}
 }
 
 =head3 article_request_type_for_items
@@ -218,8 +225,6 @@ sub article_requests_finished {
 
 =head3 items
 
-=head3 items
-
 my @items = $biblio->items();
 my $items = $biblio->items();
 
@@ -247,12 +252,43 @@ Returns the itemtype for this record.
 sub itemtype {
     my ( $self ) = @_;
 
-    return $self->_biblioitem()->itemtype();
+    return $self->biblioitem()->itemtype();
+}
+
+=head3 holds
+
+my $holds = $biblio->holds();
+
+return the current holds placed on this record
+
+=cut
+
+sub holds {
+    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
+
+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
+=head3 biblioitem
 
-my $field = $self->_biblioitem()->itemtype
+my $field = $self->biblioitem()->itemtype
 
 Returns the related Koha::Biblioitem object for this Biblio object
 
@@ -266,6 +302,23 @@ sub 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 type
 
 =cut