Bugzilla – Attachment 153436 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.29 KB, created by
Matt Blenkinsop
on 2023-07-14 08:15:19 UTC
(
hide
)
Description:
Bug 33245: Introduce patron->is_active
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-07-14 08:15:19 UTC
Size:
3.29 KB
patch
obsolete
>From 8531d3e09995be19be9246a99339c699a5c9ee59 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 > >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;' >Note: replace X by a valid borrowernumber. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >--- > Koha/Patron.pm | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 58 insertions(+) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 2a8eecf9f6..5c0597ead2 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::Context; > use C4::Auth qw( checkpw_hash ); >@@ -792,6 +793,63 @@ 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. If no parameter is passed, >+we look at the last 6 months. >+ >+=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 { >+ $dt = dt_from_string()->subtract( days => 180 ); # default fallback >+ } >+ >+ # 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.37.1 (Apple Git-137.1)
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