Bug 21082: Add new admin page for overdrive
authorNick Clemens <nick@bywatersolutions.com>
Tue, 17 Jul 2018 14:08:13 +0000 (14:08 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Tue, 9 Oct 2018 11:04:23 +0000 (11:04 +0000)
The 'authname' field required for OverDrive can differ per branch.
This patch adds Koha Objects for dealing with OD info and submitting
authnames per branch. The description is left open so future branch info
can be added.

To test:
1 - prove -v t/db_dependent/Koha/Library/OverDriveInfos.t
2 - visit cgi-bin/koha/admin/overdrive.pl
3 - Add some authnames for various branches
4 - Verify data saves correctly

Signed-off-by: Sandy Allgood <sandy.allgood@citruslibraries.org>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Library/OverDriveInfo.pm [new file with mode: 0644]
Koha/Library/OverDriveInfos.pm [new file with mode: 0644]
admin/overdrive.pl [new file with mode: 0755]
koha-tmpl/intranet-tmpl/prog/en/modules/admin/overdrive.tt [new file with mode: 0644]
t/db_dependent/Koha/Library/OverDriveInfos.t [new file with mode: 0644]

diff --git a/Koha/Library/OverDriveInfo.pm b/Koha/Library/OverDriveInfo.pm
new file mode 100644 (file)
index 0000000..6717699
--- /dev/null
@@ -0,0 +1,44 @@
+package Koha::Library::OverDriveInfo;
+
+# 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Carp;
+
+use Koha::Database;
+
+use base qw(Koha::Object);
+
+=head1 NAME
+
+Koha::Library::OverDriveInfo - Koha Library OverDrive Info Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 _type
+
+=cut
+
+sub _type {
+    return 'BranchesOverdrive';
+}
+
+1;
diff --git a/Koha/Library/OverDriveInfos.pm b/Koha/Library/OverDriveInfos.pm
new file mode 100644 (file)
index 0000000..8edc7fb
--- /dev/null
@@ -0,0 +1,54 @@
+package Koha::Library::OverDriveInfos;
+
+# 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use Carp;
+
+use Koha::Database;
+
+use Koha::Library::OverDriveInfo;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::Library::OverDriveInfos - Koha Library OverDrive info Object set class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+=head3 object_class
+
+=cut
+
+sub _type {
+    return 'BranchesOverdrive';
+}
+
+sub object_class {
+    return 'Koha::Library::OverDriveInfo';
+}
+
+1;
diff --git a/admin/overdrive.pl b/admin/overdrive.pl
new file mode 100755 (executable)
index 0000000..489bf0a
--- /dev/null
@@ -0,0 +1,75 @@
+#!/usr/bin/perl
+
+# Copyright Koha Development Team
+#
+# 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 CGI qw ( -utf8 );
+use C4::Auth;
+use C4::Context;
+use C4::Output;
+
+use Koha::Libraries;
+use Koha::Library::OverDriveInfos;
+
+my $input         = CGI->new;
+my @branchcodes   = $input->multi_param('branchcode');
+my @authnames     = $input->multi_param('authname');
+my $op            = $input->param('op');
+my @messages;
+
+our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {   template_name   => 'admin/overdrive.tt',
+        query           => $input,
+        type            => 'intranet',
+        authnotrequired => 0,
+        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
+    }
+);
+
+if ( $op && $op eq 'update' ) {
+    my %od_info;
+    @od_info{ @branchcodes } = @authnames;
+    while( my($branchcode,$authname) = each %od_info){
+        my $cur_info = Koha::Library::OverDriveInfos->find($branchcode);
+        if( $cur_info ) {
+            $cur_info->authname($authname)->store;
+        } else {
+            Koha::Library::OverDriveInfo->new({
+                branchcode => $branchcode,
+                authname   => $authname,
+            })->store;
+        }
+    }
+}
+
+my @branches = Koha::Libraries->search();
+my @branch_od_info;
+foreach my $branch ( @branches ){
+    my $od_info =  Koha::Library::OverDriveInfos->find($branch->branchcode);
+    if( $od_info ){
+        push @branch_od_info, { branchcode => $od_info->branchcode, authname => $od_info->authname };
+    } else {
+        push @branch_od_info, { branchcode => $branch->branchcode, authname => "" };
+    }
+}
+
+$template->param(
+    branches => \@branch_od_info,
+);
+
+output_html_with_http_headers $input, $cookie, $template->output;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/overdrive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/overdrive.tt
new file mode 100644 (file)
index 0000000..dde99d3
--- /dev/null
@@ -0,0 +1,65 @@
+[% USE Asset %]
+[% USE Branches %]
+[% USE HtmlTags %]
+[% SET footerjs = 1 %]
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Administration &rsaquo; Library OverDrive Info &rsaquo;</title>
+[% INCLUDE 'doc-head-close.inc' %]
+[% Asset.css("css/datatables.css") %]
+</head>
+
+<body id="admin_overdrive" class="admin">
+[% INCLUDE 'header.inc' %]
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo;  <a href="/cgi-bin/koha/admin/overdrive.pl">Library OverDrive Info</a> &rsaquo;
+</div>
+
+<div id="doc3" class="yui-t2">
+
+<div id="bd">
+    <div id="yui-main">
+    <div class="yui-b">
+
+<form action="/cgi-bin/koha/admin/overdrive.pl" name="overdrive_form" method="post" class="validated">
+    <input type="hidden" name="op" value="update" />
+    <fieldset class="rows">
+        <legend>
+            OverDrive
+        </legend>
+        <table id="od_info">
+            <thead>
+                <th>Branch</th>
+                <th>Authname</th>
+            </thead>
+            <tbody>
+                [% FOREACH b IN branches %]
+                <tr>
+                <td>
+                    [% Branches.GetName( b.branchcode ) %]
+                    <input type="hidden" name="branchcode" value="[% b.branchcode %]" />
+                </td>
+                <td>
+                    <input type="text" name="authname" value="[% b.authname %]" />
+                </td>
+                </tr>
+                [% END %]
+            </tbody>
+        </table>
+        <input type="submit" value="Submit">
+</form>
+
+</div>
+</div>
+<div class="yui-b">
+[% INCLUDE 'admin-menu.inc' %]
+</div>
+</div>
+
+[% MACRO jsinclude BLOCK %]
+    [% Asset.js("js/admin-menu.js") %]
+    [% INCLUDE 'datatables.inc' %]
+    [% INCLUDE 'columns_settings.inc' %]
+    <script type="text/javascript">
+    </script>
+[% END %]
+[% INCLUDE 'intranet-bottom.inc' %]
diff --git a/t/db_dependent/Koha/Library/OverDriveInfos.t b/t/db_dependent/Koha/Library/OverDriveInfos.t
new file mode 100644 (file)
index 0000000..02802a3
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+
+# Copyright 2018 Koha Development team
+#
+# 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 => 4;
+
+use Koha::Library::OverDriveInfos;
+use Koha::Database;
+
+use t::lib::TestBuilder;
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+my $builder = t::lib::TestBuilder->new;
+my $library1 = $builder->build({ source => 'Branch'});
+my $library2 = $builder->build({ source => 'Branch'});
+my $nb_of_infos = Koha::Library::OverDriveInfos->search->count;
+my $new_od_info_1 = Koha::Library::OverDriveInfo->new({
+    branchcode => $library1->{'branchcode'},
+    authname => 'Gorilla'
+})->store;
+my $new_od_info_2 = Koha::Library::OverDriveInfo->new({
+    branchcode => $library2->{'branchcode'},
+    authname => 'Cheese'
+})->store;
+
+
+is( $new_od_info_1->authname, "Gorilla", 'Adding a new authname should have set the authname');
+is( Koha::Library::OverDriveInfos->search->count, $nb_of_infos + 2, 'The 2 infos should have been added' );
+
+my $retrieved_od_info_1 = Koha::Library::OverDriveInfos->find( $new_od_info_1->branchcode );
+is( $retrieved_od_info_1->authname, $new_od_info_1->authname, 'Find an info  by branch should return the correct info' );
+
+$retrieved_od_info_1->delete;
+is( Koha::Library::OverDriveInfos->search->count, $nb_of_infos + 1, 'Delete should have deleted the info' );
+
+$schema->storage->txn_rollback;