1 package Koha
::CirculationRules
;
3 # Copyright Vaara-kirjastot 2015
4 # Copyright Koha Development Team 2016
6 # This file is part of Koha.
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
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.
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.
24 use Koha
::CirculationRule
;
26 use base
qw(Koha::Objects);
30 Koha::CirculationRules - Koha CirculationRule Object set class
38 =head3 get_effective_rule
42 sub get_effective_rule
{
43 my ( $self, $params ) = @_;
45 my $rule_name = $params->{rule_name
};
46 my $categorycode = $params->{categorycode
};
47 my $itemtype = $params->{itemtype
};
48 my $branchcode = $params->{branchcode
};
50 Koha
::Exceptions
::MissingParameter
->throw(
51 "Required parameter 'rule_name' missing")
54 for my $v ( $branchcode, $categorycode, $itemtype ) {
55 $v = undef if $v and $v eq '*';
59 $search_params->{rule_name
} = $rule_name;
61 $search_params->{categorycode
} = defined $categorycode ?
[ $categorycode, undef ] : undef;
62 $search_params->{itemtype
} = defined $itemtype ?
[ $itemtype, undef ] : undef;
63 $search_params->{branchcode
} = defined $branchcode ?
[ $branchcode, undef ] : undef;
65 my $rule = $self->search(
69 -desc
=> [ 'branchcode', 'categorycode', 'itemtype' ]
83 my ( $self, $params ) = @_;
85 for my $mandatory_parameter (qw( branchcode categorycode itemtype rule_name rule_value ) ){
86 Koha
::Exceptions
::MissingParameter
->throw(
87 "Required parameter 'branchcode' missing")
88 unless exists $params->{$mandatory_parameter};
91 my $branchcode = $params->{branchcode
};
92 my $categorycode = $params->{categorycode
};
93 my $itemtype = $params->{itemtype
};
94 my $rule_name = $params->{rule_name
};
95 my $rule_value = $params->{rule_value
};
97 for my $v ( $branchcode, $categorycode, $itemtype ) {
98 $v = undef if $v and $v eq '*';
100 my $rule = $self->search(
102 rule_name
=> $rule_name,
103 branchcode
=> $branchcode,
104 categorycode
=> $categorycode,
105 itemtype
=> $itemtype,
110 if ( defined $rule_value ) {
111 $rule->rule_value($rule_value);
119 if ( defined $rule_value ) {
120 $rule = Koha
::CirculationRule
->new(
122 branchcode
=> $branchcode,
123 categorycode
=> $categorycode,
124 itemtype
=> $itemtype,
125 rule_name
=> $rule_name,
126 rule_value
=> $rule_value,
141 my ( $self, $params ) = @_;
143 my $branchcode = $params->{branchcode
};
144 my $categorycode = $params->{categorycode
};
145 my $itemtype = $params->{itemtype
};
146 my $rules = $params->{rules
};
148 my $rule_objects = [];
149 while ( my ( $rule_name, $rule_value ) = each %$rules ) {
150 my $rule_object = Koha
::CirculationRules
->set_rule(
152 branchcode
=> $branchcode,
153 categorycode
=> $categorycode,
154 itemtype
=> $itemtype,
155 rule_name
=> $rule_name,
156 rule_value
=> $rule_value,
159 push( @
$rule_objects, $rule_object );
162 return $rule_objects;
167 Delete a set of circulation rules, needed for cleaning up when deleting issuingrules
174 while ( my $rule = $self->next ){
185 return 'CirculationRule';
193 return 'Koha::CirculationRule';