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

(-)a/Koha/Template/Plugin/CirculationRules.pm (-2 / +2 lines)
Lines 43-49 sub Get { Link Here
43
}
43
}
44
44
45
sub Search {
45
sub Search {
46
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name, $want_rule) = @_;
46
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name, $params) = @_;
47
47
48
    $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
48
    $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
49
    $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*};
49
    $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*};
Lines 58-64 sub Search { Link Here
58
        }
58
        }
59
    )->next;
59
    )->next;
60
60
61
    return $rule if $want_rule;
61
    return $rule if $params->{want_rule};
62
    return $rule->rule_value if $rule;
62
    return $rule->rule_value if $rule;
63
}
63
}
64
64
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-9 / +9 lines)
Lines 543-558 Link Here
543
                    <th>Return policy</th>
543
                    <th>Return policy</th>
544
                    <th class="noExport">Actions</th>
544
                    <th class="noExport">Actions</th>
545
                </tr>
545
                </tr>
546
                [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty', 1, 1 ) %]
546
                [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty', { want_rule = 1 } ) %]
547
                [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty', 1, 1 ) %]
547
                [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty', { want_rule = 1 } ) %]
548
                [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds', 1, 1 ) %]
548
                [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds', { want_rule = 1 } ) %]
549
                [% SET holdallowed = CirculationRules.Search( current_branch, undef, undef, 'holdallowed', 1 ) %]
549
                [% SET holdallowed = CirculationRules.Search( current_branch, undef, undef, 'holdallowed', { want_rule = 1 } ) %]
550
                [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy', 1 ) %]
550
                [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy', { want_rule = 1 }) %]
551
                [% SET returnbranch = CirculationRules.Search( current_branch, undef, undef, 'returnbranch', 1 ) %]
551
                [% SET returnbranch = CirculationRules.Search( current_branch, undef, undef, 'returnbranch', { want_rule = 1 }) %]
552
                [% SET dcharp = ( patron_maxissueqty || patron_maxonsiteissueqty || rule_value || holdallowed || hold_fulfillment_policy || returnbranch ) %]
552
                [% SET default_checkout_hold_and_return_policy = ( patron_maxissueqty || patron_maxonsiteissueqty || rule_value || holdallowed || hold_fulfillment_policy || returnbranch ) %]
553
                <tr>
553
                <tr>
554
                    <td>
554
                    <td>
555
                        [% IF ( dcharp ) %]
555
                        [% IF ( default_checkout_hold_and_return_policy ) %]
556
                            <em>
556
                            <em>
557
                            Defaults
557
                            Defaults
558
                            </em>
558
                            </em>
Lines 698-704 Link Here
698
                    </td>
698
                    </td>
699
                    <td class="actions">
699
                    <td class="actions">
700
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
700
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
701
                        [% IF (dcharp) %]
701
                        [% IF ( default_checkout_hold_and_return_policy ) %]
702
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=*&amp;branch=[% current_branch | html %]" id="unset"><i class="fa fa-undo"></i> Unset</a>
702
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&amp;categorycode=*&amp;branch=[% current_branch | html %]" id="unset"><i class="fa fa-undo"></i> Unset</a>
703
                        [% END %]
703
                        [% END %]
704
                    </td>
704
                    </td>
(-)a/t/db_dependent/Template/Plugin/CirculationRules.t (-1 / +92 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
use Test::MockModule;
21
22
use Koha::CirculationRules;
23
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
26
27
BEGIN {
28
    use_ok('Koha::Template::Plugin::CirculationRules');
29
}
30
31
my $schema  = Koha::Database->schema;
32
my $builder = t::lib::TestBuilder->new;
33
34
subtest 'Basic function tests' => sub {
35
36
    plan tests => 10;
37
38
    $schema->storage->txn_begin;
39
40
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
41
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
42
43
    my $plugin = Koha::Template::Plugin::CirculationRules->new();
44
    ok($plugin, "initialized CirculationRules plugin");
45
46
    my $rule_value = $plugin->Get($library_1->branchcode,'*','*','maxholds');
47
    is($rule_value, undef, 'Max holds not set, Get returns undef');
48
49
    $rule_value = $plugin->Search($library_1->branchcode,'*','*','maxholds');
50
    is($rule_value, undef, 'Max holds not set, Search returns undef');
51
52
    my $rule = $plugin->Search($library_1->branchcode,'*','*','maxholds', { want_rule => 1 } );
53
    is($rule, undef, 'Max holds not set, Search with want_rule returns undef');
54
55
    Koha::CirculationRules->set_rule(
56
        {
57
            branchcode   => '*',
58
            categorycode => '*',
59
            rule_name    => 'max_holds',
60
            rule_value   => 5,
61
        }
62
    );
63
64
    Koha::CirculationRules->set_rule(
65
        {
66
            branchcode   => $library_1->branchcode,
67
            categorycode => '*',
68
            rule_name    => 'max_holds',
69
            rule_value   => "",
70
        }
71
    );
72
73
    $rule_value = $plugin->Get($library_1->branchcode,'*','*','max_holds');
74
    is($rule_value, "", 'Max holds set to blank string (unlimited), Get returns blank string for branch');
75
76
    $rule = $plugin->Search($library_1->branchcode,'*','*','max_holds', { want_rule => 1 } );
77
    is(ref $rule, "Koha::CirculationRule" , 'Max holds set to blank string, Search with want_rule returns a circulation rules object');
78
    is( $rule->rule_value, "",'Max holds set to blank string (unlimited), returned rule has correct value');
79
80
    $rule_value = $plugin->Get($library_2->branchcode,'*','*','max_holds');
81
    is($rule_value, 5, 'Max holds default set to 5, Get returns 5 for branch with no rule set');
82
83
    $rule_value = $plugin->Search('*','*','*','max_holds');
84
    is($rule_value, 5, 'Search for all libraries max holds rule, Search returns 5');
85
86
    $rule_value = $plugin->Search($library_1->branchcode,'*','*','max_holds');
87
    is($rule_value, "", 'Max holds set to blank string (unlimited), Get returns blank string for branch');
88
89
90
91
    $schema->storage->txn_rollback;
92
};

Return to bug 24154