From a8f982194cd16973882caad0b7a34160800ffdc0 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Tue, 10 Nov 2015 13:27:44 -0500 Subject: [PATCH] Use default notifications for holds in NCIP::ILS::Evergreen. When placing holds for our own patrons, we look up the user's settings for hold notifications and add those the hold parameters. If the patron has not set any defaults, we fall back to using email and day phone if these are available for the user. Signed-off-by: Jason Stephenson --- lib/NCIP/ILS/Evergreen.pm | 46 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/NCIP/ILS/Evergreen.pm b/lib/NCIP/ILS/Evergreen.pm index 27e10b7..d9929e9 100644 --- a/lib/NCIP/ILS/Evergreen.pm +++ b/lib/NCIP/ILS/Evergreen.pm @@ -301,7 +301,7 @@ sub acceptitem { # Now, we place the hold on the newly created copy on behalf # of the patron retrieved above. - my $hold = $self->place_hold($item, $user, $location); + my $hold = $self->place_hold($item, $user, $location, undef, undef, 1); if (ref($hold) eq 'NCIP::Problem') { $response->problem($hold); return $response; @@ -1634,7 +1634,7 @@ sub retrieve_user_by_id { 'open-ils.actor.user.fleshed.retrieve', $self->{session}->{authtoken}, $id, - [ 'card', 'cards', 'standing_penalties', 'addresses', 'home_ou' ] + [ 'card', 'cards', 'standing_penalties', 'addresses', 'home_ou', 'settings' ] ); # Check for an error. undef($result) if ($result && $U->event_code($result)); @@ -2220,7 +2220,7 @@ sub create_fuller_copy { =head2 place_hold - $hold = $ils->place_hold($item, $user, $location, $expiration, $org_unit); + $hold = $ils->place_hold($item, $user, $location, $expiration, $org_unit, $do_notification); This function places a hold on $item for $user for pickup at $location. If location is not provided or undefined, the user's home @@ -2238,6 +2238,9 @@ control the selection ou and selection depth for the hold. This essentially limits the hold to being filled by copies belonging to the specified org_unit or its children. +The $do_notification parameter is true or false for whether or not to +add the patron's default notification options to the hold when placed. + $item can be a copy (asset::copy), volume (asset::call_number), or bib (biblio::record_entry). The appropriate hold type will be placed depending on the object. @@ -2254,6 +2257,7 @@ sub place_hold { my $location = shift; my $expiration = shift; my $org_unit = shift; + my $do_notification = shift; # If $location is undefined, use the user's home_ou, which should # have been fleshed when the user was retrieved. @@ -2275,6 +2279,42 @@ sub place_hold { } } + # Notification params. + if ($do_notification) { + my ($hold_notify) = grep {$_->name() eq 'opac.hold_notify'} @{$user->settings()}; + if ($hold_notify) { + if ($hold_notify->value() =~ /email/) { + $params->{email_notify} = 1; + } + if ($hold_notify->value() =~ /phone/) { + my ($default_phone) = grep {$_->name() eq 'opac.default_phone'} @{$user->settings()}; + if ($default_phone) { + $params->{phone_notify} = $default_phone->value(); + $params->{phone_notify} =~ s/"//g; + } elsif ($user->day_phone()) { + $params->{phone_notify} = $user->day_phone(); + } + } + if ($hold_notify->value() =~ /sms/) { + my ($sms_carrier) = grep {$_->name() eq 'opac.default_sms_carrier'} @{$user->settings()}; + my ($sms_notify) = grep {$_->name() eq 'opac.default_sms_notify'} @{$user->settings()}; + if ($sms_carrier && $sms_notify) { + $params->{sms_carrier} = $sms_carrier->value(); + $params->{sms_notify} = $sms_notify->value(); + $params->{sms_carrier} =~ s/"//g; + $params->{sms_notify} =~ s/"//g; + } + } + } else { + if ($user->email()) { + $params->{email_notify} = 1; + } + if ($user->day_phone()) { + $params->{phone_notify} = $user->day_phone(); + } + } + } + my $response = $U->simplereq( 'open-ils.circ', 'open-ils.circ.holds.test_and_create.batch', -- 2.43.2