Bug 18104 - allow SIP2 field AE (personal name ) to be customized
authorKyle M Hall <kyle@bywatersolutions.com>
Mon, 6 Mar 2017 12:05:31 +0000 (12:05 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 6 Jul 2017 17:52:54 +0000 (14:52 -0300)
Koha's SIP2 server sends the patron's name in the format "Firstname
Surname" which is not very good for machine reading. We need to allow
the format of the patron name to be customized in a manner similar to
what is done with the DA field on bug 16755.

Test Plan:
1) Apply this patch, start or restart your SIP server
2) Find a patron with a first and last name
3) Send a patron information request via the sip2 cli tool
4) Note the AE field has the format "<firstname> <surname>" ( i.e. the current behavior )
5) Add this parameter to the login stanza you are using:
   ae_field_template="[% patron.surname %][% IF patron.firstname %], [% patron.firstname %][% END %]"
6) Restart your SIP server
7) Repeat step 3
8) Note the AE field now has the format "<surname>, <firstname>"

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Benjamin Daeuber <BDaeuber@cityoffargo.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/SIP/ILS/Patron.pm
C4/SIP/Sip/MsgType.pm
etc/SIPconfig.xml

index 64ef4f6..391926b 100644 (file)
@@ -191,6 +191,26 @@ sub AUTOLOAD {
     }
 }
 
+sub name {
+    my ( $self, $template ) = @_;
+
+    if ($template) {
+        require Template;
+        require Koha::Patrons;
+
+        my $tt = Template->new();
+
+        my $patron = Koha::Patrons->find( $self->{borrowernumber} );
+
+        my $output;
+        $tt->process( \$template, { patron => $patron }, \$output );
+        return $output;
+    }
+    else {
+        return $self->{name};
+    }
+}
+
 sub check_password {
     my ( $self, $pwd ) = @_;
 
index f3815cf..dded51e 100644 (file)
@@ -420,7 +420,7 @@ sub build_patron_status {
 
         $resp .= patron_status_string($patron);
         $resp .= $lang . timestamp();
-        $resp .= add_field( FID_PERSONAL_NAME, $patron->name );
+        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ) );
 
         # while the patron ID we got from the SC is valid, let's
         # use the one returned from the ILS, just in case...
@@ -948,7 +948,7 @@ sub handle_patron_info {
         # while the patron ID we got from the SC is valid, let's
         # use the one returned from the ILS, just in case...
         $resp .= add_field( FID_PATRON_ID,     $patron->id );
-        $resp .= add_field( FID_PERSONAL_NAME, $patron->name );
+        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ) );
 
         # TODO: add code for the fields
         #   hold items limit
@@ -1246,7 +1246,7 @@ sub handle_patron_enable {
         $resp .= $patron->language . timestamp();
 
         $resp .= add_field( FID_PATRON_ID,     $patron->id );
-        $resp .= add_field( FID_PERSONAL_NAME, $patron->name );
+        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ) );
         if ( defined($patron_pwd) ) {
             $resp .= add_field( FID_VALID_PATRON_PWD, sipbool( $patron->check_password($patron_pwd) ) );
         }
index 80f667e..f51f093 100644 (file)
@@ -51,6 +51,7 @@
       <login id="lpl-sc-beacock" password="xyzzy"
              delimiter="|" error-detect="enabled" institution="LPL"
              send_patron_home_library_in_af="1"
+             ae_field_template="[% patron.surname %][% IF patron.firstname %], [% patron.firstname %][% END %]"
              da_field_template="[% patron.surname %][% IF patron.firstname %], [% patron.firstname %][% END %]"
              av_field_template="[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]" >
           <screen_msg_regex find="Greetings from Koha." replace="Welcome to your library!" />