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);
30 use C4
::Circulation
qw(GetIssuingRule);
32 use Koha
::Biblioitems
;
33 use Koha
::ArticleRequests
;
34 use Koha
::ArticleRequest
::Status
;
38 Koha::Biblio - Koha Biblio Object class
48 my @subtitles = $biblio->subtitles();
50 Returns list of subtitles for a record.
52 Keyword to MARC mapping for subtitle must be set for this method to return any possible values.
59 return map { $_->{subfield
} } @
{ GetRecordValue
( 'subtitle', GetMarcBiblio
( $self->id ), $self->frameworkcode ) };
62 =head3 can_article_request
64 my $bool = $biblio->can_article_request( $borrower );
66 Returns true if article requests can be made for this record
68 $borrower must be a Koha::Patron object
72 sub can_article_request
{
73 my ( $self, $borrower ) = @_;
75 my $rule = $self->article_request_type($borrower);
76 return q{} if $rule eq 'item_only' && !$self->items()->count();
77 return 1 if $rule && $rule ne 'no';
82 =head3 article_request_type
84 my $type = $biblio->article_request_type( $borrower );
86 Returns the article request type based on items, or on the record
87 itself if there are no items.
89 $borrower must be a Koha::Patron object
93 sub article_request_type
{
94 my ( $self, $borrower ) = @_;
96 return q{} unless $borrower;
98 my $rule = $self->article_request_type_for_items( $borrower );
99 return $rule if $rule;
101 # If the record has no items that are requestable, go by the record itemtype
102 $rule = $self->article_request_type_for_bib($borrower);
103 return $rule if $rule;
108 =head3 article_request_type_for_bib
110 my $type = $biblio->article_request_type_for_bib
112 Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record
116 sub article_request_type_for_bib
{
117 my ( $self, $borrower ) = @_;
119 return q{} unless $borrower;
121 my $borrowertype = $borrower->categorycode;
122 my $itemtype = $self->itemtype();
124 my $rules = C4
::Circulation
::GetIssuingRule
( $borrowertype, $itemtype );
126 return $rules->{article_requests
} || q{};
129 =head3 article_request_type_for_items
131 my $type = $biblio->article_request_type_for_items
133 Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record's items
135 If there is a conflict where some items are 'bib_only' and some are 'item_only', 'bib_only' will be returned.
139 sub article_request_type_for_items
{
140 my ( $self, $borrower ) = @_;
143 foreach my $item ( $self->items()->as_list() ) {
144 my $rule = $item->article_request_type($borrower);
145 return $rule if $rule eq 'bib_only'; # we don't need to go any further
149 return 'item_only' if $counts->{item_only
};
150 return 'yes' if $counts->{yes
};
151 return 'no' if $counts->{no};
155 =head3 article_requests
157 my @requests = $biblio->article_requests
159 Returns the article requests associated with this Biblio
163 sub article_requests
{
164 my ( $self, $borrower ) = @_;
166 $self->{_article_requests
} ||= Koha
::ArticleRequests
->search( { biblionumber
=> $self->biblionumber() } );
168 return wantarray ?
$self->{_article_requests
}->as_list : $self->{_article_requests
};
171 =head3 article_requests_current
173 my @requests = $biblio->article_requests_current
175 Returns the article requests associated with this Biblio that are incomplete
179 sub article_requests_current
{
180 my ( $self, $borrower ) = @_;
182 $self->{_article_requests_current
} ||= Koha
::ArticleRequests
->search(
184 biblionumber
=> $self->biblionumber(),
186 { status
=> Koha
::ArticleRequest
::Status
::Pending
},
187 { status
=> Koha
::ArticleRequest
::Status
::Processing
}
192 return wantarray ?
$self->{_article_requests_current
}->as_list : $self->{_article_requests_current
};
195 =head3 article_requests_finished
197 my @requests = $biblio->article_requests_finished
199 Returns the article requests associated with this Biblio that are completed
203 sub article_requests_finished
{
204 my ( $self, $borrower ) = @_;
206 $self->{_article_requests_finished
} ||= Koha
::ArticleRequests
->search(
208 biblionumber
=> $self->biblionumber(),
210 { status
=> Koha
::ArticleRequest
::Status
::Completed
},
211 { status
=> Koha
::ArticleRequest
::Status
::Canceled
}
216 return wantarray ?
$self->{_article_requests_finished
}->as_list : $self->{_article_requests_finished
};
221 my @items = $biblio->items();
222 my $items = $biblio->items();
224 Returns the related Koha::Items object for this biblio in scalar context,
225 or list of Koha::Item objects in list context.
232 $self->{_items
} ||= Koha
::Items
->search( { biblionumber
=> $self->biblionumber() } );
234 return wantarray ?
$self->{_items
}->as_list : $self->{_items
};
239 my $itemtype = $biblio->itemtype();
241 Returns the itemtype for this record.
248 return $self->_biblioitem()->itemtype();
253 my $field = $self->_biblioitem()->itemtype
255 Returns the related Koha::Biblioitem object for this Biblio object
262 $self->{_biblioitem
} ||= Koha
::Biblioitems
->find( { biblionumber
=> $self->biblionumber() } );
264 return $self->{_biblioitem
};
277 Kyle M Hall <kyle@bywatersolutions.com>