Bug 18282: operationId must be unique
[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 $search_categorycode = $default;
48     my $search_itemtype     = $default;
49     my $search_branchcode   = $default;
50
51     if ($categorycode) {
52         $search_categorycode = { 'in' => [ $categorycode, $default ] };
53     }
54     if ($itemtype) {
55         $search_itemtype = { 'in' => [ $itemtype, $default ] };
56     }
57     if ($branchcode) {
58         $search_branchcode = { 'in' => [ $branchcode, $default ] };
59     }
60
61     my $rule = $self->search({
62         categorycode => $search_categorycode,
63         itemtype     => $search_itemtype,
64         branchcode   => $search_branchcode,
65     }, {
66         order_by => {
67             -desc => ['branchcode', 'categorycode', 'itemtype']
68         },
69         rows => 1,
70     })->single;
71     return $rule;
72 }
73
74 =head3 type
75
76 =cut
77
78 sub _type {
79     return 'Issuingrule';
80 }
81
82 sub object_class {
83     return 'Koha::IssuingRule';
84 }
85
86 1;