From cf207a07a1104b752b16b89bd6dac50331fb2bc2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 2 Mar 2019 14:14:11 -0300 Subject: [PATCH] Bug 18925: Fix 'Default checkout, hold policy by patron category' block We want ->Search to return undef if the rule does not exist. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- Koha/Template/Plugin/CirculationRules.pm | 20 +++++++++++++++++++ .../prog/en/modules/admin/smart-rules.tt | 11 +++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Koha/Template/Plugin/CirculationRules.pm b/Koha/Template/Plugin/CirculationRules.pm index d6c79c8c00..004ba92736 100644 --- a/Koha/Template/Plugin/CirculationRules.pm +++ b/Koha/Template/Plugin/CirculationRules.pm @@ -42,4 +42,24 @@ sub Get { return $rule->rule_value if $rule; } +sub Search { + my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_; + + $branchcode = undef if $branchcode eq q{}; + $categorycode = undef if $categorycode eq q{}; + $itemtype = undef if $itemtype eq q{}; + + my $rule = Koha::CirculationRules->search( + { + branchcode => $branchcode, + categorycode => $categorycode, + itemtype => $itemtype, + rule_name => $rule_name, + } + )->next; + + return $rule->rule_value if $rule; +} + + 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index b5134fb1d9..e41d59b655 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -533,9 +533,9 @@   [% FOREACH c IN categorycodes %] - [% SET patron_maxissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxissueqty' ) %] - [% SET patron_maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %] - [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %] + [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %] + [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %] + [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %] [% IF patron_maxissueqty || patron_maxonsiteissueqty || max_holds %] @@ -561,9 +561,8 @@ [% END %] - [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode || '*', branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %] - [% IF rule_value.defined && rule_value != '' %] - [% rule_value | html %] + [% IF max_holds.defined && max_holds != '' %] + [% max_holds | html %] [% ELSE %] Unlimited [% END %] -- 2.39.5