From 3e9a94c546bb1907ab38351afddc53f3d8d85b12 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 20 Jun 2008 08:11:15 -0500 Subject: [PATCH] bug 2000 - alternate issuing rules - set sorting of rules Issuing rules are now explicitly sorted by patron category, then item type. The default patron category sorts last; within a list of item types for a given patron category, the default item type sorts last. This follows the order in which the issuing rules are applied. Since the primary sort is patron category, also moved that to be the first column in the issuing rules table. Signed-off-by: Joshua Ferraro --- admin/smart-rules.pl | 37 ++++++++++++++++++- .../prog/en/modules/admin/smart-rules.tmpl | 32 +++++++++------- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index bc9f9a756f..2b6a1bec06 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -125,11 +125,46 @@ while (my $row = $sth2->fetchrow_hashref) { push @row_loop, $row; } $sth->finish; + +my @sorted_row_loop = sort by_category_and_itemtype @row_loop; + $template->param(categoryloop => \@category_loop, itemtypeloop => \@itemtypes, - rules => \@row_loop, + rules => \@sorted_row_loop, branchloop => \@branchloop, humanbranch => ($branch ne '*' ? $branches->{$branch}->{branchname} : ''), branch => $branch ); output_html_with_http_headers $input, $cookie, $template->output; + +exit 0; + +# sort by patron category, then item type, putting +# default entries at the bottom +sub by_category_and_itemtype { + unless (by_category($a, $b)) { + return by_itemtype($a, $b); + } +} + +sub by_category { + my ($a, $b) = @_; + if ($a->{'default_humancategorycode'}) { + return ($b->{'default_humancategorycode'} ? 0 : 1); + } elsif ($b->{'default_humancategorycode'}) { + return -1; + } else { + return $a->{'humancategorycode'} cmp $b->{'humancategorycode'}; + } +} + +sub by_itemtype { + my ($a, $b) = @_; + if ($a->{'default_humanitemtype'}) { + return ($b->{'default_humanitemtype'} ? 0 : 1); + } elsif ($b->{'default_humanitemtype'}) { + return -1; + } else { + return $a->{'humanitemtype'} cmp $b->{'humanitemtype'}; + } +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl index a00c16ecab..4bc47cbb41 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl @@ -59,20 +59,26 @@ $(document).ready(function() { - + + + + + + + - - @@ -87,18 +93,18 @@ $(document).ready(function() { -- 2.39.5
Item TypePatron CategoryAmountGrace
Period
Charging
Interval
Amount
Loanable
Loan time Patron CategoryItem TypeAmountGrace PeriodCharging IntervalAmoun LoanableLoan time 
+ Any - + + Any - + $
- + + + - + + +