Bug 10626 - Remove doubled up TT plugins - Merge KohaBranchName and Branches
authorKyle M Hall <kyle@bywatersolutions.com>
Tue, 23 Jul 2013 13:52:08 +0000 (09:52 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Sat, 14 Dec 2013 01:05:56 +0000 (01:05 +0000)
Looking at the TT plugin directory I notice we have some plugins that
seem to do the same thing:

KohaBranchName.pm
Branches.pm

This patch drops KohaBranchName in favor of Branches

Test Plan:
1) Apply this patch
2) View a basket group, note the branch name is displayed
3) View a subscription's details, note the branch name is displayed
4) View suggestions, note the branch names are displayed
5) Return an item that needs transfered, note the branch name is displayed
6) Run 'prove t/db_dependent/Koha_template_plugin_Branches.t'

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
Also tested with a branch name with umlauts.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Koha/Template/Plugin/Branches.pm
Koha/Template/Plugin/KohaBranchName.pm [deleted file]
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt
koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt
t/db_dependent/Koha_template_plugin_Branches.t [new file with mode: 0644]
t/db_dependent/Koha_template_plugin_KohaBranchName.t [deleted file]

index e9ff105..343158c 100644 (file)
@@ -32,7 +32,7 @@ sub GetName {
     my $sth   = C4::Context->dbh->prepare($query);
     $sth->execute($branchcode);
     my $b = $sth->fetchrow_hashref();
-    return encode( 'UTF-8', $b->{'branchname'} );
+    return $b ? encode( 'UTF-8', $b->{'branchname'} ) : q{};
 }
 
 1;
diff --git a/Koha/Template/Plugin/KohaBranchName.pm b/Koha/Template/Plugin/KohaBranchName.pm
deleted file mode 100644 (file)
index 51d1a44..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-package Koha::Template::Plugin::KohaBranchName;
-
-# Copyright Bywater Solutions 2012
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-use Modern::Perl;
-
-use Template::Plugin::Filter;
-use base qw( Template::Plugin::Filter );
-
-use C4::Branch qw( GetBranchName );;
-
-sub filter {
-    my ($self, $branchcode) = @_;
-    my $name = GetBranchName( $branchcode );
-    return defined($name) ? $name : '';
-}
-
-1;
index c7c9a1b..f256ec3 100644 (file)
@@ -1,4 +1,4 @@
-[% USE KohaBranchName %]
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Basket grouping for [% booksellername |html %]</title>
 <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
