View | Details | Raw Unified | Return to bug 10190
Collapse All | Expand All

(-)a/Koha/CirculationRules.pm (-1 / +18 lines)
Lines 169-174 our $RULE_KINDS = { Link Here
169
        is_monetary  => 1,
169
        is_monetary  => 1,
170
        can_be_blank => 1,
170
        can_be_blank => 1,
171
    },
171
    },
172
    overdue_X_delay => {
173
        scope        => [ 'branchcode', 'categorycode', 'itemtype' ],
174
        can_be_blank => 0,
175
    },
176
        overdue_X_mtt => {
177
        scope        => [ 'branchcode', 'categorycode', 'itemtype' ],
178
        can_be_blank => 1,
179
    },
180
        overdue_X_notice => {
181
        scope        => [ 'branchcode', 'categorycode', 'itemtype' ],
182
        can_be_blank => 1,
183
    },
184
        overdue_X_restrict => {
185
        scope        => [ 'branchcode', 'categorycode', 'itemtype' ],
186
        can_be_blank => 0,
187
    },
172
    renewalperiod => {
188
    renewalperiod => {
173
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
189
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
174
    },
190
    },
Lines 371-377 sub set_rule { Link Here
371
          unless exists $params->{$mandatory_parameter};
387
          unless exists $params->{$mandatory_parameter};
372
    }
388
    }
373
389
374
    my $kind_info = $RULE_KINDS->{ $params->{rule_name} };
390
    ( my $rule_key = $params->{rule_name} ) =~ s/_\d_/_X_/;
391
    my $kind_info = $RULE_KINDS->{$rule_key};
375
    Koha::Exceptions::MissingParameter->throw(
392
    Koha::Exceptions::MissingParameter->throw(
376
        "set_rule given unknown rule '$params->{rule_name}'!")
393
        "set_rule given unknown rule '$params->{rule_name}'!")
377
        unless defined $kind_info;
394
        unless defined $kind_info;
(-)a/Koha/REST/V1/CirculationRules.pm (-8 / +58 lines)
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
- 

Return to bug 10190