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

(-)a/Koha/Template/Plugin/ClassSources.pm (+41 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::ClassSources;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use base qw( Template::Plugin );
21
22
use C4::Context;
23
use Koha::ClassSources;
24
25
sub all {
26
    my ($self, $params) = @_;
27
28
    my $selected = $params->{selected};
29
30
    my $default_source = C4::Context->preference("DefaultClassificationSource");
31
32
    my @class_sources = grep {
33
             $_->used
34
          or ( $selected       and $_->cn_source eq $selected )
35
          or ( $default_source and $_->cn_source eq $default_source )
36
    } Koha::ClassSources->search->as_list;
37
38
    return @class_sources;
39
}
40
41
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc (-5 / +34 lines)
Lines 1-4 Link Here
1
[% USE AuthorisedValues %]
1
[% USE AuthorisedValues %]
2
[% USE Branches %]
3
[% USE ClassSources %]
4
[% USE ItemTypes %]
2
[% IF wrap_fieldset != 0 %]
5
[% IF wrap_fieldset != 0 %]
3
<fieldset class="rows">
6
<fieldset class="rows">
4
    <legend>Additional fields</legend>
7
    <legend>Additional fields</legend>
Lines 15-25 Link Here
15
                        <select name="additional_field_[% field.id | html %]" id="additional_field_[% field.id | html %]">
18
                        <select name="additional_field_[% field.id | html %]" id="additional_field_[% field.id | html %]">
16
                    [% END %]
19
                    [% END %]
17
                        <option value=""></option>
20
                        <option value=""></option>
18
                        [% FOREACH av IN AuthorisedValues.GetAuthValueDropbox( authorised_value_category ) %]
21
                        [% IF authorised_value_category == 'branches' %]
19
                            [% IF av.authorised_value == values.${field.id} %]
22
                            [% FOREACH branch IN Branches.all() %]
20
                                <option value="[% av.authorised_value | html %]" selected="selected">[% av.lib | html %]</option>
23
                                [% IF branch.branchcode == values.${field.id} %]
21
                            [% ELSE %]
24
                                    <option value="[% branch.branchcode | html %]" selected="selected">[% branch.branchname | html %]</option>
22
                                <option value="[% av.authorised_value | html %]">[% av.lib | html %]</option>
25
                                [% ELSE %]
26
                                    <option value="[% branch.branchcode | html %]">[% branch.branchname | html %]</option>
27
                                [% END %]
28
                            [% END %]
29
                        [% ELSIF authorised_value_category == 'cn_source' %]
30
                            [% FOREACH class_source IN ClassSources.all({ selected => values.${field.id} }) %]
31
                                [% IF class_source.cn_source == values.${field.id} %]
32
                                    <option value="[% class_source.cn_source | html %]" selected="selected">[% class_source.description | html %]</option>
33
                                [% ELSE %]
34
                                    <option value="[% class_source.cn_source | html %]">[% class_source.description | html %]</option>
35
                                [% END %]
36
                            [% END %]
37
                        [% ELSIF authorised_value_category == 'itemtypes' %]
38
                            [% FOREACH itemtype IN ItemTypes.Get() %]
39
                                [% IF itemtype.itemtype == values.${field.id} %]
40
                                    <option value="[% itemtype.itemtype | html %]" selected="selected">[% itemtype.description | html %]</option>
41
                                [% ELSE %]
42
                                    <option value="[% itemtype.itemtype | html %]">[% itemtype.description | html %]</option>
43
                                [% END %]
44
                            [% END %]
45
                        [% ELSE %]
46
                            [% FOREACH av IN AuthorisedValues.GetAuthValueDropbox( authorised_value_category ) %]
47
                                [% IF av.authorised_value == values.${field.id} %]
48
                                    <option value="[% av.authorised_value | html %]" selected="selected">[% av.lib | html %]</option>
49
                                [% ELSE %]
50
                                    <option value="[% av.authorised_value | html %]">[% av.lib | html %]</option>
51
                                [% END %]
23
                            [% END %]
52
                            [% END %]
24
                        [% END %]
53
                        [% END %]
25
                    </select> <span>(Authorised values for [% authorised_value_category | html %])</span>
54
                    </select> <span>(Authorised values for [% authorised_value_category | html %])</span>
(-)a/t/db_dependent/Koha/Template/Plugin/ClassSources.t (-1 / +90 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
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, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Test::More tests => 2;
20
21
use t::lib::Mocks;
22
23
BEGIN {
24
    use_ok('Koha::Template::Plugin::ClassSources');
25
}
26
27
my $schema  = Koha::Database->schema;
28
29
subtest 'all' => sub {
30
    plan tests => 4;
31
32
    $schema->storage->txn_begin;
33
    $schema->resultset('ClassSource')->delete();
34
    $schema->resultset('ClassSource')->create({
35
        cn_source => 'anscr',
36
        description => 'ANSCR (Sound Recordings)',
37
        used => 0,
38
        class_sort_rule => 'generic',
39
        class_split_rule => 'generic',
40
    });
41
    $schema->resultset('ClassSource')->create({
42
        cn_source => 'ddc',
43
        description => 'Dewey Decimal Classification',
44
        used => 1,
45
        class_sort_rule => 'dewey',
46
        class_split_rule => 'dewey',
47
    });
48
    $schema->resultset('ClassSource')->create({
49
        cn_source => 'z',
50
        description => 'Other/Generic Classification Scheme',
51
        used => 0,
52
        class_sort_rule => 'generic',
53
        class_split_rule => 'generic',
54
    });
55
56
    t::lib::Mocks::mock_preference('DefaultClassificationSource', '');
57
58
    my $plugin = Koha::Template::Plugin::ClassSources->new();
59
    subtest 'when given no parameters' => sub {
60
        plan tests => 2;
61
        my @class_sources = $plugin->all();
62
63
        is(scalar @class_sources, 1, 'it returns only "used" class sources');
64
        is($class_sources[0]->used, 1, 'it returns only "used" class sources');
65
    };
66
67
    subtest 'when given parameter "selected"' => sub {
68
        plan tests => 1;
69
        my @class_sources = $plugin->all({ selected => 'anscr' });
70
71
        ok(scalar @class_sources == 2, 'it returns "used" class sources and the selected one');
72
    };
73
74
    subtest 'when DefaultClassificationSource is set to a not used class source' => sub {
75
        plan tests => 1;
76
        t::lib::Mocks::mock_preference('DefaultClassificationSource', 'anscr');
77
        my @class_sources = $plugin->all();
78
79
        ok(scalar @class_sources == 2, 'it returns "used" class sources and the default one');
80
    };
81
82
    subtest 'when DefaultClassificationSource is set and "selected" parameter is given' => sub {
83
        plan tests => 1;
84
        t::lib::Mocks::mock_preference('DefaultClassificationSource', 'anscr');
85
        my @class_sources = $plugin->all({ selected => 'z' });
86
        ok(scalar @class_sources == 3, 'it returns "used" class sources, the default one and the selected one');
87
    };
88
89
    $schema->storage->txn_rollback;
90
};

Return to bug 11844