|
Lines 24-29
use List::MoreUtils qw( any uniq );
Link Here
|
| 24 |
use JSON qw( to_json ); |
24 |
use JSON qw( to_json ); |
| 25 |
use Unicode::Normalize qw( NFKD ); |
25 |
use Unicode::Normalize qw( NFKD ); |
| 26 |
use Try::Tiny; |
26 |
use Try::Tiny; |
|
|
27 |
use DateTime (); |
| 27 |
|
28 |
|
| 28 |
use C4::Auth qw( checkpw_hash ); |
29 |
use C4::Auth qw( checkpw_hash ); |
| 29 |
use C4::Context; |
30 |
use C4::Context; |
|
Lines 808-813
sub is_expired {
Link Here
|
| 808 |
return 0; |
809 |
return 0; |
| 809 |
} |
810 |
} |
| 810 |
|
811 |
|
|
|
812 |
=head3 is_active |
| 813 |
|
| 814 |
$patron->is_active({ [ since => $date ], [ days|weeks|months|years => $value ] }) |
| 815 |
|
| 816 |
A patron is considered 'active' if their account did not expire, and has not been anonymized, |
| 817 |
and patron logged in recently, or placed a hold, article request or borrowed a book recently. |
| 818 |
A recent enrollment as new patron counts too. |
| 819 |
|
| 820 |
Recently is defined by $date or $value in days, weeks or months. You should |
| 821 |
pass one of those; otherwise an exception is thrown. |
| 822 |
|
| 823 |
=cut |
| 824 |
|
| 825 |
sub is_active { |
| 826 |
my ( $self, $params ) = @_; |
| 827 |
return 0 if $self->is_expired or $self->anonymized; |
| 828 |
|
| 829 |
my $dt; |
| 830 |
if ( $params->{since} ) { |
| 831 |
$dt = dt_from_string( $params->{since}, 'iso' ); |
| 832 |
} elsif ( grep { $params->{$_} } qw(days weeks months years) ) { |
| 833 |
$dt = dt_from_string(); |
| 834 |
foreach my $duration (qw(days weeks months years)) { |
| 835 |
$dt = $dt->subtract( $duration => $params->{$duration} ) if $params->{$duration}; |
| 836 |
} |
| 837 |
} else { |
| 838 |
Koha::Exceptions::MissingParameter->throw('is_active needs date or period'); |
| 839 |
} |
| 840 |
|
| 841 |
# Enrollment within this period? |
| 842 |
return 1 if DateTime->compare( dt_from_string( $self->dateenrolled ), $dt ) > -1; |
| 843 |
|
| 844 |
# Last seen? Updated each login when you track patron activity |
| 845 |
if ( C4::Context->preference('TrackLastPatronActivity') ) { |
| 846 |
return 1 if DateTime->compare( dt_from_string( $self->lastseen ), $dt ) > -1; |
| 847 |
} |
| 848 |
|
| 849 |
# Check holds, issues and article requests |
| 850 |
return 1 if $self->holds->filter_by_last_update( |
| 851 |
{ |
| 852 |
timestamp_column_name => 'timestamp', from => $dt, |
| 853 |
} |
| 854 |
)->count; |
| 855 |
return 1 if $self->old_holds->filter_by_last_update( |
| 856 |
{ |
| 857 |
timestamp_column_name => 'timestamp', from => $dt, |
| 858 |
} |
| 859 |
)->count; |
| 860 |
return 1 if $self->checkouts->filter_by_last_update( |
| 861 |
{ |
| 862 |
timestamp_column_name => 'timestamp', from => $dt, |
| 863 |
} |
| 864 |
)->count; |
| 865 |
return 1 if $self->old_checkouts->filter_by_last_update( |
| 866 |
{ |
| 867 |
timestamp_column_name => 'timestamp', from => $dt, |
| 868 |
} |
| 869 |
)->count; |
| 870 |
return 1 if $self->article_requests->filter_by_last_update( |
| 871 |
{ |
| 872 |
timestamp_column_name => 'updated_on', from => $dt, |
| 873 |
} |
| 874 |
)->count; |
| 875 |
|
| 876 |
return 0; |
| 877 |
} |
| 878 |
|
| 811 |
=head3 password_expired |
879 |
=head3 password_expired |
| 812 |
|
880 |
|
| 813 |
my $password_expired = $patron->password_expired; |
881 |
my $password_expired = $patron->password_expired; |
| 814 |
- |
|
|