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.
27 use Koha
::DateUtils
qw( dt_from_string );
29 use base
qw(Koha::Object);
32 use Koha
::Biblioitems
;
33 use Koha
::ArticleRequests
;
34 use Koha
::ArticleRequest
::Status
;
35 use Koha
::IssuingRules
;
36 use Koha
::Subscriptions
;
40 Koha::Biblio - Koha Biblio Object class
50 Overloaded I<store> method to set default values
57 $self->datecreated( dt_from_string
) unless $self->datecreated;
59 return $self->SUPER::store
;
64 my @subtitles = $biblio->subtitles();
66 Returns list of subtitles for a record.
68 Keyword to MARC mapping for subtitle must be set for this method to return any possible values.
75 return map { $_->{subfield
} } @
{
76 C4
::Biblio
::GetRecordValue
(
78 C4
::Biblio
::GetMarcBiblio
({ biblionumber
=> $self->id }),
79 $self->frameworkcode ) };
82 =head3 can_article_request
84 my $bool = $biblio->can_article_request( $borrower );
86 Returns true if article requests can be made for this record
88 $borrower must be a Koha::Patron object
92 sub can_article_request
{
93 my ( $self, $borrower ) = @_;
95 my $rule = $self->article_request_type($borrower);
96 return q{} if $rule eq 'item_only' && !$self->items()->count();
97 return 1 if $rule && $rule ne 'no';
102 =head3 article_request_type
104 my $type = $biblio->article_request_type( $borrower );
106 Returns the article request type based on items, or on the record
107 itself if there are no items.
109 $borrower must be a Koha::Patron object
113 sub article_request_type
{
114 my ( $self, $borrower ) = @_;
116 return q{} unless $borrower;
118 my $rule = $self->article_request_type_for_items( $borrower );
119 return $rule if $rule;
121 # If the record has no items that are requestable, go by the record itemtype
122 $rule = $self->article_request_type_for_bib($borrower);
123 return $rule if $rule;
128 =head3 article_request_type_for_bib
130 my $type = $biblio->article_request_type_for_bib
132 Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record
136 sub article_request_type_for_bib
{
137 my ( $self, $borrower ) = @_;
139 return q{} unless $borrower;
141 my $borrowertype = $borrower->categorycode;
142 my $itemtype = $self->itemtype();
144 my $issuing_rule = Koha
::IssuingRules
->get_effective_issuing_rule({ categorycode
=> $borrowertype, itemtype
=> $itemtype });
146 return q{} unless $issuing_rule;
147 return $issuing_rule->article_requests || q{}
150 =head3 article_request_type_for_items
152 my $type = $biblio->article_request_type_for_items
154 Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record's items
156 If there is a conflict where some items are 'bib_only' and some are 'item_only', 'bib_only' will be returned.
160 sub article_request_type_for_items
{
161 my ( $self, $borrower ) = @_;
164 foreach my $item ( $self->items()->as_list() ) {
165 my $rule = $item->article_request_type($borrower);
166 return $rule if $rule eq 'bib_only'; # we don't need to go any further
170 return 'item_only' if $counts->{item_only
};
171 return 'yes' if $counts->{yes
};
172 return 'no' if $counts->{no};
176 =head3 article_requests
178 my @requests = $biblio->article_requests
180 Returns the article requests associated with this Biblio
184 sub article_requests
{
185 my ( $self, $borrower ) = @_;
187 $self->{_article_requests
} ||= Koha
::ArticleRequests
->search( { biblionumber
=> $self->biblionumber() } );
189 return wantarray ?
$self->{_article_requests
}->as_list : $self->{_article_requests
};
192 =head3 article_requests_current
194 my @requests = $biblio->article_requests_current
196 Returns the article requests associated with this Biblio that are incomplete
200 sub article_requests_current
{
201 my ( $self, $borrower ) = @_;
203 $self->{_article_requests_current
} ||= Koha
::ArticleRequests
->search(
205 biblionumber
=> $self->biblionumber(),
207 { status
=> Koha
::ArticleRequest
::Status
::Pending
},
208 { status
=> Koha
::ArticleRequest
::Status
::Processing
}
213 return wantarray ?
$self->{_article_requests_current
}->as_list : $self->{_article_requests_current
};
216 =head3 article_requests_finished
218 my @requests = $biblio->article_requests_finished
220 Returns the article requests associated with this Biblio that are completed
224 sub article_requests_finished
{
225 my ( $self, $borrower ) = @_;
227 $self->{_article_requests_finished
} ||= Koha
::ArticleRequests
->search(
229 biblionumber
=> $self->biblionumber(),
231 { status
=> Koha
::ArticleRequest
::Status
::Completed
},
232 { status
=> Koha
::ArticleRequest
::Status
::Canceled
}
237 return wantarray ?
$self->{_article_requests_finished
}->as_list : $self->{_article_requests_finished
};
242 my @items = $biblio->items();
243 my $items = $biblio->items();
245 Returns the related Koha::Items object for this biblio in scalar context,
246 or list of Koha::Item objects in list context.
253 $self->{_items
} ||= Koha
::Items
->search( { biblionumber
=> $self->biblionumber() } );
255 return wantarray ?
$self->{_items
}->as_list : $self->{_items
};
260 my $itemtype = $biblio->itemtype();
262 Returns the itemtype for this record.
269 return $self->biblioitem()->itemtype();
274 my $holds = $biblio->holds();
276 return the current holds placed on this record
281 my ( $self, $params, $attributes ) = @_;
282 $attributes->{order_by
} = 'priority' unless exists $attributes->{order_by
};
283 my $hold_rs = $self->_result->reserves->search( $params, $attributes );
284 return Koha
::Holds
->_new_from_dbic($hold_rs);
289 my $holds = $biblio->current_holds
291 Return the holds placed on this bibliographic record.
292 It does not include future holds.
298 my $dtf = Koha
::Database
->new->schema->storage->datetime_parser;
300 { reservedate
=> { '<=' => $dtf->format_date(dt_from_string
) } } );
305 my $field = $self->biblioitem()->itemtype
307 Returns the related Koha::Biblioitem object for this Biblio object
314 $self->{_biblioitem
} ||= Koha
::Biblioitems
->find( { biblionumber
=> $self->biblionumber() } );
316 return $self->{_biblioitem
};
321 my $subscriptions = $self->subscriptions
323 Returns the related Koha::Subscriptions object for this Biblio object
330 $self->{_subscriptions
} ||= Koha
::Subscriptions
->search( { biblionumber
=> $self->biblionumber } );
332 return $self->{_subscriptions
};
335 =head3 has_items_waiting_or_intransit
337 my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit
339 Tells if this bibliographic record has items waiting or in transit.
343 sub has_items_waiting_or_intransit
{
346 if ( Koha
::Holds
->search({ biblionumber
=> $self->id,
347 found
=> ['W', 'T'] })->count ) {
351 foreach my $item ( $self->items ) {
352 return 1 if $item->get_transfer;
368 Kyle M Hall <kyle@bywatersolutions.com>