From 3fe72285e97596cffe862a5ed3bcb5e845709748 Mon Sep 17 00:00:00 2001 From: Ayoub Glizi-Vicioso Date: Tue, 3 Feb 2026 17:44:39 -0500 Subject: [PATCH] Bug 35145: Fix patron attribute type ordering --- Koha/Patron/Attribute/Types.pm | 11 +++++------ admin/patron-attr-types.pl | 10 +++++++++- .../prog/en/includes/member-attribute-types.inc | 1 + members/memberentry.pl | 2 ++ opac/opac-memberentry.pl | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Koha/Patron/Attribute/Types.pm b/Koha/Patron/Attribute/Types.pm index dd0eb93e36..4a677db0d2 100644 --- a/Koha/Patron/Attribute/Types.pm +++ b/Koha/Patron/Attribute/Types.pm @@ -50,11 +50,10 @@ sub patron_attributes_form { my $template = shift; my $attributes = shift; my $op = shift; - my $query = shift // {}; my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; - my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( $query, {}, $library_id ); - if ( $attribute_types->count == 0 ) { + my @attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, { order_by => \'display_order IS NULL, display_order ASC , code ASC' }, $library_id) -> as_list(); + if ( !@attribute_types ) { $template->param( no_patron_attribute_types => 1 ); return; } @@ -68,7 +67,7 @@ sub patron_attributes_form { my @attribute_loop = (); my $i = 0; my %items_by_class; - while ( my ($attr_type) = $attribute_types->next ) { + for my $attr_type (@attribute_types) { my $entry = { class => $attr_type->class(), code => $attr_type->code(), @@ -87,7 +86,7 @@ sub patron_attributes_form { if ( $attr_type->authorised_value_category() ) { $newentry->{use_dropdown} = 1; $newentry->{auth_val_loop} = - C4::Koha::GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} ); + GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} ); } $i++; undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' ); @@ -99,7 +98,7 @@ sub patron_attributes_form { my $newentry = {%$entry}; if ( $attr_type->authorised_value_category() ) { $newentry->{use_dropdown} = 1; - $newentry->{auth_val_loop} = C4::Koha::GetAuthorisedValues( $attr_type->authorised_value_category() ); + $newentry->{auth_val_loop} = GetAuthorisedValues( $attr_type->authorised_value_category() ); } $newentry->{form_id} = "patron_attr_$i"; push @{ $items_by_class{ $attr_type->class() } }, $newentry; diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl index 9e2734d258..520f2dca59 100755 --- a/admin/patron-attr-types.pl +++ b/admin/patron-attr-types.pl @@ -258,7 +258,6 @@ sub patron_attribute_type_list { my @classes = uniq( map { $_->class } @attr_types ); @classes = sort @classes; - my @attributes_loop; # FIXME This is not efficient and should be improved @@ -268,6 +267,15 @@ sub patron_attribute_type_list { next if $attr->class ne $class; push @items, $attr; } + + @items = sort { + (defined $a->display_order ? $a->display_order : 9999) + <=> + (defined $b->display_order ? $b->display_order : 9999) + || $a->code cmp $b->code + } @items; + + my $av = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } ); my $lib = $av->count ? $av->next->lib : $class; push @attributes_loop, { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-attribute-types.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-attribute-types.inc index c1f7540fd0..7b7bd9cd02 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-attribute-types.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-attribute-types.inc @@ -1,3 +1,4 @@ +[%- KOHA -%] [% BLOCK 'memberentry_patron_attributes_form' %] [% UNLESS ( no_patron_attribute_types ) %]
diff --git a/members/memberentry.pl b/members/memberentry.pl index 34932e4a4c..9c166ae2d6 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -1062,3 +1062,5 @@ sub add_guarantors { } } } + +1; \ No newline at end of file diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index dcd149347a..bd08bd3c61 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -705,7 +705,7 @@ sub GeneratePatronAttributesForm { # Get all attribute types and the values for this patron (if applicable) my @types = grep { $_->opac_editable() or $_->opac_display } # FIXME filter using DBIC - Koha::Patron::Attribute::Types->search( {}, { order_by => 'display_order' } )->as_list(); + Koha::Patron::Attribute::Types->search( {}, { order_by => \'display_order IS NULL, display_order ASC , code ASC' } )->as_list(); if ( scalar(@types) == 0 ) { return []; } -- 2.52.0