From c2a771d07fc0ef4db9ab620b57b9adefa600785e Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 22 Sep 2021 15:49:15 -0300 Subject: [PATCH] Bug 29083: Update article requests-related Koha::Patron methods to use relationships This patch makes Koha::Patron->article_requests use the underlying DBIC relationship and _new_from_dbic instead of a plain search. It also refactors 'article_requests_current' and 'article_requests_finished' to use ->article_requests, as well as the new methods introduced by bug 29082 for filtering. No behavior change should take place. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Patron.t \ t/db_dependent/ArticleRequests.t => SUCCESS: Tests pass! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/Patron.pm | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 967ae9a33b..37d07375ad 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -983,26 +983,21 @@ sub can_request_article { =head3 article_requests -my @requests = $borrower->article_requests(); -my $requests = $borrower->article_requests(); + my $article_requests = $patron->article_requests; -Returns either a list of ArticleRequests objects, -or an ArtitleRequests object, depending on the -calling context. +Returns the patron article requests. =cut sub article_requests { - my ( $self ) = @_; - - $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() }); + my ($self) = @_; - return $self->{_article_requests}; + return Koha::ArticleRequests->_new_from_dbic( scalar $self->_result->article_requests ); } =head3 article_requests_current -my @requests = $patron->article_requests_current + my $current_article_requests = $patron->article_requests_current Returns the article requests associated with this patron that are incomplete @@ -1011,23 +1006,12 @@ Returns the article requests associated with this patron that are incomplete sub article_requests_current { my ( $self ) = @_; - $self->{_article_requests_current} ||= Koha::ArticleRequests->search( - { - borrowernumber => $self->id(), - -or => [ - { status => Koha::ArticleRequest::Status::Requested }, - { status => Koha::ArticleRequest::Status::Pending }, - { status => Koha::ArticleRequest::Status::Processing } - ] - } - ); - - return $self->{_article_requests_current}; + return $self->article_requests->filter_by_current; } =head3 article_requests_finished -my @requests = $biblio->article_requests_finished + my $finished_article_requests = $biblio->article_requests_finished Returns the article requests associated with this patron that are completed @@ -1036,17 +1020,7 @@ Returns the article requests associated with this patron that are completed 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}; + return $self->article_requests->filter_by_finished; } =head3 add_enrolment_fee_if_needed -- 2.20.1