Bug 17670: Grammar mistakes - effect vs affect
[koha.git] / Koha / Patrons.pm
index 384a25c..4318179 100644 (file)
@@ -23,6 +23,8 @@ use Carp;
 
 use Koha::Database;
 
+use Koha::ArticleRequests;
+use Koha::ArticleRequest::Status;
 use Koha::Patron;
 
 use base qw(Koha::Objects);
@@ -37,38 +39,115 @@ Koha::Patron - Koha Patron Object class
 
 =cut
 
-=head3 housebound_choosers
+=head3 search_housebound_choosers
 
 Returns all Patrons which are Housebound choosers.
 
 =cut
 
-sub housebound_choosers {
+sub search_housebound_choosers {
     my ( $self ) = @_;
-    my $cho = $self->_resultset->search
-        ->search_related('borrower_attributes', {
-            code => 'HSBND',
-            attribute => 'CHO',
+    my $cho = $self->_resultset
+        ->search_related('housebound_role', {
+            housebound_chooser => 1,
         })->search_related('borrowernumber');
     return Koha::Patrons->_new_from_dbic($cho);
 }
 
-=head3 housebound_deliverers
+=head3 search_housebound_deliverers
 
 Returns all Patrons which are Housebound deliverers.
 
 =cut
 
-sub housebound_deliverers {
+sub search_housebound_deliverers {
     my ( $self ) = @_;
-    my $del = $self->_resultset->search
-        ->search_related('borrower_attributes', {
-            code => 'HSBND',
-            attribute => 'DEL',
+    my $del = $self->_resultset
+        ->search_related('housebound_role', {
+            housebound_deliverer => 1,
         })->search_related('borrowernumber');
     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