@@ -269,8 +269,8 @@ function submitForm(form) {
                                                                                                [% END %]
                                                </td>
                                     <td>[% basketgroup.id %]</td>
-                                    <td>[% basketgroup.billingplace | $KohaBranchName %]</td>
-                                    <td>[% IF (basketgroup.freedeliveryplace) %]Free delivery place[% ELSE %][% basketgroup.deliveryplace | $KohaBranchName %][% END %]</td>
+                                    <td>[% Branches.GetName( basketgroup.billingplace ) %]</td>
+                                    <td>[% IF (basketgroup.freedeliveryplace) %]Free delivery place[% ELSE %][% Branches.GetName( basketgroup.deliveryplace ) %][% END %]</td>
                                     <td>[% basketgroup.basketsqty %]</td>
                                                        <td>
                                                                <input type="button" onclick="closeandprint([% basketgroup.id %])" value="Close and print" />
@@ -307,8 +307,8 @@ function submitForm(form) {
                                                                                [% END %]
                                        </td>
                                     <td>[% basketgroup.id %]</td>
-                                    <td>[% basketgroup.billingplace | $KohaBranchName %]</td>
-                                    <td>[% IF (basketgroup.freedeliveryplace) %]Free delivery place[% ELSE %][% basketgroup.deliveryplace | $KohaBranchName %][% END %]</td>
+                                    <td>[% Branches.GetName( basketgroup.billingplace ) %]</td>
+                                    <td>[% IF (basketgroup.freedeliveryplace) %]Free delivery place[% ELSE %][% Branches.GetName( basketgroup.deliveryplace ) %][% END %]</td>
                                     <td>[% basketgroup.basketsqty %]</td>
                                        <td>
                                                        <form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="reopen" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid %]" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id %]" /><input type="submit" value="Reopen" /></form>
index fb30311..550c4ca 100644 (file)
@@ -1,5 +1,5 @@
 [% USE KohaDates %]
-[% USE KohaBranchName %]
+[% USE Branches %]
 
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Circulation &rsaquo; Check in [% title |html %]</title>
@@ -92,7 +92,7 @@ $(document).ready(function () {
 </div>
 [% END %]
 <!-- case of a mistake in transfer loop -->
-[% IF ( WrongTransfer ) %]<div id="return2" class="dialog message"><!-- WrongTransfer --><h3>Please return <a href="/cgi-bin/koha/catalogue/detail.pl?type=intra&amp;biblionumber=[% itembiblionumber %]">[% title |html %]</a> to [% TransferWaitingAt | $KohaBranchName %]</h3><h3><a href="#" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;&amp;branchcode=[% homebranch %]&amp;op=slip'); return true;">Print slip</a> or <a href="/cgi-bin/koha/circ/returns.pl?itemnumber=[% itemnumber %]&amp;canceltransfer=1">Cancel transfer</a></h3>
+[% IF ( WrongTransfer ) %]<div id="return2" class="dialog message"><!-- WrongTransfer --><h3>Please return <a href="/cgi-bin/koha/catalogue/detail.pl?type=intra&amp;biblionumber=[% itembiblionumber %]">[% title |html %]</a> to [% Branches.GetName( TransferWaitingAt ) %]</h3><h3><a href="#" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;&amp;branchcode=[% homebranch %]&amp;op=slip'); return true;">Print slip</a> or <a href="/cgi-bin/koha/circ/returns.pl?itemnumber=[% itemnumber %]&amp;canceltransfer=1">Cancel transfer</a></h3>
 [% IF ( wborcnum ) %]<h5>Hold for:</h5>
         <ul><li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">
             [% borsurname %], [% borfirstname %]</a> ([% borcnum %])</li>
index ccac0bb..59b12a7 100644 (file)
@@ -1,4 +1,4 @@
-[% USE KohaBranchName %]
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Serials &rsaquo; Details for subscription #[% subscriptionid %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -87,7 +87,7 @@ $(document).ready(function() {
         <li><span class="label">Librarian identity:</span> [% librarian %]</li>
         <li><span class="label">Vendor:</span> <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% aqbooksellerid %]">[% aqbooksellername %]</a></li>
         <li><span class="label">Biblio:</span>  <a href="/cgi-bin/koha/catalogue/[% default_bib_view %].pl?biblionumber=[% bibnum %]">[% bibliotitle %]</a> <i>([% bibnum %])</i></li>
-[% IF ( branchcode ) %]<li><span class="label">Library:</span> [% branchcode | $KohaBranchName %]</li>[% END %]
+[% IF ( branchcode ) %]<li><span class="label">Library:</span> [% Branches.GetName( branchcode ) %]</li>[% END %]
         [% IF ( serialsadditems ) %]
             <li><span class="label">Items:</span> Serial receipt creates an item record.</li>
         [% ELSE %]
index 7c6c98d..9f5c40e 100644 (file)
@@ -1,5 +1,5 @@
 [% USE KohaAuthorisedValues %]
-[% USE KohaBranchName %]
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions  &rsaquo;
     [% IF ( op_save ) %]
@@ -242,18 +242,18 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o
             <tr>
                 <th><span class="label">Suggestion creation</span> </th>
                 <td>[% suggesteddate %]</td>
-                <td>[% IF ( suggestedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% suggestedby_borrowernumber %]">[% suggestedby_surname %], [% suggestedby_firstname %]</a>  [% suggestedby_branchcode | $KohaBranchName %] ([% suggestedby_description %])[% END %]
+                <td>[% IF ( suggestedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% suggestedby_borrowernumber %]">[% suggestedby_surname %], [% suggestedby_firstname %]</a>  [% Branches.GetName( suggestedby_branchcode ) %] ([% suggestedby_description %])[% END %]
                 </td>
             </tr>
             <tr>
                 <th><span class="label">Suggestion management</span> </th>
                 <td>[% manageddate %]</td>
-                <td>[% IF ( managedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% managedby_borrowernumber %]">[% managedby_surname %], [% managedby_firstname %]</a> [% managedby_branchcode | $KohaBranchName %] ([% managedby_description %])[% END %]</td>
+                <td>[% IF ( managedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% managedby_borrowernumber %]">[% managedby_surname %], [% managedby_firstname %]</a> [% Branches.GetName( managedby_branchcode ) %] ([% managedby_description %])[% END %]</td>
             </tr>
             <tr>
                 <th><span class="label">Suggestion accepted</span> </th>
                 <td>[% accepteddate %]</td>
-                <td>[% IF ( acceptedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% acceptedby_borrowernumber %]">[% acceptedby_surname %], [% acceptedby_firstname %]</a> [% acceptedby_branchcode | $KohaBranchName %] ([% acceptedby_description %])[% END %]</td>
+                <td>[% IF ( acceptedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% acceptedby_borrowernumber %]">[% acceptedby_surname %], [% acceptedby_firstname %]</a> [% Branches.GetName( acceptedby_branchcode ) %] ([% acceptedby_description %])[% END %]</td>
             </tr>
             </tbody>
         </table></li></ol>
@@ -374,18 +374,18 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o
             <tr>
                 <th><label for="suggesteddate">Suggestion creation</label> </th>
                 <td><input type="text" id="suggesteddate" name="suggesteddate" size="10" maxlength="10" value="[% suggesteddate %]"/></td>
-                <td><input type="hidden" id="suggestedby" name="suggestedby" value="[% suggestedby %]"/>[% IF ( suggestedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% suggestedby_borrowernumber %]">[% suggestedby_surname %], [% suggestedby_firstname %]</a>  [% suggestedby_branchcode | $KohaBranchName %] ([% suggestedby_description %])[% END %]
+                <td><input type="hidden" id="suggestedby" name="suggestedby" value="[% suggestedby %]"/>[% IF ( suggestedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% suggestedby_borrowernumber %]">[% suggestedby_surname %], [% suggestedby_firstname %]</a>  [% Branches.GetName( suggestedby_branchcode ) %] ([% suggestedby_description %])[% END %]
                 </td>
             </tr>
             <tr>
                 <th><label for="managedon">Suggestion management</label> </th>
                 <td><input type="text" id="managedon" name="manageddate" size="10" maxlength="10" value="[% manageddate %]" /></td>
-                <td><input type="hidden" id="managedby" name="managedby" value="[% managedby %]"/>[% IF ( managedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% managedby_borrowernumber %]">[% managedby_surname %], [% managedby_firstname %]</a> [% managedby_branchcode | $KohaBranchName %] ([% managedby_description %])[% END %]</td>
+                <td><input type="hidden" id="managedby" name="managedby" value="[% managedby %]"/>[% IF ( managedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% managedby_borrowernumber %]">[% managedby_surname %], [% managedby_firstname %]</a> [% Branches.GetName( managedby_branchcode ) %] ([% managedby_description %])[% END %]</td>
             </tr>
             <tr>
                 <th><label for="accepteddate">Suggestion accepted</label> </th>
                 <td><input type="text" id="accepteddate" name="accepteddate" size="10" maxlength="10" value="[% accepteddate %]" /></td>
-                <td><input type="hidden" id="acceptedby" name="acceptedby" value="[% acceptedby %]"/>[% IF ( acceptedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% acceptedby_borrowernumber %]">[% acceptedby_surname %], [% acceptedby_firstname %]</a> [% acceptedby_branchcode | $KohaBranchName %] ([% acceptedby_description %])[% END %]</td>
+                <td><input type="hidden" id="acceptedby" name="acceptedby" value="[% acceptedby %]"/>[% IF ( acceptedby_borrowernumber ) %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% acceptedby_borrowernumber %]">[% acceptedby_surname %], [% acceptedby_firstname %]</a> [% Branches.GetName( acceptedby_branchcode ) %] ([% acceptedby_description %])[% END %]</td>
             </tr>
             </tbody>
         </table></li></ol>
@@ -503,7 +503,7 @@ h4.local_collapse a { font-size : 80%; text-decoration: none; } fieldset.brief o
                     [% IF ( suggestions_loo.manageddate ) %] - [% suggestions_loo.manageddate %][% END %]
                 </td>
                 <td>
-                    [% suggestions_loo.branchcode | $KohaBranchName %]
+                    [% Branches.GetName( suggestions_loo.branchcode ) %]
                 </td>
                 <td>
                     [% suggestions_loo.budget_name %]
diff --git a/t/db_dependent/Koha_template_plugin_Branches.t b/t/db_dependent/Koha_template_plugin_Branches.t
new file mode 100644 (file)
index 0000000..c47c466
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+# Copyright 2013 Equinox Software, Inc.
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Test::More tests => 5;
+
+BEGIN {
+    use_ok('Koha::Template::Plugin::Branches');
+}
+
+my $plugin = Koha::Template::Plugin::Branches->new();
+ok($plugin, "initialized Branches plugin");
+
+my $name = $plugin->GetName('CPL');
+is($name, 'Centerville', 'retrieved expected name for CPL');
+
+$name = $plugin->GetName('__ANY__');
+is($name, '', 'received empty string as name of the "__ANY__" placeholder library code');
+
+$name = $plugin->GetName(undef);
+is($name, '', 'received empty string as name of NULL/undefined library code');
diff --git a/t/db_dependent/Koha_template_plugin_KohaBranchName.t b/t/db_dependent/Koha_template_plugin_KohaBranchName.t
deleted file mode 100644 (file)
index dbba6da..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/perl
-
-# Copyright 2013 Equinox Software, Inc.
-#
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
-#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use Test::More tests => 5;
-
-BEGIN {
-    use_ok('Koha::Template::Plugin::KohaBranchName');
-}
-
-my $filter = Koha::Template::Plugin::KohaBranchName->new();
-ok($filter, "initialized KohaBranchName plugin");
-
-my $name = $filter->filter('CPL');
-is($name, 'Centerville', 'retrieved expected name for CPL');
-
-$name = $filter->filter('__ANY__');
-is($name, '', 'received empty string as name of the "__ANY__" placeholder library code');
-
-$name = $filter->filter(undef);
-is($name, '', 'received empty string as name of NULL/undefined library code');