bug 2848 [1/2]: Send notifications to patrons when hold is received

This adds notification code to Reserves.pm to send notifications through email
or SMS to patrons when their hold is filled. It does not send the letter
directly, but instead uses EnqueueLetter. Also, it relies on
EnhancedPatronMessaging being on and the hold notification being turned on for
the specific patron through the 'Messaging' tab.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
Jesse Weaver 2008-12-05 15:11:13 -06:00 committed by Galen Charlton
parent 6ca9d3eb14
commit c9a50403e5
5 changed files with 113 additions and 12 deletions

View file

@ -467,27 +467,32 @@ sub SendAlerts {
=cut
sub parseletter {
my ( $letter, $table, $pk ) = @_;
my ( $letter, $table, $pk, $pk2 ) = @_;
# warn "Parseletter : ($letter,$table,$pk)";
my $dbh = C4::Context->dbh;
my $sth;
if ( $table eq 'biblio' ) {
$sth = $dbh->prepare("select * from biblio where biblionumber=?");
}
elsif ( $table eq 'biblioitems' ) {
} elsif ( $table eq 'biblioitems' ) {
$sth = $dbh->prepare("select * from biblioitems where biblionumber=?");
}
elsif ( $table eq 'borrowers' ) {
} elsif ( $table eq 'items' ) {
$sth = $dbh->prepare("select * from items where itemnumber=?");
} elsif ( $table eq 'reserves' ) {
$sth = $dbh->prepare("select * from reserves where borrowernumber = ? and biblionumber=?");
} elsif ( $table eq 'borrowers' ) {
$sth = $dbh->prepare("select * from borrowers where borrowernumber=?");
}
elsif ( $table eq 'branches' ) {
} elsif ( $table eq 'branches' ) {
$sth = $dbh->prepare("select * from branches where branchcode=?");
}
elsif ( $table eq 'aqbooksellers' ) {
} elsif ( $table eq 'aqbooksellers' ) {
$sth = $dbh->prepare("select * from aqbooksellers where id=?");
}
$sth->execute($pk);
if ( $pk2 ) {
$sth->execute($pk, $pk2);
} else {
$sth->execute($pk);
}
# store the result in an hash
my $values = $sth->fetchrow_hashref;
@ -499,7 +504,6 @@ sub parseletter {
my $replacefield = "<<$table.$field>>";
my $replacedby = $values->{$field};
# warn "REPLACE $replacefield by $replacedby";
$letter->{title} =~ s/$replacefield/$replacedby/g;
$letter->{content} =~ s/$replacefield/$replacedby/g;
}
@ -749,6 +753,8 @@ sub _send_message_by_email {
my $message = shift;
my $member = C4::Members::GetMember( $message->{'borrowernumber'} );
return unless $message->{'to_address'} or $member->{'email'};
my $content = encode('utf8', $message->{'content'});
my %sendmail_params = (
To => $message->{'to_address'} || $member->{'email'},

View file

@ -91,6 +91,7 @@ END_SQL
# warn( Data::Dumper->Dump( [ $row ], [ 'row' ] ) );
$return->{'days_in_advance'} = $row->{'days_in_advance'} if defined $row->{'days_in_advance'};
$return->{'wants_digest'} = $row->{'wants_digest'} if defined $row->{'wants_digest'};
$return->{'letter_code'} = $row->{'letter_code'};
$transports{$row->{'message_transport_type'}} = 1;
}
@{$return->{'transports'}} = keys %transports;

View file

@ -31,6 +31,13 @@ use C4::Search;
use C4::Circulation;
use C4::Accounts;
# for _koha_notify_reserve
use C4::Members::Messaging;
use C4::Members qw( GetMember );
use C4::Letters;
use C4::Branch qw( GetBranchDetail );
use List::MoreUtils qw( firstidx );
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
my $library_name = C4::Context->preference("LibraryName");
@ -1010,6 +1017,9 @@ sub ModReserveAffect {
$sth = $dbh->prepare($query);
$sth->execute( $itemnumber, $borrowernumber,$biblionumber);
$sth->finish;
_koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber ) if ( !$transferToDo );
return;
}
@ -1375,6 +1385,72 @@ sub _Findgroupreserve {
return @results;
}
=item _koha_notify_reserve
=over 4
_koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber );
=back
Sends a notification to the patron that their hold has been filled (through
ModReserveAffect, _not_ ModReserveFill)
=cut
sub _koha_notify_reserve {
my ($itemnumber, $borrowernumber, $biblionumber) = @_;
my $dbh = C4::Context->dbh;
my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, message_name => 'Hold Filled' } );
return if ( !defined( $messagingprefs->{'letter_code'} ) );
my $sth = $dbh->prepare("
SELECT *
FROM reserves
WHERE borrowernumber = ?
AND biblionumber = ?
");
$sth->execute( $borrowernumber, $biblionumber );
my $reserve = $sth->fetchrow_hashref;
my $branch_details = GetBranchDetail( $reserve->{'branchcode'} );
my $admin_email_address = $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
my $letter = getletter( 'reserves', $messagingprefs->{'letter_code'} );
C4::Letters::parseletter( $letter, 'branches', $reserve->{'branchcode'} );
C4::Letters::parseletter( $letter, 'borrowers', $reserve->{'borrowernumber'} );
C4::Letters::parseletter( $letter, 'biblio', $reserve->{'biblionumber'} );
C4::Letters::parseletter( $letter, 'reserves', $reserve->{'borrowernumber'}, $reserve->{'biblionumber'} );
if ( $reserve->{'itemnumber'} ) {
C4::Letters::parseletter( $letter, 'items', $reserve->{'itemnumber'} );
}
$letter->{'content'} =~ s/<<[a-z0-9_]+\.[a-z0-9]+>>//g; #remove any stragglers
if ( -1 != firstidx { $_ eq 'email' } @{$messagingprefs->{transports}} ) {
# aka, 'email' in ->{'transports'}
C4::Letters::EnqueueLetter(
{ letter => $letter,
borrowernumber => $borrowernumber,
message_transport_type => 'email',
from_address => $admin_email_address,
}
);
}
if ( -1 != firstidx { $_ eq 'sms' } @{$messagingprefs->{transports}} ) {
C4::Letters::EnqueueLetter(
{ letter => $letter,
borrowernumber => $borrowernumber,
message_transport_type => 'sms',
}
);
}
}
=back
=head1 AUTHOR

