Bug 19855: Remove C4::Letters::findrelatedto
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 20 Dec 2017 17:14:57 +0000 (14:14 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 23 Apr 2018 17:22:15 +0000 (14:22 -0300)
This subroutine is called only once. It only concat firstname and
surname for subscribers.
It can be easily replaced with Koha::Patron

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Letters.pm
serials/viewalerts.pl

index 40cd364..ed27b1f 100644 (file)
@@ -46,7 +46,7 @@ BEGIN {
     require Exporter;
     @ISA = qw(Exporter);
     @EXPORT = qw(
-        &GetLetters &GetLettersAvailableForALibrary &GetLetterTemplates &DelLetter &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &findrelatedto &SendAlerts &GetPrintMessages &GetMessageTransportTypes
+        &GetLetters &GetLettersAvailableForALibrary &GetLetterTemplates &DelLetter &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &SendAlerts &GetPrintMessages &GetMessageTransportTypes
     );
 }
 
@@ -337,37 +337,6 @@ sub getalert {
     return $sth->fetchall_arrayref({});
 }
 
-=head2 findrelatedto($type, $externalid)
-
-    parameters :
-    - $type : the type of alert
-    - $externalid : the id of the "object" to query
-
-    In the table alert, a "id" is stored in the externalid field. This "id" is related to another table, depending on the type of the alert.
-    When type=issue, the id is related to a subscriptionid and this sub returns the name of the biblio.
-
-=cut
-    
-# outmoded POD:
-# When type=virtual, the id is related to a virtual shelf and this sub returns the name of the sub
-
-sub findrelatedto {
-    my $type       = shift or return;
-    my $externalid = shift or return;
-    my $q = ($type eq 'issue'   ) ?
-"select title as result from subscription left join biblio on subscription.biblionumber=biblio.biblionumber where subscriptionid=?" :
-            ($type eq 'borrower') ?
-"select concat(firstname,' ',surname) from borrowers where borrowernumber=?" : undef;
-    unless ($q) {
-        warn "findrelatedto(): Illegal type '$type'";
-        return;
-    }
-    my $sth = C4::Context->dbh->prepare($q);
-    $sth->execute($externalid);
-    my ($result) = $sth->fetchrow;
-    return $result;
-}
-
 =head2 SendAlerts
 
     my $err = &SendAlerts($type, $externalid, $letter_code);
index 451032f..63ed214 100755 (executable)
@@ -46,8 +46,10 @@ my $subscriptionid=$input->param('subscriptionid');
 my $borrowers = getalert('','issue',$subscriptionid);
 my $subscription = GetSubscription($subscriptionid);
 
-foreach (@$borrowers) {
-    $_->{name} = findrelatedto('borrower',$_->{borrowernumber});
+for my $borrowernumber (@$borrowers) {
+    my $patron = Koha::Patrons->find( $borrowernumber );
+    next unless $borrowernumber; # Just in case...
+    $borrowers->{name} = join( ' ', $patron->firstname, $patron->surname );
 }
 $template->param(alertloop => $borrowers,
                 bibliotitle => $subscription->{bibliotitle},