From 200655d57791a919dd45e4ffbe34ce06cc2c29c0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 1 Jun 2022 10:00:37 +0200 Subject: [PATCH] Bug 30874: Simplify categories loop construction --- .../prog/en/modules/members/memberentrygen.tt | 42 +++++++++-------- members/memberentry.pl | 45 +++++++------------ 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 78bee54ae19..55446fba3fe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -914,26 +914,32 @@ legend:hover {
  • Required
  • diff --git a/members/memberentry.pl b/members/memberentry.pl index b8219370680..dbe0a170a90 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -668,37 +668,23 @@ if(!defined($data{'sex'})){ ##Now all the data to modify a member. my @typeloop; -my $no_categories = 1; -my $no_add; -foreach my $category_type (qw(C A S P I X)) { - my $categories_limits = { category_type => $category_type }; - $categories_limits->{canbeguarantee} = 1 if ($guarantor_id); - my $patron_categories = Koha::Patron::Categories->search_with_library_limits( $categories_limits, {order_by => ['categorycode']} ); - $no_categories = 0 if $patron_categories->count > 0; - - my @categoryloop; - while ( my $patron_category = $patron_categories->next ) { - push @categoryloop, - { 'categorycode' => $patron_category->categorycode, - 'categoryname' => $patron_category->description, - 'effective_min_password_length' => $patron_category->effective_min_password_length, - 'effective_require_strong_password' => $patron_category->effective_require_strong_password, - 'categorycodeselected' => - ( defined($categorycode) && $patron_category->categorycode eq $categorycode ), - }; - } - my %typehash; - $typehash{'typename'} = $category_type; - my $typedescription = "typename_" . $typehash{'typename'}; - $typehash{'categoryloop'} = \@categoryloop; - push @typeloop, - { 'typename' => $category_type, - $typedescription => 1, - 'categoryloop' => \@categoryloop - }; +my $categories_limits = { category_type => [qw(C A S P I X) ] }; +$categories_limits->{canbeguarantee} = 1 if ($guarantor_id); +my $patron_categories = Koha::Patron::Categories->search_with_library_limits( + { + category_type => [qw(C A S P I X)], + ( $guarantor_id ? ( canbeguarantee => 1 ) : () ) + }, + { order_by => ['categorycode'] } +); +my $no_categories = ! $patron_categories->count; +my $categories = {}; +foreach my $patron_category ($patron_categories->as_list ) { + push @{ $categories->{ $patron_category->category_type } }, $patron_category; } + $template->param( - typeloop => \@typeloop, + patron_categories => $categories, no_categories => $no_categories, ); @@ -760,6 +746,7 @@ if (defined ($data{'branchcode'}) and ( $op eq 'modify' || $op eq 'duplicate' || } $template->param( userbranch => $userbranch ); +my $no_add; if ( Koha::Libraries->search->count < 1 ){ $no_add = 1; $template->param(no_branches => 1); -- 2.25.1