View file

@ -209,6 +209,11 @@ $(document).ready(function() {
<!--TMPL_ELSE-->
<option value="members">Members</option>
<!--/TMPL_IF-->
<!--TMPL_IF Name="reserves"-->
<option value="reserves" selected="selected">Holds</option>
<!--TMPL_ELSE-->
<option value="reserves">Holds</option>
<!--/TMPL_IF-->
</select>
</li>
<li>
@ -250,6 +255,11 @@ $(document).ready(function() {
<!--TMPL_ELSE-->
<option value="members">Members</option>
<!--/TMPL_IF-->
<!--TMPL_IF Name="reserves"-->
<option value="reserves" selected="selected">Holds</option>
<!--TMPL_ELSE-->
<option value="reserves">Holds</option>
<!--/TMPL_IF-->
</select>
</li>
<li>

View file

@ -54,10 +54,12 @@ sub StringSearch {
return $sth->fetchall_arrayref({});
}
# FIXME untranslateable
our %column_map = (
aqbooksellers => 'BOOKSELLERS',
aqorders => 'ORDERS',
serial => 'SERIALS',
reserves => 'HOLDS',
);
sub column_picks ($) {
@ -132,7 +134,13 @@ if ( $op eq 'add_form' ) {
push @SQLfieldname, column_picks('branches');
# add acquisition specific tables
if ( index( $module, "acquisition" ) > 0 ) { # FIXME: imprecise comparison
if ( $module eq "reserves" ) {
push @SQLfieldname, column_picks('borrowers'),
column_picks('reserves'),
column_picks('biblio'),
column_picks('items');
}
elsif ( index( $module, "acquisition" ) > 0 ) { # FIXME: imprecise comparison
push @SQLfieldname, column_picks('aqbooksellers'), column_picks('aqorders');
# add issues specific tables
}