From 46fb615cce700a70f249d4f601c758d0e500d946 Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Wed, 14 Aug 2024 20:06:43 +0000 Subject: [PATCH] Bug 35145: Add ability to order patron attribute types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Here is a summary of the changes: - Added the new column 'display_order' to 'borrower_attribute_types' table ---> Created an atomic update file (bug_35145_order_patron_attributes.pl) ---> Updated the kohastructure.sql file - Added the new column 'Display order' for '/cgi-bin/koha/admin/patron-attr-types.pl' table ---> The table now defaults to sorting based on the 'display_order' column - Added the field 'Appear in position' in the patron attribute types create/edit form - Changed the order of patron attribute types in the patron create/edit form (OPAC and staff interfcce) so it's now sorted by the assigned display_order TEST PLAN 1) Go to 'Koha administration > Patron attribute types > + New patron attribute type' 2) Fill out the form ---> Code: Enter any code, for example 'WEIGHT' ---> Description: Enter any description ---> Display in OPAC: Check ---> Editable in OPAC: Check ---> Class: Keep it empty 3) Click 'Save' 4) Repeat to add a second code with a code alphabetically before the previous one, for example SURNAME 5) Optionally, add more to really view the order 6) Go to 'Koha administration > System preferences' 7) Search for 'selfreg' 8) Set 'PatronSelfRegistration' to 'Allow' 9) Set a category in 'PatronSelfRegistrationDefaultCategory' 10) Click on the 'Save all OPAC preferences' button 11) Go to the OPAC and click on the 'Create an account' button 12) Go to the bottom of the form ---> Note that the patron attribute fields are presented in alphabetical order of code 13) Apply the patch 14) Perform an atomic update (./installer/data/mysql/updatedatabase.pl) 15) Return to 'Koha administration > Patron attribute types' ---> Notice the new 'Display order' column in the tables 16) Choose one of the attribute types you created earlier and click on the 'edit' button ---> You should now see the 'Appear in position' field 17) Enter a number in the 'Appear in position' field and click on 'Save' 18) Repeat the last two steps for each attribute type you created ---> Notice that the patron attribute types tables are sorted by display_order by default 19) In the staff interface, go to 'Patrons > + New patron' ---> In the 'Additional attributes and identifiers' section, notice that the fields are in the given number order 20) In the OPAC, return to the patron creation form (step 11) ---> At the end of the form, notice that the fields are in the given number order Signed-off-by: Anneli Österman --- admin/patron-attr-types.pl | 2 ++ .../prog/en/modules/admin/patron-attr-types.tt | 10 ++++++++++ members/memberentry.pl | 2 +- members/moremember.pl | 7 +++++-- opac/opac-memberentry.pl | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl index 401522b604..b9b9f2823b 100755 --- a/admin/patron-attr-types.pl +++ b/admin/patron-attr-types.pl @@ -120,6 +120,7 @@ sub add_update_attribute_type { my $display_checkout = $input->param('display_checkout') ? 1 : 0; my $category_code = $input->param('category_code') || undef; my $class = $input->param('class'); + my $display_order = $input->param('display_order') || undef; my $attr_type = Koha::Patron::Attribute::Types->find($code); if ( $op eq 'edit' ) { @@ -157,6 +158,7 @@ sub add_update_attribute_type { display_checkout => $display_checkout, category_code => $category_code, class => $class, + display_order => $display_order, } )->store; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt index 57748196e1..0bcc70eab0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt @@ -105,6 +105,14 @@ Required +
  • + + [% IF ( attribute_type.display_order ) %] + + [% ELSE %] + + [% END %] +
  • [% IF attribute_type AND attribute_type.repeatable AND NOT can_be_set_to_nonrepeatable %]
  • @@ -326,6 +334,7 @@ Authorized value category Mandatory Searching + Display order Actions @@ -376,6 +385,7 @@ Not searchable [% END %] + [% item.display_order | html %] Edit Delete diff --git a/members/memberentry.pl b/members/memberentry.pl index f1fd9bfe5b..b8c23cf3da 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -928,7 +928,7 @@ sub patron_attributes_form { my $op = shift; my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; - my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id); + my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, { order_by => 'display_order' }, $library_id); if ( $attribute_types->count == 0 ) { $template->param(no_patron_attribute_types => 1); return; diff --git a/members/moremember.pl b/members/moremember.pl index 773bc4190d..934e0cce9d 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -140,14 +140,17 @@ unless ( Koha::Patron::Categories->search_with_library_limits( { 'me.categorycod if (C4::Context->preference('ExtendedPatronAttributes')) { my @attributes = $patron->extended_attributes->as_list; # FIXME Must be improved! + my $attribute_types = Koha::Patron::Attribute::Types->search({}, { order_by => 'display_order' }); my @classes = uniq( map {$_->type->class} @attributes ); @classes = sort @classes; my @attributes_loop; for my $class (@classes) { my @items; - for my $attr (@attributes) { - push @items, $attr if $attr->type->class eq $class + while ( my ( $attr_type ) = $attribute_types->next ) { + for my $attr (@attributes) { + push @items, $attr if ($attr->type->class eq $class && $attr_type->code() eq $attr->type->code) + } } my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class }); my $lib = $av->count ? $av->next->lib : $class; diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 28b7a1aa26..1c21a37bf6 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -664,7 +664,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()->as_list(); + Koha::Patron::Attribute::Types->search( {}, { order_by => 'display_order' } )->as_list(); if ( scalar(@types) == 0 ) { return []; } -- 2.43.0