Bug 30874: Simplify categories loop construction

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2022-06-01 10:00:37 +02:00 committed by Tomas Cohen Arazi
parent 71611bb146
commit a2330a84e0
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 38 additions and 49 deletions

View file

@ -929,26 +929,32 @@ legend:hover {
<li>
<label for="categorycode_entry" class="required">Category: </label>
<select id="categorycode_entry" name="categorycode">
[% FOREACH typeloo IN typeloop %]
[% FOREACH categoryloo IN typeloo.categoryloop %]
[% IF ( loop.first ) %]
[% IF ( typeloo.typename_C ) %]<optgroup label="Child">[% END %]
[% IF ( typeloo.typename_A ) %]<optgroup label="Adult">[% END %]
[% IF ( typeloo.typename_S ) %]<optgroup label="Staff">[% END %]
[% IF ( typeloo.typename_I ) %]<optgroup label="Organization">[% END %]
[% IF ( typeloo.typename_P ) %]<optgroup label="Professional">[% END %]
[% IF ( typeloo.typename_X ) %]<optgroup label="Statistical">[% END %]
[% FOREACH category_type IN patron_categories.keys %]
[% SWITCH category_type %]
[% CASE 'C' %]
<optgroup label="Child">
[% CASE 'A' %]
<optgroup label="Adult">
[% CASE 'S' %]
<optgroup label="Staff">
[% CASE 'I' %]
<optgroup label="Organization">
[% CASE 'P' %]
<optgroup label="Professional">
[% CASE 'X' %]
<optgroup label="Statistical">
[% CASE %]
<optgroup label="Unknown">
[% END %]
[% IF ( categoryloo.categorycodeselected ) %]
<option value="[% categoryloo.categorycode | html %]" selected="selected" data-pwd-length="[% categoryloo.effective_min_password_length | html %]" data-pwd-strong="[% categoryloo.effective_require_strong_password | html %]" data-typename="[% typeloo.typename | html %]">[% categoryloo.categoryname | html %]</option>
[% FOREACH category IN patron_categories.$category_type %]
[% IF category.categorycode == patron_category.categorycode %]
<option value="[% category.categorycode | html %]" selected="selected" data-pwd-length="[% category.effective_min_password_length | html %]" data-pwd-strong="[% category.effective_require_strong_password | html %]" data-typename="[% category_type | html %]">[% category.description | html %]</option>
[% ELSE %]
<option value="[% categoryloo.categorycode | html %]" data-pwd-length="[% categoryloo.effective_min_password_length | html %]" data-pwd-strong="[% categoryloo.effective_require_strong_password | html %]" data-typename="[% typeloo.typename | html %]">[% categoryloo.categoryname | html %]</option>
<option value="[% category.categorycode | html %]" data-pwd-length="[% category.effective_min_password_length | html %]" data-pwd-strong="[% category.effective_require_strong_password | html %]" data-typename="[% category_type | html %]">[% category.description | html %]</option>
[% END %]
[% END %]
[% IF ( loop.last ) %]
</optgroup>
[% END %]
[% END # /FOREACH categoryloo %]
[% END # /FOREACH typeloo %]
</select>
<span class="required">Required</span>
</li>

View file

@ -667,39 +667,21 @@ 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->{can_be_guarantee} = 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 ) {
$categorycode = $patron_category->categorycode unless defined($categorycode); #If none passed in, select the first
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' =>
( $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 $patron_categories = Koha::Patron::Categories->search_with_library_limits(
{
category_type => [qw(C A S P I X)],
( $guarantor_id ? ( can_be_guarantee => 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,
);
@ -761,6 +743,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);