From 84e8e10d5eacc681d51dab964d0e846c6454e4cd Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 9 Aug 2006 22:11:46 +0000 Subject: [PATCH] added first-draft hold notification code - sans any actual notification git-svn-id: svn://svn.open-ils.org/ILS/trunk@5413 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Circ/Holds.pm | 112 +++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index 0d0a5d0a27..106ad5217a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -25,6 +25,7 @@ use OpenILS::Event; use OpenSRF::Utils::Logger qw(:logger); use OpenILS::Utils::CStoreEditor q/:funcs/; use OpenILS::Utils::PermitHold; +use OpenSRF::Utils::SettingsClient; use OpenILS::Const qw/:const/; my $apputils = "OpenILS::Application::AppUtils"; @@ -1068,8 +1069,115 @@ sub find_nearest_permitted_hold { } -#__PACKAGE__->register_method( -#); + +# Generates a hold email notification +sub hold_email_notifify { + my( $class, $editor, $hold, $title, $volume, $copy ) = @_; + + my $sclient = OpenSRF::Utils::SettingsClient->new; + my $template = $sclient->config_value('hold_email_template'); + return undef unless $template; + + $logger->info("hold_notify: using template $template"); + + my $patron = $editor->retrieve_actor_user($hold->usr) + or return $editor->event; + + return undef unless + $patron->email and $patron->email =~ /.+\@.+/; # see if it's remotely email-esque + + $logger->info("hold_notify: using email ".$patron->email); + + my( $str, $evt ); + + $str = load_template($template); + return undef unless $str; + ($str, $evt) = flesh_template( $editor, $hold, $title, $volume, $copy, $patron, $str ); + return $evt if $evt; + return undef unless $str; + + $logger->info("hold_notify: $str"); + return undef; +} + + +sub load_template { + my $template = shift; + + unless( open(F, $template) ) { + $logger->error("Unable to open hold notification template file: $template"); + return undef; + } + + # load the template, strip comments + my @lines = ; + close(F); + + my $str = ''; + for(@lines) { + chomp $_; + next if $_ =~ /^\s*\#/o; + $_ =~ s/\#.*//og; + $str .= "$_\n"; + } + + return $str; +} + + +sub flesh_template { + my( $editor, $hold, $title, $volume, $copy, $patron, $str ) = @_; + + + my $p_addr; + unless( $p_addr = + $editor->retrieve_actor_user_address($patron->billing_address)) { + unless( $p_addr = + $editor->retrieve_actor_user_address($patron->mailing_address)) { + $logger->warn("No address for user ".$patron->id); + return undef; + } + } + + my $org = $editor->retrieve_actor_org_unit($hold->pickup_lib) + or return (undef, $editor->event); + + my $o_name = $org->name; + my $o_addr = $org->holds_address; + my $p_name = $patron->first_given_name .' '.$patron->family_name; + + my $p_addrs = $p_addr->street1."\n".$p_addr->street2."\n". + $p_addr->city."\n".$p_addr->state."\n".$p_addr->post_code."\n"; + + my @time = localtime(); + my $day = $time[3]; + my $month = $time[4] + 1; + my $year = $time[5] + 1900; + + my $mods = $U->record_to_mvr($title); + my $ttle = $mods->title; + my $author = $mods->author; + my $cn = $volume->label; + my $barcode = $copy->barcode; + my $copy_number = $copy->copy_number; + + $str =~ s/\${DATE}/$year-$month-$day/; + $str =~ s/\${LIBRARY}/$o_name/; + $str =~ s/\${LIBRARY_ADDRESS}/$o_addr/; + $str =~ s/\${PATRON_NAME}/$p_name/; + $str =~ s/\${PATRON_ADDRESS}/$p_addrs/; + + $str =~ s/\${TITLE}/$ttle/; + $str =~ s/\${AUTHOR}/$author/; + $str =~ s/\${CALL_NUMBER}/$cn/; + $str =~ s/\${COPY_BARCODE}/$barcode/; + $str =~ s/\${COPY_NUMBER}/$copy_number/; + + $logger->info("hold_notify: fleshed template: $str"); + + return $str; +} + -- 2.43.2