From df339d0372c633635bc63d87d7caa7807a540aed Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 17 Jul 2018 14:08:13 +0000 Subject: [PATCH] Bug 21082: Add new admin page for overdrive 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 Signed-off-by: Chris Cormack Signed-off-by: Nick Clemens --- Koha/Library/OverDriveInfo.pm | 44 +++++++++++ Koha/Library/OverDriveInfos.pm | 54 +++++++++++++ admin/overdrive.pl | 75 +++++++++++++++++++ .../prog/en/modules/admin/overdrive.tt | 65 ++++++++++++++++ t/db_dependent/Koha/Library/OverDriveInfos.t | 55 ++++++++++++++ 5 files changed, 293 insertions(+) create mode 100644 Koha/Library/OverDriveInfo.pm create mode 100644 Koha/Library/OverDriveInfos.pm create mode 100755 admin/overdrive.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/overdrive.tt create mode 100644 t/db_dependent/Koha/Library/OverDriveInfos.t diff --git a/Koha/Library/OverDriveInfo.pm b/Koha/Library/OverDriveInfo.pm new file mode 100644 index 0000000000..6717699235 --- /dev/null +++ b/Koha/Library/OverDriveInfo.pm @@ -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 index 0000000000..8edc7fb40b --- /dev/null +++ b/Koha/Library/OverDriveInfos.pm @@ -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 index 0000000000..489bf0ad40 --- /dev/null +++ b/admin/overdrive.pl @@ -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 . + +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 index 0000000000..dde99d3f43 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/overdrive.tt @@ -0,0 +1,65 @@ +[% USE Asset %] +[% USE Branches %] +[% USE HtmlTags %] +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › Library OverDrive Info › +[% INCLUDE 'doc-head-close.inc' %] +[% Asset.css("css/datatables.css") %] + + + +[% INCLUDE 'header.inc' %] + + + +
+ +
+
+
+ +
+ +
+ + OverDrive + + + + + + + + [% FOREACH b IN branches %] + + + + + [% END %] + +
BranchAuthname
+ [% Branches.GetName( b.branchcode ) %] + + + +
+ + + +
+
+
+[% INCLUDE 'admin-menu.inc' %] +
+
+ +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/admin-menu.js") %] + [% INCLUDE 'datatables.inc' %] + [% INCLUDE 'columns_settings.inc' %] + +[% 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 index 0000000000..02802a3b6a --- /dev/null +++ b/t/db_dependent/Koha/Library/OverDriveInfos.t @@ -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 . + +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; -- 2.39.5