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 154-160
sub list_rules {
Link Here
|
154 |
group_by => [ 'branchcode', 'categorycode', 'itemtype' ] |
170 |
group_by => [ 'branchcode', 'categorycode', 'itemtype' ] |
155 |
} |
171 |
} |
156 |
)->unblessed; |
172 |
)->unblessed; |
157 |
|
|
|
158 |
} |
173 |
} |
159 |
|
174 |
|
160 |
# Map context into rules |
175 |
# Map context into rules |
Lines 264-267
sub set_rules {
Link Here
|
264 |
} |
279 |
} |
265 |
} |
280 |
} |
266 |
|
281 |
|
|
|
282 |
=head3 _all_kinds |
283 |
|
284 |
Utility function to get a list of all valid rule kinds including those that are repeatable |
285 |
|
286 |
=cut |
287 |
|
288 |
sub _all_kinds { |
289 |
my @all_valid_kinds; |
290 |
my @distinct_kinds = Koha::CirculationRules->search( |
291 |
{}, |
292 |
{ |
293 |
columns => ['rule_name'], |
294 |
distinct => 1, |
295 |
} |
296 |
)->get_column('rule_name'); |
297 |
|
298 |
my %seen; |
299 |
my $valid_kinds = Koha::CirculationRules->rule_kinds; |
300 |
for my $kind (@distinct_kinds) { |
301 |
( my $kind_key = $kind ) =~ s/_\d_/_X_/; |
302 |
if ( exists $valid_kinds->{$kind_key} && !$seen{$kind} ) { |
303 |
push @all_valid_kinds, $kind; |
304 |
$seen{$kind} = 1; |
305 |
} |
306 |
} |
307 |
|
308 |
# Add in any unset but valid rules |
309 |
for my $valid_kind ( keys %{$valid_kinds} ) { |
310 |
if ( $valid_kind !~ /_X_/ && !$seen{$valid_kind} ) { |
311 |
push @all_valid_kinds, $valid_kind; |
312 |
$seen{$valid_kind} = 1; |
313 |
} |
314 |
} |
315 |
return \@all_valid_kinds; |
316 |
} |
317 |
|
267 |
1; |
318 |
1; |
268 |
- |
|
|