Lines 50-60
sub list_rules {
Link Here
|
50 |
my $c = shift->openapi->valid_input or return; |
50 |
my $c = shift->openapi->valid_input or return; |
51 |
|
51 |
|
52 |
return try { |
52 |
return try { |
53 |
my $effective = $c->param('effective') // 1; |
53 |
my $effective = $c->param('effective') // 1; |
54 |
my $kinds = |
|
|
55 |
defined( $c->param('rules') ) |
56 |
? [ split /\s*,\s*/, $c->param('rules') ] |
57 |
: [ keys %{ Koha::CirculationRules->rule_kinds } ]; |
58 |
my $item_type = $c->param('item_type_id'); |
54 |
my $item_type = $c->param('item_type_id'); |
59 |
my $branchcode = $c->param('library_id'); |
55 |
my $branchcode = $c->param('library_id'); |
60 |
my $patron_category = $c->param('patron_category_id'); |
56 |
my $patron_category = $c->param('patron_category_id'); |
Lines 114-119
sub list_rules {
Link Here
|
114 |
} |
110 |
} |
115 |
} |
111 |
} |
116 |
|
112 |
|
|
|
113 |
my $kinds; |
114 |
if ( defined( $c->param('rules') ) ) { |
115 |
$kinds = [ split /\s*,\s*/, $c->param('rules') ]; |
116 |
my $valid_kinds = Koha::CirculationRules->rule_kinds; |
117 |
for my $rule ( @{$kinds} ) { |
118 |
( my $rule_key = $rule ) =~ s/_\d_/_X_/; |
119 |
return $c->render_invalid_parameter_value( |
120 |
{ |
121 |
path => '/query/rules', |
122 |
values => { |
123 |
uri => '/api/v1/kinds', |
124 |
field => 'rule_name' |
125 |
} |
126 |
} |
127 |
) unless $valid_kinds->{$rule_key}; |
128 |
} |
129 |
} else { |
130 |
$kinds = _all_kinds(); |
131 |
} |
132 |
|
117 |
my $rules; |
133 |
my $rules; |
118 |
if ($effective) { |
134 |
if ($effective) { |
119 |
|
135 |
|
Lines 125-131
sub list_rules {
Link Here
|
125 |
rules => $kinds |
141 |
rules => $kinds |
126 |
} |
142 |
} |
127 |
) // {}; |
143 |
) // {}; |
128 |
my $return; |
144 |
my $return = {}; |
129 |
for my $kind ( @{$kinds} ) { |
145 |
for my $kind ( @{$kinds} ) { |
130 |
$return->{$kind} = $effective_rules->{$kind}; |
146 |
$return->{$kind} = $effective_rules->{$kind}; |
131 |
} |
147 |
} |
Lines 155-161
sub list_rules {
Link Here
|
155 |
order_by => [ 'branchcode', 'categorycode', 'itemtype' ], |
171 |
order_by => [ 'branchcode', 'categorycode', 'itemtype' ], |
156 |
} |
172 |
} |
157 |
)->unblessed; |
173 |
)->unblessed; |
158 |
|
|
|
159 |
} |
174 |
} |
160 |
|
175 |
|
161 |
# Map context into rules |
176 |
# Map context into rules |
Lines 265-268
sub set_rules {
Link Here
|
265 |
} |
280 |
} |
266 |
} |
281 |
} |
267 |
|
282 |
|
|
|
283 |
=head3 _all_kinds |
284 |
|
285 |
Utility function to get a list of all valid rule kinds including those that are repeatable |
286 |
|
287 |
=cut |
288 |
|
289 |
sub _all_kinds { |
290 |
my @all_valid_kinds; |
291 |
my @distinct_kinds = Koha::CirculationRules->search( |
292 |
{}, |
293 |
{ |
294 |
columns => ['rule_name'], |
295 |
distinct => 1, |
296 |
} |
297 |
)->get_column('rule_name'); |
298 |
|
299 |
my %seen; |
300 |
my $valid_kinds = Koha::CirculationRules->rule_kinds; |
301 |
for my $kind (@distinct_kinds) { |
302 |
( my $kind_key = $kind ) =~ s/_\d_/_X_/; |
303 |
if ( exists $valid_kinds->{$kind_key} && !$seen{$kind} ) { |
304 |
push @all_valid_kinds, $kind; |
305 |
$seen{$kind} = 1; |
306 |
} |
307 |
} |
308 |
|
309 |
# Add in any unset but valid rules |
310 |
for my $valid_kind ( keys %{$valid_kinds} ) { |
311 |
if ( $valid_kind !~ /_X_/ && !$seen{$valid_kind} ) { |
312 |
push @all_valid_kinds, $valid_kind; |
313 |
$seen{$valid_kind} = 1; |
314 |
} |
315 |
} |
316 |
return \@all_valid_kinds; |
317 |
} |
318 |
|
268 |
1; |
319 |
1; |
269 |
- |
|
|