Bug 17642: Do not explode if no authorised value exist
[koha.git] / Koha / IssuingRules.pm
1 package Koha::IssuingRules;
2
3 # Copyright Vaara-kirjastot 2015
4 # Copyright Koha Development Team 2016
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 3 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use Modern::Perl;
22
23 use Koha::Database;
24
25 use Koha::IssuingRule;
26
27 use base qw(Koha::Objects);
28
29 =head1 NAME
30
31 Koha::IssuingRules - Koha IssuingRule Object set class
32
33 =head1 API
34
35 =head2 Class Methods
36
37 =cut
38
39 sub get_effective_issuing_rule {
40     my ( $self, $params ) = @_;
41
42     my $default      = '*';
43     my $categorycode = $params->{categorycode};
44     my $itemtype     = $params->{itemtype};
45     my $branchcode   = $params->{branchcode};
46
47     my $rule = $self->find($params);
48     return $rule if $rule;
49
50     $rule = $self->find(
51         {
52             categorycode => $categorycode,
53             itemtype     => $default,
54             branchcode   => $branchcode
55         }
56     );
57     return $rule if $rule;
58
59     $rule = $self->find(
60         {
61             categorycode => $default,
62             itemtype     => $itemtype,
63             branchcode   => $branchcode
64         }
65     );
66     return $rule if $rule;
67
68     $rule = $self->find(
69         {
70             categorycode => $default,
71             itemtype     => $default,
72             branchcode   => $branchcode
73         }
74     );
75     return $rule if $rule;
76
77     $rule = $self->find(
78         {
79             categorycode => $categorycode,
80             itemtype     => $itemtype,
81             branchcode   => $default
82         }
83     );
84     return $rule if $rule;
85
86     $rule = $self->find(
87         {
88             categorycode => $categorycode,
89             itemtype     => $default,
90             branchcode   => $default
91         }
92     );
93     return $rule if $rule;
94
95     $rule = $self->find(
96         {
97             categorycode => $default,
98             itemtype     => $itemtype,
99             branchcode   => $default
100         }
101     );
102     return $rule if $rule;
103
104     $rule = $self->find(
105         {
106             categorycode => $default,
107             itemtype     => $default,
108             branchcode   => $default
109         }
110     );
111     return $rule if $rule;
112
113     return;
114 }
115
116 =head3 type
117
118 =cut
119
120 sub _type {
121     return 'Issuingrule';
122 }
123
124 sub object_class {
125     return 'Koha::IssuingRule';
126 }
127
128 1;