From bf1563e60b31244f4ea977eb84954fb8501ed59a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 7 Oct 2015 12:23:24 -0400 Subject: [PATCH] Bug 14610 - Add and update modules Signed-off-by: Jennifer Schmidt Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall --- C4/Letters.pm | 25 ++-- Koha/ArticleRequest.pm | 223 +++++++++++++++++++++++++++++++++ Koha/ArticleRequest/Status.pm | 44 +++++++ Koha/ArticleRequests.pm | 103 +++++++++++++++ Koha/Biblio.pm | 198 +++++++++++++++++++++++++++++ Koha/Biblios.pm | 2 +- Koha/Item.pm | 46 +++++++ Koha/Patron.pm | 67 ++++++++++ Koha/Patrons.pm | 81 ++++++++++++ Koha/Template/Plugin/Biblio.pm | 31 +++++ 10 files changed, 807 insertions(+), 13 deletions(-) create mode 100644 Koha/ArticleRequest.pm create mode 100644 Koha/ArticleRequest/Status.pm create mode 100644 Koha/ArticleRequests.pm diff --git a/C4/Letters.pm b/C4/Letters.pm index fffaa0de91..9f17169c8d 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -766,18 +766,19 @@ sub _parseletter_sth { # broke things for the rest of us. prepare_cached is a better # way to cache statement handles anyway. my $query = - ($table eq 'biblio' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : - ($table eq 'biblioitems' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : - ($table eq 'items' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : - ($table eq 'issues' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : - ($table eq 'old_issues' ) ? "SELECT * FROM $table WHERE itemnumber = ? ORDER BY timestamp DESC LIMIT 1" : - ($table eq 'reserves' ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" : - ($table eq 'borrowers' ) ? "SELECT * FROM $table WHERE borrowernumber = ?" : - ($table eq 'branches' ) ? "SELECT * FROM $table WHERE branchcode = ?" : - ($table eq 'suggestions' ) ? "SELECT * FROM $table WHERE suggestionid = ?" : - ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE id = ?" : - ($table eq 'aqorders' ) ? "SELECT * FROM $table WHERE ordernumber = ?" : - ($table eq 'opac_news' ) ? "SELECT * FROM $table WHERE idnew = ?" : + ($table eq 'biblio' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : + ($table eq 'biblioitems' ) ? "SELECT * FROM $table WHERE biblionumber = ?" : + ($table eq 'items' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : + ($table eq 'issues' ) ? "SELECT * FROM $table WHERE itemnumber = ?" : + ($table eq 'old_issues' ) ? "SELECT * FROM $table WHERE itemnumber = ? ORDER BY timestamp DESC LIMIT 1" : + ($table eq 'reserves' ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" : + ($table eq 'borrowers' ) ? "SELECT * FROM $table WHERE borrowernumber = ?" : + ($table eq 'branches' ) ? "SELECT * FROM $table WHERE branchcode = ?" : + ($table eq 'suggestions' ) ? "SELECT * FROM $table WHERE suggestionid = ?" : + ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE id = ?" : + ($table eq 'aqorders' ) ? "SELECT * FROM $table WHERE ordernumber = ?" : + ($table eq 'opac_news' ) ? "SELECT * FROM $table WHERE idnew = ?" : + ($table eq 'article_requests') ? "SELECT * FROM $table WHERE id = ?" : ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" : ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" : ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" : diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm new file mode 100644 index 0000000000..217e1878cc --- /dev/null +++ b/Koha/ArticleRequest.pm @@ -0,0 +1,223 @@ +package Koha::ArticleRequest; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; +use Koha::Patrons; +use Koha::Biblios; +use Koha::Items; +use Koha::Libraries; +use Koha::ArticleRequest::Status; +use Koha::DateUtils qw(dt_from_string); + +use base qw(Koha::Object); + +=head1 NAME + +Koha::ArticleRequest - Koha Article Request Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 open + +=cut + +sub open { + my ($self) = @_; + + $self->status(Koha::ArticleRequest::Status::Pending); + $self->notify(); + return $self; +} + +=head3 process + +=cut + +sub process { + my ($self) = @_; + + $self->status(Koha::ArticleRequest::Status::Processing); + $self->store(); + $self->notify(); + return $self; +} + +=head3 complete + +=cut + +sub complete { + my ($self) = @_; + + $self->status(Koha::ArticleRequest::Status::Completed); + $self->store(); + $self->notify(); + return $self; +} + +=head3 cancel + +=cut + +sub cancel { + my ( $self, $notes ) = @_; + + $self->status(Koha::ArticleRequest::Status::Canceled); + $self->notes($notes) if $notes; + $self->store(); + $self->notify(); + return $self; +} + +=head3 notify + +=cut + +sub notify { + my ($self) = @_; + + my $status = $self->status; + + if ( + my $letter = C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => "AR_$status", + message_transport_type => 'email', + tables => { + article_requests => $self->id, + borrowers => $self->borrowernumber, + biblio => $self->biblionumber, + biblioitems => $self->biblionumber, + items => $self->itemnumber, + branches => $self->branchcode, + }, + ) + ) + { + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $self->borrowernumber, + message_transport_type => 'email', + } + ) or warn "can't enqueue letter $letter"; + } +} + +=head3 biblio + +Returns the Koha::Biblio object for this article request + +=cut + +sub biblio { + my ($self) = @_; + + $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() ); + + return $self->{_biblio}; +} + +=head3 item + +Returns the Koha::Item object for this article request + +=cut + +sub item { + my ($self) = @_; + + $self->{_item} ||= Koha::Items->find( $self->itemnumber() ); + + return $self->{_item}; +} + +=head3 borrower + +Returns the Koha::Patron object for this article request + +=cut + +sub borrower { + my ($self) = @_; + + $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() ); + + return $self->{_borrower}; +} + +=head3 branch + +Returns the Koha::Library object for this article request + +=cut + +sub branch { + my ($self) = @_; + + $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() ); + + return $self->{_branch}; +} + +=head3 store + +Override the default store behavior so that new opan requests +will have notifications sent. + +=cut + +sub store { + my ($self) = @_; + + if ( $self->in_storage() ) { + my $now = dt_from_string(); + $self->updated_on($now); + + return $self->SUPER::store(); + } + else { + $self->open(); + return $self->SUPER::store(); + } +} + +=head3 _type + +=cut + +sub _type { + return 'ArticleRequest'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/ArticleRequest/Status.pm b/Koha/ArticleRequest/Status.pm new file mode 100644 index 0000000000..f66324b96f --- /dev/null +++ b/Koha/ArticleRequest/Status.pm @@ -0,0 +1,44 @@ +package Koha::ArticleRequest::Status; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +sub Pending { + return 'PENDING'; +} + +sub Processing { + return 'PROCESSING'; +} + +sub Completed { + return 'COMPLETED'; +} + +sub Canceled { + return 'CANCELED'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/ArticleRequests.pm b/Koha/ArticleRequests.pm new file mode 100644 index 0000000000..bc47789be6 --- /dev/null +++ b/Koha/ArticleRequests.pm @@ -0,0 +1,103 @@ +package Koha::ArticleRequests; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::ArticleRequest; +use Koha::ArticleRequest::Status; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::ArticleRequests - Koha ArticleRequests Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 pending + +=cut + +sub pending { + my ( $self, $branchcode ) = @_; + my $params = { status => Koha::ArticleRequest::Status::Pending }; + $params->{branchcode} = $branchcode if $branchcode; + return Koha::ArticleRequests->search( $params ); +} + +=head3 processing + +=cut + +sub processing { + my ( $self, $branchcode ) = @_; + my $params = { status => Koha::ArticleRequest::Status::Processing }; + $params->{branchcode} = $branchcode if $branchcode; + return Koha::ArticleRequests->search( $params ); +} + +=head3 completed + +=cut + +sub completed { + my ( $self, $branchcode ) = @_; + my $params = { status => Koha::ArticleRequest::Status::Completed }; + $params->{branchcode} = $branchcode if $branchcode; + return Koha::ArticleRequests->search( $params ); +} + +=head3 canceled + +=cut + +sub canceled { + my ( $self, $branchcode ) = @_; + my $params = { status => Koha::ArticleRequest::Status::Canceled }; + $params->{branchcode} = $branchcode if $branchcode; + return Koha::ArticleRequests->search( $params ); +} + +=head3 _type + +=cut + +sub _type { + return 'ArticleRequest'; +} + +sub object_class { + return 'Koha::ArticleRequest'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 38b53f9324..1760d65d47 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -27,6 +27,12 @@ use Koha::Database; use base qw(Koha::Object); +use C4::Circulation qw(GetIssuingRule); +use Koha::Items; +use Koha::Biblioitems; +use Koha::ArticleRequests; +use Koha::ArticleRequest::Status; + =head1 NAME Koha::Biblio - Koha Biblio Object class @@ -53,8 +59,170 @@ sub subtitles { return map { $_->{subfield} } @{ GetRecordValue( 'subtitle', GetMarcBiblio( $self->id ), $self->frameworkcode ) }; } +=head3 can_article_request + +my $bool = $biblio->can_article_request( $borrower ); + +Returns true if article requests can be made for this record + +$borrower must be a Koha::Patron object + +=cut + +sub can_article_request { + my ( $self, $borrower ) = @_; + + my $rule = $self->article_request_type($borrower); + return q{} if $rule eq 'item_only' && !$self->items()->count(); + return 1 if $rule && $rule ne 'no'; + + return q{}; +} + +=head3 article_request_type + +my $type = $biblio->article_request_type( $borrower ); + +Returns the article request type based on items, or on the record +itself if there are no items. + +$borrower must be a Koha::Patron object + +=cut + +sub article_request_type { + my ( $self, $borrower ) = @_; + + return q{} unless $borrower; + + my $rule = $self->article_request_type_for_items( $borrower ); + return $rule if $rule; + + # If the record has no items that are requestable, go by the record itemtype + $rule = $self->article_request_type_for_bib($borrower); + return $rule if $rule; + + return q{}; +} + +=head3 article_request_type_for_bib + +my $type = $biblio->article_request_type_for_bib + +Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record + +=cut + +sub article_request_type_for_bib { + my ( $self, $borrower ) = @_; + + return q{} unless $borrower; + + my $borrowertype = $borrower->categorycode; + my $itemtype = $self->itemtype(); + + my $rules = C4::Circulation::GetIssuingRule( $borrowertype, $itemtype ); + + return $rules->{article_requests} || q{}; +} + +=head3 article_request_type_for_items + +my $type = $biblio->article_request_type_for_items + +Returns the article request type 'yes', 'no', 'item_only', 'bib_only', for the given record's items + +If there is a conflict where some items are 'bib_only' and some are 'item_only', 'bib_only' will be returned. + +=cut + +sub article_request_type_for_items { + my ( $self, $borrower ) = @_; + + my $counts; + foreach my $item ( $self->items()->as_list() ) { + my $rule = $item->article_request_type($borrower); + return $rule if $rule eq 'bib_only'; # we don't need to go any further + $counts->{$rule}++; + } + + return 'item_only' if $counts->{item_only}; + return 'yes' if $counts->{yes}; + return 'no' if $counts->{no}; + return q{}; +} + +=head3 article_requests + +my @requests = $biblio->article_requests + +Returns the article requests associated with this Biblio + +=cut + +sub article_requests { + my ( $self, $borrower ) = @_; + + $self->{_article_requests} ||= Koha::ArticleRequests->search( { biblionumber => $self->biblionumber() } ); + + return wantarray ? $self->{_article_requests}->as_list : $self->{_article_requests}; +} + +=head3 article_requests_current + +my @requests = $biblio->article_requests_current + +Returns the article requests associated with this Biblio that are incomplete + +=cut + +sub article_requests_current { + my ( $self, $borrower ) = @_; + + $self->{_article_requests_current} ||= Koha::ArticleRequests->search( + { + biblionumber => $self->biblionumber(), + -or => [ + { status => Koha::ArticleRequest::Status::Pending }, + { status => Koha::ArticleRequest::Status::Processing } + ] + } + ); + + return wantarray ? $self->{_article_requests_current}->as_list : $self->{_article_requests_current}; +} + +=head3 article_requests_finished + +my @requests = $biblio->article_requests_finished + +Returns the article requests associated with this Biblio that are completed + +=cut + +sub article_requests_finished { + my ( $self, $borrower ) = @_; + + $self->{_article_requests_finished} ||= Koha::ArticleRequests->search( + { + biblionumber => $self->biblionumber(), + -or => [ + { status => Koha::ArticleRequest::Status::Completed }, + { status => Koha::ArticleRequest::Status::Canceled } + ] + } + ); + + return wantarray ? $self->{_article_requests_finished}->as_list : $self->{_article_requests_finished}; +} + +=head3 items + =head3 items +my @items = $biblio->items(); +my $items = $biblio->items(); + Returns the related Koha::Items object for this biblio in scalar context, or list of Koha::Item objects in list context. @@ -68,6 +236,36 @@ sub items { return wantarray ? $self->{_items}->as_list : $self->{_items}; } +=head3 itemtype + +my $itemtype = $biblio->itemtype(); + +Returns the itemtype for this record. + +=cut + +sub itemtype { + my ( $self ) = @_; + + return $self->_biblioitem()->itemtype(); +} + +=head3 _biblioitem + +my $field = $self->_biblioitem()->itemtype + +Returns the related Koha::Biblioitem object for this Biblio object + +=cut + +sub _biblioitem { + my ($self) = @_; + + $self->{_biblioitem} ||= Koha::Biblioitems->find( { biblionumber => $self->biblionumber() } ); + + return $self->{_biblioitem}; +} + =head3 type =cut diff --git a/Koha/Biblios.pm b/Koha/Biblios.pm index 29f32fc190..49cfc2ca98 100644 --- a/Koha/Biblios.pm +++ b/Koha/Biblios.pm @@ -1,6 +1,6 @@ package Koha::Biblios; -# Copyright ByWater Solutions 2014 +# Copyright ByWater Solutions 2015 # # This file is part of Koha. # diff --git a/Koha/Item.pm b/Koha/Item.pm index 0bbc4933a0..758d19ce23 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -23,6 +23,8 @@ use Carp; use Koha::Database; +use C4::Context; +use C4::Circulation qw(GetIssuingRule); use Koha::Item::Transfer; use Koha::Patrons; use Koha::Libraries; @@ -123,6 +125,50 @@ sub last_returned_by { } } +=head3 can_article_request + +my $bool = $item->can_article_request( $borrower ) + +Returns true if item can be specifically requested + +$borrower must be a Koha::Patron object + +=cut + +sub can_article_request { + my ( $self, $borrower ) = @_; + + my $rule = $self->article_request_type($borrower); + + return 1 if $rule && $rule ne 'no' && $rule ne 'bib_only'; + return q{}; +} + +=head3 article_request_type + +my $type = $item->article_request_type( $borrower ) + +returns 'yes', 'no', 'bib_only', or 'item_only' + +$borrower must be a Koha::Patron object + +=cut + +sub article_request_type { + my ( $self, $borrower ) = @_; + + my $branch_control = C4::Context->preference('HomeOrHoldingBranch'); + my $branchcode = + $branch_control eq 'homebranch' ? $self->homebranch + : $branch_control eq 'holdingbranch' ? $self->holdingbranch + : undef; + my $borrowertype = $borrower->categorycode; + my $itemtype = $self->effective_itemtype(); + my $rules = GetIssuingRule( $borrowertype, $itemtype, $branchcode ); + + return $rules->{article_requests} || q{}; +} + =head3 type =cut diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 93c2186dbc..24daaeeb96 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -359,6 +359,73 @@ sub move_to_deleted { return Koha::Database->new->schema->resultset('Deletedborrower')->create($patron_infos); } +=head3 article_requests + +my @requests = $borrower->article_requests(); +my $requests = $borrower->article_requests(); + +Returns either a list of ArticleRequests objects, +or an ArtitleRequests object, depending on the +calling context. + +=cut + +sub article_requests { + my ( $self ) = @_; + + $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() }); + + return $self->{_article_requests}; +} + +=head3 article_requests_current + +my @requests = $patron->article_requests_current + +Returns the article requests associated with this patron that are incomplete + +=cut + +sub article_requests_current { + my ( $self ) = @_; + + $self->{_article_requests_current} ||= Koha::ArticleRequests->search( + { + borrowernumber => $self->id(), + -or => [ + { status => Koha::ArticleRequest::Status::Pending }, + { status => Koha::ArticleRequest::Status::Processing } + ] + } + ); + + return $self->{_article_requests_current}; +} + +=head3 article_requests_finished + +my @requests = $biblio->article_requests_finished + +Returns the article requests associated with this patron that are completed + +=cut + +sub article_requests_finished { + my ( $self, $borrower ) = @_; + + $self->{_article_requests_finished} ||= Koha::ArticleRequests->search( + { + borrowernumber => $self->id(), + -or => [ + { status => Koha::ArticleRequest::Status::Completed }, + { status => Koha::ArticleRequest::Status::Canceled } + ] + } + ); + + return $self->{_article_requests_finished}; +} + =head3 type =cut diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 1af2c06a3f..431817902f 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -23,6 +23,8 @@ use Carp; use Koha::Database; +use Koha::ArticleRequests; +use Koha::ArticleRequest::Status; use Koha::Patron; use base qw(Koha::Objects); @@ -67,6 +69,85 @@ sub search_housebound_deliverers { return Koha::Patrons->_new_from_dbic($del); } +=head3 guarantor + +Returns a Koha::Patron object for this borrower's guarantor + +=cut + +sub guarantor { + my ( $self ) = @_; + + return Koha::Patrons->find( $self->guarantorid() ); +} + +=head3 article_requests + +my @requests = $borrower->article_requests(); +my $requests = $borrower->article_requests(); + +Returns either a list of ArticleRequests objects, +or an ArtitleRequests object, depending on the +calling context. + +=cut + +sub article_requests { + my ( $self ) = @_; + + $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() }); + + return $self->{_article_requests}; +} + +=head3 article_requests_current + +my @requests = $patron->article_requests_current + +Returns the article requests associated with this patron that are incomplete + +=cut + +sub article_requests_current { + my ( $self ) = @_; + + $self->{_article_requests_current} ||= Koha::ArticleRequests->search( + { + borrowernumber => $self->id(), + -or => [ + { status => Koha::ArticleRequest::Status::Pending }, + { status => Koha::ArticleRequest::Status::Processing } + ] + } + ); + + return $self->{_article_requests_current}; +} + +=head3 article_requests_finished + +my @requests = $biblio->article_requests_finished + +Returns the article requests associated with this patron that are completed + +=cut + +sub article_requests_finished { + my ( $self, $borrower ) = @_; + + $self->{_article_requests_finished} ||= Koha::ArticleRequests->search( + { + borrowernumber => $self->id(), + -or => [ + { status => Koha::ArticleRequest::Status::Completed }, + { status => Koha::ArticleRequest::Status::Canceled } + ] + } + ); + + return $self->{_article_requests_finished}; +} + =head3 type =cut diff --git a/Koha/Template/Plugin/Biblio.pm b/Koha/Template/Plugin/Biblio.pm index 3f9cc4fe41..e9d7a73009 100644 --- a/Koha/Template/Plugin/Biblio.pm +++ b/Koha/Template/Plugin/Biblio.pm @@ -23,6 +23,10 @@ use Template::Plugin; use base qw( Template::Plugin ); use Koha::Holds; +use Koha::Biblios; +use Koha::Patrons; +use Koha::ArticleRequests; +use Koha::ArticleRequest::Status; sub HoldsCount { my ( $self, $biblionumber ) = @_; @@ -32,4 +36,31 @@ sub HoldsCount { return $holds->count(); } +sub ArticleRequestsActiveCount { + my ( $self, $biblionumber ) = @_; + + my $ar = Koha::ArticleRequests->search( + { + biblionumber => $biblionumber, + status => [ + -or => [ + status => Koha::ArticleRequest::Status::Pending, + status => Koha::ArticleRequest::Status::Processing + ] + ] + } + ); + + return $ar->count(); +} + +sub CanArticleRequest { + my ( $self, $biblionumber, $borrowernumber ) = @_; + + my $biblio = Koha::Biblios->find( $biblionumber ); + my $borrower = Koha::Patrons->find( $borrowernumber ); + + return $biblio ? $biblio->can_article_request( $borrower ) : 0; +} + 1; -- 2.39.5