@@ -, +, @@ methods to use relationships $ kshell k$ prove t/db_dependent/Koha/Patron.t \ t/db_dependent/ArticleRequests.t --- Koha/Patron.pm | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) --- a/Koha/Patron.pm +++ a/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 --