@@ -, +, @@ --- 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 --- a/Koha/Library/OverDriveInfo.pm +++ a/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; --- a/Koha/Library/OverDriveInfos.pm +++ a/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; --- a/admin/overdrive.pl +++ a/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; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/overdrive.tt +++ a/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' %] --- a/t/db_dependent/Koha/Library/OverDriveInfos.t +++ a/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; --