View | Details | Raw Unified | Return to bug 21082
Collapse All | Expand All

(-)a/Koha/Library/OverDriveInfo.pm (+44 lines)
Line 0 Link Here
1
package Koha::Library::OverDriveInfo;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Library::OverDriveInfo - Koha Library OverDrive Info Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 _type
37
38
=cut
39
40
sub _type {
41
    return 'BranchesOverdrive';
42
}
43
44
1;
(-)a/Koha/Library/OverDriveInfos.pm (+54 lines)
Line 0 Link Here
1
package Koha::Library::OverDriveInfos;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::Library::OverDriveInfo;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Library::OverDriveInfos - Koha Library OverDrive info Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
=head3 object_class
43
44
=cut
45
46
sub _type {
47
    return 'BranchesOverdrive';
48
}
49
50
sub object_class {
51
    return 'Koha::Library::OverDriveInfo';
52
}
53
54
1;
(-)a/admin/overdrive.pl (+75 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright Koha Development Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
22
use C4::Auth;
23
use C4::Context;
24
use C4::Output;
25
26
use Koha::Libraries;
27
use Koha::Library::OverDriveInfos;
28
29
my $input         = CGI->new;
30
my @branchcodes   = $input->multi_param('branchcode');
31
my @authnames     = $input->multi_param('authname');
32
my $op            = $input->param('op');
33
my @messages;
34
35
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {   template_name   => 'admin/overdrive.tt',
37
        query           => $input,
38
        type            => 'intranet',
39
        authnotrequired => 0,
40
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
41
    }
42
);
43
44
if ( $op && $op eq 'update' ) {
45
    my %od_info;
46
    @od_info{ @branchcodes } = @authnames;
47
    while( my($branchcode,$authname) = each %od_info){
48
        my $cur_info = Koha::Library::OverDriveInfos->find($branchcode);
49
        if( $cur_info ) {
50
            $cur_info->authname($authname)->store;
51
        } else {
52
            Koha::Library::OverDriveInfo->new({
53
                branchcode => $branchcode,
54
                authname   => $authname,
55
            })->store;
56
        }
57
    }
58
}
59
60
my @branches = Koha::Libraries->search();
61
my @branch_od_info;
62
foreach my $branch ( @branches ){
63
    my $od_info =  Koha::Library::OverDriveInfos->find($branch->branchcode);
64
    if( $od_info ){
65
        push @branch_od_info, { branchcode => $od_info->branchcode, authname => $od_info->authname };
66
    } else {
67
        push @branch_od_info, { branchcode => $branch->branchcode, authname => "" };
68
    }
69
}
70
71
$template->param(
72
    branches => \@branch_od_info,
73
);
74
75
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/overdrive.tt (+65 lines)
Line 0 Link Here
1
[% USE Asset %]
2
[% USE Branches %]
3
[% USE HtmlTags %]
4
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Administration &rsaquo; Library OverDrive Info &rsaquo;</title>
7
[% INCLUDE 'doc-head-close.inc' %]
8
[% Asset.css("css/datatables.css") %]
9
</head>
10
11
<body id="admin_overdrive" class="admin">
12
[% INCLUDE 'header.inc' %]
13
14
<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;
15
</div>
16
17
<div id="doc3" class="yui-t2">
18
19
<div id="bd">
20
    <div id="yui-main">
21
    <div class="yui-b">
22
23
<form action="/cgi-bin/koha/admin/overdrive.pl" name="overdrive_form" method="post" class="validated">
24
    <input type="hidden" name="op" value="update" />
25
    <fieldset class="rows">
26
        <legend>
27
            OverDrive
28
        </legend>
29
        <table id="od_info">
30
            <thead>
31
                <th>Branch</th>
32
                <th>Authname</th>
33
            </thead>
34
            <tbody>
35
                [% FOREACH b IN branches %]
36
                <tr>
37
                <td>
38
                    [% Branches.GetName( b.branchcode ) %]
39
                    <input type="hidden" name="branchcode" value="[% b.branchcode %]" />
40
                </td>
41
                <td>
42
                    <input type="text" name="authname" value="[% b.authname %]" />
43
                </td>
44
                </tr>
45
                [% END %]
46
            </tbody>
47
        </table>
48
        <input type="submit" value="Submit">
49
</form>
50
51
</div>
52
</div>
53
<div class="yui-b">
54
[% INCLUDE 'admin-menu.inc' %]
55
</div>
56
</div>
57
58
[% MACRO jsinclude BLOCK %]
59
    [% Asset.js("js/admin-menu.js") %]
60
    [% INCLUDE 'datatables.inc' %]
61
    [% INCLUDE 'columns_settings.inc' %]
62
    <script type="text/javascript">
63
    </script>
64
[% END %]
65
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/t/db_dependent/Koha/Library/OverDriveInfos.t (-1 / +55 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2018 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 4;
23
24
use Koha::Library::OverDriveInfos;
25
use Koha::Database;
26
27
use t::lib::TestBuilder;
28
29
my $schema = Koha::Database->new->schema;
30
$schema->storage->txn_begin;
31
32
my $builder = t::lib::TestBuilder->new;
33
my $library1 = $builder->build({ source => 'Branch'});
34
my $library2 = $builder->build({ source => 'Branch'});
35
my $nb_of_infos = Koha::Library::OverDriveInfos->search->count;
36
my $new_od_info_1 = Koha::Library::OverDriveInfo->new({
37
    branchcode => $library1->{'branchcode'},
38
    authname => 'Gorilla'
39
})->store;
40
my $new_od_info_2 = Koha::Library::OverDriveInfo->new({
41
    branchcode => $library2->{'branchcode'},
42
    authname => 'Cheese'
43
})->store;
44
45
46
is( $new_od_info_1->authname, "Gorilla", 'Adding a new authname should have set the authname');
47
is( Koha::Library::OverDriveInfos->search->count, $nb_of_infos + 2, 'The 2 infos should have been added' );
48
49
my $retrieved_od_info_1 = Koha::Library::OverDriveInfos->find( $new_od_info_1->branchcode );
50
is( $retrieved_od_info_1->authname, $new_od_info_1->authname, 'Find an info  by branch should return the correct info' );
51
52
$retrieved_od_info_1->delete;
53
is( Koha::Library::OverDriveInfos->search->count, $nb_of_infos + 1, 'Delete should have deleted the info' );
54
55
$schema->storage->txn_rollback;

Return to bug 21082