Bugzilla – Attachment 156542 Details for
Bug 33245
Add $patron->is_active
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33245: Introduce patron->is_active
Bug-33245-Introduce-patron-isactive.patch (text/plain), 3.55 KB, created by
Marcel de Rooy
on 2023-10-04 13:50:10 UTC
(
hide
)
Description:
Bug 33245: Introduce patron->is_active
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-10-04 13:50:10 UTC
Size:
3.55 KB
patch
obsolete
>From 2def6ac31fd1f5ab04edf8fb0ec31e3dd1f4ad63 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 16 Mar 2023 14:34:58 +0000 >Subject: [PATCH] Bug 33245: Introduce patron->is_active >Content-Type: text/plain; charset=utf-8 > >Does only add the new patron method. > >NOTE: We may define additional criteria at some point, but I think >that this is a good starting point. > >Test plan: >Run perl -MKoha::Patron -e'print Koha::Patrons->find(X)->is_active(Y);' >Note: replace X by a valid borrowernumber and Y by date criterium. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/Patron.pm | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 68 insertions(+) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 5d7ca9b782..df9b6b9313 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -24,6 +24,7 @@ use List::MoreUtils qw( any uniq ); > use JSON qw( to_json ); > use Unicode::Normalize qw( NFKD ); > use Try::Tiny; >+use DateTime (); > > use C4::Auth qw( checkpw_hash ); > use C4::Context; >@@ -808,6 +809,73 @@ sub is_expired { > return 0; > } > >+=head3 is_active >+ >+$patron->is_active({ [ since => $date ], [ days|weeks|months|years => $value ] }) >+ >+A patron is considered 'active' if their account did not expire, and has not been anonymized, >+and patron logged in recently, or placed a hold, article request or borrowed a book recently. >+A recent enrollment as new patron counts too. >+ >+Recently is defined by $date or $value in days, weeks or months. You should >+pass one of those; otherwise an exception is thrown. >+ >+=cut >+ >+sub is_active { >+ my ( $self, $params ) = @_; >+ return 0 if $self->is_expired or $self->anonymized; >+ >+ my $dt; >+ if ( $params->{since} ) { >+ $dt = dt_from_string( $params->{since}, 'iso' ); >+ } elsif ( grep { $params->{$_} } qw(days weeks months years) ) { >+ $dt = dt_from_string(); >+ foreach my $duration (qw(days weeks months years)) { >+ $dt = $dt->subtract( $duration => $params->{$duration} ) if $params->{$duration}; >+ } >+ } else { >+ Koha::Exceptions::MissingParameter->throw('is_active needs date or period'); >+ } >+ >+ # Enrollment within this period? >+ return 1 if DateTime->compare( dt_from_string( $self->dateenrolled ), $dt ) > -1; >+ >+ # Last seen? Updated each login when you track patron activity >+ if ( C4::Context->preference('TrackLastPatronActivity') ) { >+ return 1 if DateTime->compare( dt_from_string( $self->lastseen ), $dt ) > -1; >+ } >+ >+ # Check holds, issues and article requests >+ return 1 if $self->holds->filter_by_last_update( >+ { >+ timestamp_column_name => 'timestamp', from => $dt, >+ } >+ )->count; >+ return 1 if $self->old_holds->filter_by_last_update( >+ { >+ timestamp_column_name => 'timestamp', from => $dt, >+ } >+ )->count; >+ return 1 if $self->checkouts->filter_by_last_update( >+ { >+ timestamp_column_name => 'timestamp', from => $dt, >+ } >+ )->count; >+ return 1 if $self->old_checkouts->filter_by_last_update( >+ { >+ timestamp_column_name => 'timestamp', from => $dt, >+ } >+ )->count; >+ return 1 if $self->article_requests->filter_by_last_update( >+ { >+ timestamp_column_name => 'updated_on', from => $dt, >+ } >+ )->count; >+ >+ return 0; >+} >+ > =head3 password_expired > > my $password_expired = $patron->password_expired; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33245
:
151800
|
151801
|
151802
|
153435
|
153436
|
153437
|
155050
|
155051
|
155052
|
155161
|
155162
|
155163
|
156528
|
156529
|
156530
|
156541
| 156542 |
156543