Browse Source

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 <sandy.allgood@citruslibraries.org>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
18.11.x
Nick Clemens 6 years ago
parent
commit
df339d0372
  1. 44
      Koha/Library/OverDriveInfo.pm
  2. 54
      Koha/Library/OverDriveInfos.pm
  3. 75
      admin/overdrive.pl
  4. 65
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/overdrive.tt
  5. 55
      t/db_dependent/Koha/Library/OverDriveInfos.t

44
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;

54
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;

75
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 <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;

65
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' %]
<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' %]

55
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 <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;
Loading…
Cancel
Save