From e949354f83159b7ee92c8dac41cd870db892d78a 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 Signed-off-by: Lucas Gass Signed-off-by: David Nind Signed-off-by: Laura_Escamilla Signed-off-by: David Nind --- admin/patron-attr-types.pl | 2 + .../en/modules/admin/patron-attr-types.tt | 10 +++ members/memberentry.pl | 72 +++++++++++++++++++ members/moremember.pl | 7 +- opac/opac-memberentry.pl | 2 +- 5 files changed, 90 insertions(+), 3 deletions(-) diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl index 47c16306a8..9e2734d258 100755 --- a/admin/patron-attr-types.pl +++ b/admin/patron-attr-types.pl @@ -121,6 +121,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' ) { @@ -158,6 +159,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 631a41867b..beb057b1b2 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 %] +
  • @@ -330,6 +338,7 @@ Mandatory in staff interface Mandatory in OPAC Searching + Display order Actions @@ -388,6 +397,7 @@ Not searchable [% END %] + [% item.display_order | html %] Edit Delete diff --git a/members/memberentry.pl b/members/memberentry.pl index bade3ad35e..e9a0cb91fc 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -958,6 +958,78 @@ sub parse_extended_patron_attributes { return \@attr; } +sub patron_attributes_form { + my $template = shift; + my $attributes = shift; + 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( {}, { order_by => 'display_order' }, $library_id); + if ( $attribute_types->count == 0 ) { + $template->param( no_patron_attribute_types => 1 ); + return; + } + + # map patron's attributes into a more convenient structure + my %attr_hash = (); + foreach my $attr (@$attributes) { + push @{ $attr_hash{ $attr->{code} } }, $attr; + } + + my @attribute_loop = (); + my $i = 0; + my %items_by_class; + while ( my ($attr_type) = $attribute_types->next ) { + my $entry = { + class => $attr_type->class(), + code => $attr_type->code(), + description => $attr_type->description(), + repeatable => $attr_type->repeatable(), + category => $attr_type->authorised_value_category(), + category_code => $attr_type->category_code(), + mandatory => $attr_type->mandatory(), + is_date => $attr_type->is_date(), + }; + if ( exists $attr_hash{ $attr_type->code() } ) { + foreach my $attr ( @{ $attr_hash{ $attr_type->code() } } ) { + my $newentry = {%$entry}; + $newentry->{value} = $attr->{attribute}; + $newentry->{use_dropdown} = 0; + if ( $attr_type->authorised_value_category() ) { + $newentry->{use_dropdown} = 1; + $newentry->{auth_val_loop} = + GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} ); + } + $i++; + undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' ); + $newentry->{form_id} = "patron_attr_$i"; + push @{ $items_by_class{ $attr_type->class() } }, $newentry; + } + } else { + $i++; + my $newentry = {%$entry}; + if ( $attr_type->authorised_value_category() ) { + $newentry->{use_dropdown} = 1; + $newentry->{auth_val_loop} = GetAuthorisedValues( $attr_type->authorised_value_category() ); + } + $newentry->{form_id} = "patron_attr_$i"; + push @{ $items_by_class{ $attr_type->class() } }, $newentry; + } + } + for my $class ( sort keys %items_by_class ) { + my $av = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } ); + my $lib = $av->count ? $av->next->lib : $class; + push @attribute_loop, { + class => $class, + items => $items_by_class{$class}, + lib => $lib, + }; + } + + $template->param( patron_attributes => \@attribute_loop ); + +} + sub add_guarantors { my ( $patron, $input ) = @_; diff --git a/members/moremember.pl b/members/moremember.pl index 9cf8574e10..cc539f55f0 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -143,14 +143,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 1daa2daf2c..6c6b1f87e3 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()->as_list(); + Koha::Patron::Attribute::Types->search( {}, { order_by => 'display_order' } )->as_list(); if ( scalar(@types) == 0 ) { return []; } -- 2.39.5