3 # A Class for hiding the ILS's concept of the patron from the OpenSIP
7 package OpenILS::SIP::Patron;
13 use Sys::Syslog qw(syslog);
15 use Digest::MD5 qw(md5_hex);
17 use OpenILS::Application::AppUtils;
18 my $U = 'OpenILS::Application::AppUtils';
20 our (@ISA, @EXPORT_OK);
24 @EXPORT_OK = qw(invalid_patron);
27 my ($class, $patron_id) = @_;
28 my $type = ref($class) || $class;
31 syslog("LOG_DEBUG", "new OpenILS Patron(%s): searching...", $patron_id);
33 require OpenILS::Utils::CStoreEditor;
34 my $e = OpenILS::Utils::CStoreEditor->new;
36 if(!UNIVERSAL::can($e, 'search_actor_card')) {
37 syslog("LOG_WARNING", "Reloading CStoreEditor...");
38 delete $INC{'OpenILS/Utils/CStoreEditor.pm'};
39 require OpenILS::Utils::CStoreEditor;
40 $e = OpenILS::Utils::CStoreEditor->new;
44 my $c = $e->search_actor_card({barcode => $patron_id}, {idlist=>1});
49 $user = $e->search_actor_user(
70 $user = (@$user) ? $$user[0] : undef;
74 syslog("LOG_WARNING", "Unable to find patron %s", $patron_id);
78 $self->{user} = $user;
79 $self->{id} = $patron_id;
82 syslog("LOG_DEBUG", "new OpenILS Patron(%s): found patron '%s'", $patron_id);
95 my $u = $self->{user};
96 return $u->first_given_name . ' ' .
97 $u->second_given_name . ' ' . $u->family_name;
102 return "" unless $addr;
103 return $addr->street1 .' '.
114 my $u = $self->{user};
115 my $addr = $u->billing_address;
116 my $str = __addr_string($addr);
117 my $maddr = $u->mailing_address;
118 $str .= "\n" . __addr_string($maddr)
119 if $maddr and $maddr->id ne $addr->id;
125 return $self->{user}->email;
130 return $self->{user}->day_phone;
135 return $self->{user}->dob;
140 return $self->{user}->profile->name;
145 return '000'; # Unspecified
148 # How much more detail do we need to check here?
151 my $u = $self->{user};
152 return ($u->barred ne 't') and ($u->card->active ne 'f');
155 # How much more detail do we need to check here?
158 my $u = $self->{user};
159 return ($u->barred ne 'f') and ($u->card->active ne 'f');
172 # return true if the card provided is marked as lost
185 my ($self, $pwd) = @_;
186 return md5_hex($pwd) eq $self->{user}->passwd;
211 sub too_many_charged {
216 sub too_many_overdue {
218 if( $self->{user}->standing_penalties ) {
219 return grep { $_->penalty_type eq 'PATRON_EXCEEDS_OVERDUE_COUNT' }
220 @{$self->{user}->standing_penalties};
225 # not completely sure what this means
226 sub too_many_renewal {
231 # not relevant, handled by fines/fees
232 sub too_many_claim_return {
237 # not relevant, handled by fines/fees
243 sub excessive_fines {
245 if( $self->{user}->standing_penalties ) {
246 return grep { $_->penalty_type eq 'PATRON_EXCEEDS_FINES' }
247 @{$self->{user}->standing_penalties};
253 # Until someone suggests otherwise, fees and fines are the same
257 if( $self->{user}->standing_penalties ) {
258 return grep { $_->penalty_type eq 'PATRON_EXCEEDS_FINES' }
259 @{$self->{user}->standing_penalties};
264 # not relevant, handled by fines/fees
265 sub too_many_billed {
273 # List of outstanding holds placed
276 my ($self, $start, $end) = @_;
278 my $holds = $self->{editor}->search_action_hold_request(
279 { usr => $self->{user}->id, fulfillment_time => undef }
283 push( @holds, $self->__hold_to_title($_) ) for @$holds;
285 return (defined $start and defined $end) ?
286 [ $holds[($start-1)..($end-1)] ] :
290 sub __hold_to_title {
293 my $e = $self->{editor};
295 my( $id, $mods, $title, $volume, $copy );
297 if( $hold->hold_type eq 'C' ) {
298 $copy = $e->retrieve_asset_copy($hold->target);
301 if( $copy || $hold->hold_type eq 'V' ) {
302 return $copy->dummy_title if $copy and $copy->call_number == -1;
303 $id = ($copy) ? $copy->call_number : $hold->target;
304 $volume = $e->retrieve_asset_call_number($id);
307 if( $volume || $hold->hold_type eq 'T' ) {
308 $id = ($volume) ? $volume->record : $hold->target;
309 $mods = $U->simplereq(
311 'open-ils.search.biblio.record.mods_slim.retrieve', $id );
314 if( $hold->hold_type eq 'M' ) {
315 $mods = $U->simplereq(
317 'open-ils.search.biblio.metarecord.mods_slim.retrieve', $hold->target);
321 return ($mods) ? $mods->title : "";
325 # remove the hold on item item_id from my hold queue.
326 # return true if I was holding the item, false otherwise.
329 my ($self, $item_id) = @_;
334 my ($self, $start, $end) = @_;
337 return (defined $start and defined $end) ?
338 [ $overdues[($start-1)..($end-1)] ] :
343 my ($self, $start, $end) = shift;
346 return (defined $start and defined $end) ?
347 [ $charges[($start-1)..($end-1)] ] :
352 my ($self, $start, $end) = @_;
354 return (defined $start and defined $end) ?
355 [ $fines[($start-1)..($end-1)] ] : \@fines;
358 # not currently supported
360 my ($self, $start, $end) = @_;
365 my ($self, $start, $end) = @_;
367 return (defined $start and defined $end) ?
368 [ $holds[($start-1)..($end-1)] ] : \@holds;
372 my ($self, $card_retained, $blocked_card_msg) = @_;
373 # Mark the card as inactive, set patron alert
377 # Testing purposes only
380 # Un-mark card as inactive, grep out the patron alert
381 $self->{screen_msg} = "All privileges restored.";
390 return "Please contact library staff";
394 return "Please contact library staff";