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 365-371 sub set_rule { Link Here
365
          unless exists $params->{$mandatory_parameter};
381
          unless exists $params->{$mandatory_parameter};
366
    }
382
    }
367
383
368
    my $kind_info = $RULE_KINDS->{ $params->{rule_name} };
384
    ( my $rule_key = $params->{rule_name} ) =~ s/_\d_/_X_/;
385
    my $kind_info = $RULE_KINDS->{$rule_key};
369
    Koha::Exceptions::MissingParameter->throw(
386
    Koha::Exceptions::MissingParameter->throw(
370
        "set_rule given unknown rule '$params->{rule_name}'!")
387
        "set_rule given unknown rule '$params->{rule_name}'!")
371
        unless defined $kind_info;
388
        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 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
- 

Return to bug 10190