Lines 40-59
sub get_kinds {
Link Here
|
40 |
); |
40 |
); |
41 |
} |
41 |
} |
42 |
|
42 |
|
43 |
=head3 list_effective_rules |
43 |
=head3 list_rules |
44 |
|
44 |
|
45 |
List all effective rules for the requested patron/item/branch combination |
45 |
Get effective rules for the requested patron/item/branch combination |
46 |
|
46 |
|
47 |
=cut |
47 |
=cut |
48 |
|
48 |
|
49 |
sub list_effective_rules { |
49 |
sub list_rules { |
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 $item_type = $c->param('item_type_id'); |
54 |
my $item_type = $c->param('item_type_id'); |
54 |
my $branchcode = $c->param('library_id'); |
55 |
my $branchcode = $c->param('library_id'); |
55 |
my $patron_category = $c->param('patron_category_id'); |
56 |
my $patron_category = $c->param('patron_category_id'); |
56 |
my $rules = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; |
57 |
my $kinds = $c->param('rules') // [ keys %{ Koha::CirculationRules->rule_kinds } ]; |
57 |
|
58 |
|
58 |
if ($item_type) { |
59 |
if ($item_type) { |
59 |
my $type = Koha::ItemTypes->find($item_type); |
60 |
my $type = Koha::ItemTypes->find($item_type); |
Lines 94-111
sub list_effective_rules {
Link Here
|
94 |
) unless $category; |
95 |
) unless $category; |
95 |
} |
96 |
} |
96 |
|
97 |
|
97 |
my $effective_rules = Koha::CirculationRules->get_effective_rules( |
98 |
my $rules; |
98 |
{ |
99 |
if ($effective) { |
99 |
categorycode => $patron_category, |
100 |
|
100 |
itemtype => $item_type, |
101 |
my $effective_rules = Koha::CirculationRules->get_effective_rules( |
101 |
branchcode => $branchcode, |
102 |
{ |
102 |
rules => $rules |
103 |
categorycode => $patron_category, |
|
|
104 |
itemtype => $item_type, |
105 |
branchcode => $branchcode, |
106 |
rules => $kinds |
107 |
} |
108 |
) // {}; |
109 |
push @{$rules}, $effective_rules; |
110 |
} else { |
111 |
my $select = [ 'branchcode', 'categorycode', 'itemtype' ]; |
112 |
my $as = [ 'branchcode', 'categorycode', 'itemtype' ]; |
113 |
for my $kind ( @{$kinds} ) { |
114 |
push @{$select}, { max => \[ "CASE WHEN rule_name = ? THEN rule_value END", $kind ], -as => $kind }; |
115 |
push @{$as}, $kind; |
103 |
} |
116 |
} |
104 |
); |
117 |
|
|
|
118 |
$rules = Koha::CirculationRules->search( |
119 |
{}, |
120 |
{ |
121 |
select => $select, |
122 |
as => $as, |
123 |
group_by => [ 'branchcode', 'categorycode', 'itemtype' ] |
124 |
} |
125 |
)->unblessed; |
126 |
|
127 |
} |
105 |
|
128 |
|
106 |
return $c->render( |
129 |
return $c->render( |
107 |
status => 200, |
130 |
status => 200, |
108 |
openapi => $effective_rules ? $effective_rules : {} |
131 |
openapi => $rules |
109 |
); |
132 |
); |
110 |
} catch { |
133 |
} catch { |
111 |
$c->unhandled_exception($_); |
134 |
$c->unhandled_exception($_); |