Bug 24026: (bug 22847 follow-up) Remove c/p issues
[koha.git] / Koha / Template / Plugin / CirculationRules.pm
1 package Koha::Template::Plugin::CirculationRules;
2
3 # Copyright ByWater Solutions 2017
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 base qw( Template::Plugin );
23
24 use Koha::CirculationRules;
25
26 sub Get {
27     my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
28
29     $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
30     $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*};
31     $itemtype     = undef if $itemtype eq q{}     or $itemtype  eq q{*};
32
33     my $rule = Koha::CirculationRules->get_effective_rule(
34         {
35             branchcode   => $branchcode,
36             categorycode => $categorycode,
37             itemtype     => $itemtype,
38             rule_name    => $rule_name,
39         }
40     );
41
42     return $rule->rule_value if $rule;
43 }
44
45 sub Search {
46     my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
47
48     $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
49     $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*};
50     $itemtype     = undef if $itemtype eq q{}     or $itemtype eq q{*};
51
52     my $rule = Koha::CirculationRules->search(
53         {
54             branchcode   => $branchcode,
55             categorycode => $categorycode,
56             itemtype     => $itemtype,
57             rule_name    => $rule_name,
58         }
59     )->next;
60
61     return $rule->rule_value if $rule;
62 }
63
64
65 1;