3 # Copyright ByWater Solutions 2014
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use C4::Biblio qw( GetRecordValue GetMarcBiblio GetFrameworkCode );
28 use base qw(Koha::Object);
31 use Koha::Biblioitems;
32 use Koha::ArticleRequests;
33 use Koha::ArticleRequest::Status;
34 use Koha::IssuingRules;
35 use Koha::Subscriptions;
39 Koha::Biblio - Koha Biblio Object class
49 my @subtitles = $biblio->subtitles();
51 Returns list of subtitles for a record.
53 Keyword to MARC mapping for subtitle must be set for this method to return any possible values.
60 return map { $_->{subfield} } @{ GetRecordValue( 'subtitle', GetMarcBiblio( $self->id ), $self->frameworkcode ) };
63 =head3 can_article_request
65 my $bool = $biblio->can_article_request( $borrower );
67 Returns true if article requests can be made for this record
69 $borrower must be a Koha::Patron object
73 sub can_article_request {
74 my ( $self, $borrower ) = @_;
76 my $rule = $self->article_request_type($borrower);
77 return q{} if $rule eq 'item_only' && !$self->items()->count();
78 return 1 if $rule && $rule ne 'no';
83 =head3 article_request_type
85 my $type = $biblio->article_request_type( $borrower );
87 Returns the article request type based on items, or on the record
88 itself if there are no items.
90 $borrower must be a Koha::Patron object
94 sub article_request_type {
95 my ( $self, $borrower ) = @_;
97 return q{} unless $borrower;
99 my $rule = $self->article_request_type_for_items( $borrower );
100 return $rule if $rule;
102 # If the record has no items that are requestable, go by the record itemtype
103 $rule = $self->article_request_type_for_bib($borrower);
104 return $rule if $rule;
109 =head3 article_request_type_for_bib
111 my $type = $biblio->article_request_type_for_bib
113 Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record
117 sub article_request_type_for_bib {
118 my ( $self, $borrower ) = @_;
120 return q{} unless $borrower;
122 my $borrowertype = $borrower->categorycode;
123 my $itemtype = $self->itemtype();
125 my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowertype, itemtype => $itemtype });
127 return q{} unless $issuing_rule;
128 return $issuing_rule->article_requests || q{}
131 =head3 article_request_type_for_items
133 my $type = $biblio->article_request_type_for_items
135 Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record's items
137 If there is a conflict where some items are 'bib_only' and some are 'item_only', 'bib_only' will be returned.
141 sub article_request_type_for_items {
142 my ( $self, $borrower ) = @_;
145 foreach my $item ( $self->items()->as_list() ) {
146 my $rule = $item->article_request_type($borrower);
147 return $rule if $rule eq 'bib_only'; # we don't need to go any further
151 return 'item_only' if $counts->{item_only};
152 return 'yes' if $counts->{yes};
153 return 'no' if $counts->{no};
157 =head3 article_requests
159 my @requests = $biblio->article_requests
161 Returns the article requests associated with this Biblio
165 sub article_requests {
166 my ( $self, $borrower ) = @_;
168 $self->{_article_requests} ||= Koha::ArticleRequests->search( { biblionumber => $self->biblionumber() } );
170 return wantarray ? $self->{_article_requests}->as_list : $self->{_article_requests};
173 =head3 article_requests_current
175 my @requests = $biblio->article_requests_current
177 Returns the article requests associated with this Biblio that are incomplete
181 sub article_requests_current {
182 my ( $self, $borrower ) = @_;
184 $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
186 biblionumber => $self->biblionumber(),
188 { status => Koha::ArticleRequest::Status::Pending },
189 { status => Koha::ArticleRequest::Status::Processing }
194 return wantarray ? $self->{_article_requests_current}->as_list : $self->{_article_requests_current};
197 =head3 article_requests_finished
199 my @requests = $biblio->article_requests_finished
201 Returns the article requests associated with this Biblio that are completed
205 sub article_requests_finished {
206 my ( $self, $borrower ) = @_;
208 $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
210 biblionumber => $self->biblionumber(),
212 { status => Koha::ArticleRequest::Status::Completed },
213 { status => Koha::ArticleRequest::Status::Canceled }
218 return wantarray ? $self->{_article_requests_finished}->as_list : $self->{_article_requests_finished};
223 my @items = $biblio->items();
224 my $items = $biblio->items();
226 Returns the related Koha::Items object for this biblio in scalar context,
227 or list of Koha::Item objects in list context.
234 $self->{_items} ||= Koha::Items->search( { biblionumber => $self->biblionumber() } );
236 return wantarray ? $self->{_items}->as_list : $self->{_items};
241 my $itemtype = $biblio->itemtype();
243 Returns the itemtype for this record.
250 return $self->biblioitem()->itemtype();
255 my $holds = $biblio->holds();
257 return the current holds placed on this record
264 my $holds_rs = $self->_result->reserves;
265 return Koha::Holds->_new_from_dbic( $holds_rs );
270 my $field = $self->biblioitem()->itemtype
272 Returns the related Koha::Biblioitem object for this Biblio object
279 $self->{_biblioitem} ||= Koha::Biblioitems->find( { biblionumber => $self->biblionumber() } );
281 return $self->{_biblioitem};
286 my $subscriptions = $self->subscriptions
288 Returns the related Koha::Subscriptions object for this Biblio object
295 $self->{_subscriptions} ||= Koha::Subscriptions->search( { biblionumber => $self->biblionumber } );
297 return $self->{_subscriptions};
311 Kyle M Hall <kyle@bywatersolutions.com>