From 29ab4b3026287974b7a6355e8446439b6bd54320 Mon Sep 17 00:00:00 2001
From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
Date: Thu, 3 Oct 2019 12:21:21 +0100
Subject: [PATCH] Bug 23681: Allow for changes to debarments

The structure of debarments has changes slightly in that the displayed
text is now a product of a call to Koha::RestrictionTypes rather than
just the debarment's code. This patch allows for that

Signed-off-by: Benjamin Veasey <B.T.Veasey@lboro.ac.uk>
Sponsored-by: Loughborough University
---
 circ/circulation.pl                                  |  2 ++
 .../prog/en/includes/borrower_debarments.inc         | 12 ++----------
 .../prog/en/modules/members/memberentrygen.tt        |  3 ++-
 members/memberentry.pl                               |  5 ++++-
 members/moremember.pl                                |  5 +++++
 5 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/circ/circulation.pl b/circ/circulation.pl
index 2fd34fc068..ff0bb158cb 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -45,6 +45,7 @@ use Koha::AuthorisedValues;
 use Koha::CsvProfiles;
 use Koha::Patrons;
 use Koha::Patron::Debarments qw( GetDebarments );
+use Koha::RestrictionTypes;
 use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Plugins;
 use Koha::Database;
@@ -625,6 +626,7 @@ $template->param(
     SpecifyDueDate            => $duedatespec_allow,
     PatronAutoComplete      => C4::Context->preference("PatronAutoComplete"),
     debarments                => scalar GetDebarments({ borrowernumber => $borrowernumber }),
+    restriction_types         => scalar Koha::RestrictionTypes->keyed_on_code(),
     todaysdate                => output_pref( { dt => dt_from_string()->set(hour => 23)->set(minute => 59), dateformat => 'sql' } ),
     has_modifications         => $has_modifications,
     override_high_holds       => $override_high_holds,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc
index 2bbfc7aad3..dbc1273f88 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc
@@ -17,18 +17,10 @@
             </thead>
             <tbody>
                 [% FOREACH d IN debarments %]
+                    [% dtype = d.type %]
                     <tr>
                         <td>
-                            [% SWITCH d.type %]
-                                [% CASE 'MANUAL' %]
-                                    <span>Manual</span>
-                                [% CASE 'OVERDUES' %]
-                                    <span>Overdues</span>
-                                [% CASE 'SUSPENSION' %]
-                                    <span>Suspension</span>
-                                [% CASE 'DISCHARGE' %]
-                                    <span>Discharge</span>
-                            [% END %]
+                            [% restriction_types.$dtype.display_text | html %]
                         </td>
                         <td>
                             [% IF d.comment.search('OVERDUES_PROCESS') %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
index c5f17cb6f0..281d69d5ba 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
@@ -1355,8 +1355,9 @@ legend:hover {
                                                 </thead>
                                                 <tbody>
                                                     [% FOREACH d IN debarments %]
+                                                        [% dtype = d.type %]
                                                         <tr>
-                                                            <td>[% d.type | html %]</td>
+                                                            <td>[% restriction_types.$dtype.display_text | html %]</td>
                                                             <td>
                                                                 [% IF d.comment.search('OVERDUES_PROCESS') %]
                                                                     Restriction added by overdues process [% d.comment.remove('OVERDUES_PROCESS ') | $raw %]
diff --git a/members/memberentry.pl b/members/memberentry.pl
index d406817ecd..514d1e197c 100755
--- a/members/memberentry.pl
+++ b/members/memberentry.pl
@@ -36,6 +36,7 @@ use Koha::AuthUtils;
 use Koha::AuthorisedValues;
 use Koha::Email;
 use Koha::Patron::Debarments qw( AddDebarment DelDebarment GetDebarments );
+use Koha::RestrictionTypes;
 use Koha::Cities;
 use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Libraries;
@@ -117,7 +118,9 @@ foreach my $id ( @delete_guarantor ) {
 
 ## Deal with debarments
 $template->param(
-    debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ) );
+    debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ),
+    restriction_types => scalar Koha::RestrictionTypes->keyed_on_code()
+);
 my @debarments_to_remove = $input->multi_param('remove_debarment');
 foreach my $d ( @debarments_to_remove ) {
     DelDebarment( $d );
diff --git a/members/moremember.pl b/members/moremember.pl
index 89ec5d9af5..3b0f5a752b 100755
--- a/members/moremember.pl
+++ b/members/moremember.pl
@@ -37,6 +37,7 @@ use List::MoreUtils qw( uniq );
 use Scalar::Util qw( looks_like_number );
 use Koha::Patron::Attribute::Types;
 use Koha::Patron::Debarments qw( GetDebarments );
+use Koha::RestrictionTypes;
 use Koha::Patron::Messages;
 use Koha::CsvProfiles;
 use Koha::Holds;
@@ -79,6 +80,10 @@ for (qw(gonenoaddress lost borrowernotes is_debarred)) {
     $patron->$_ and $template->param(flagged => 1) and last;
 }
 
+$template->param(
+    restriction_types => scalar Koha::RestrictionTypes->keyed_on_code()
+}
+
 if ( $patron->is_debarred ) {
     $template->param(
         'debarments'      => scalar GetDebarments({ borrowernumber => $borrowernumber }),
-- 
2.20.1