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> <li>
<label for="categorycode_entry" class="required">Category: </label> <label for="categorycode_entry" class="required">Category: </label>
<select id="categorycode_entry" name="categorycode"> <select id="categorycode_entry" name="categorycode">
[% FOREACH typeloo IN typeloop %] [% FOREACH category_type IN patron_categories.keys %]
[% FOREACH categoryloo IN typeloo.categoryloop %] [% SWITCH category_type %]
[% IF ( loop.first ) %] [% CASE 'C' %]
[% IF ( typeloo.typename_C ) %]<optgroup label="Child">[% END %] <optgroup label="Child">
[% IF ( typeloo.typename_A ) %]<optgroup label="Adult">[% END %] [% CASE 'A' %]
[% IF ( typeloo.typename_S ) %]<optgroup label="Staff">[% END %] <optgroup label="Adult">
[% IF ( typeloo.typename_I ) %]<optgroup label="Organization">[% END %] [% CASE 'S' %]
[% IF ( typeloo.typename_P ) %]<optgroup label="Professional">[% END %] <optgroup label="Staff">
[% IF ( typeloo.typename_X ) %]<optgroup label="Statistical">[% END %] [% CASE 'I' %]
<optgroup label="Organization">
[% CASE 'P' %]
<optgroup label="Professional">
[% CASE 'X' %]
<optgroup label="Statistical">
[% CASE %]
<optgroup label="Unknown">
[% END %] [% END %]
[% IF ( categoryloo.categorycodeselected ) %] [% FOREACH category IN patron_categories.$category_type %]
<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> [% 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 %] [% 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 %] [% END %]
[% IF ( loop.last ) %]
</optgroup> </optgroup>
[% END %] [% END %]
[% END # /FOREACH categoryloo %]
[% END # /FOREACH typeloo %]
</select> </select>
<span class="required">Required</span> <span class="required">Required</span>
</li> </li>

View file

@ -667,39 +667,21 @@ if(!defined($data{'sex'})){
##Now all the data to modify a member. ##Now all the data to modify a member.
my @typeloop; my $patron_categories = Koha::Patron::Categories->search_with_library_limits(
my $no_categories = 1; {
my $no_add; category_type => [qw(C A S P I X)],
foreach my $category_type (qw(C A S P I X)) { ( $guarantor_id ? ( can_be_guarantee => 1 ) : () )
my $categories_limits = { category_type => $category_type }; },
$categories_limits->{can_be_guarantee} = 1 if ($guarantor_id); { order_by => ['categorycode'] }
my $patron_categories = Koha::Patron::Categories->search_with_library_limits( $categories_limits, {order_by => ['categorycode']} ); );
$no_categories = 0 if $patron_categories->count > 0; my $no_categories = ! $patron_categories->count;
my $categories = {};
my @categoryloop; foreach my $patron_category ($patron_categories->as_list ) {
while ( my $patron_category = $patron_categories->next ) { push @{ $categories->{ $patron_category->category_type } }, $patron_category;
$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
};
} }
$template->param( $template->param(
typeloop => \@typeloop, patron_categories => $categories,
no_categories => $no_categories, no_categories => $no_categories,
); );
@ -761,6 +743,7 @@ if (defined ($data{'branchcode'}) and ( $op eq 'modify' || $op eq 'duplicate' ||
} }
$template->param( userbranch => $userbranch ); $template->param( userbranch => $userbranch );
my $no_add;
if ( Koha::Libraries->search->count < 1 ){ if ( Koha::Libraries->search->count < 1 ){
$no_add = 1; $no_add = 1;
$template->param(no_branches => 1); $template->param(no_branches => 1);